<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[FrontAccounting forum — Attachments deletion may leave orphan entries]]></title>
	<link rel="self" href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=6367&amp;type=atom" />
	<updated>2016-07-20T20:04:02Z</updated>
	<generator>PunBB</generator>
	<id>https://frontaccounting.com/punbb/viewtopic.php?id=6367</id>
		<entry>
			<title type="html"><![CDATA[Attachments deletion may leave orphan entries]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=25831#p25831" />
			<content type="html"><![CDATA[<p>The delete attachments function called during fiscal year deletion may leave orphan entries ib the attachments table. Listed below is the function for reference from <strong>admin/db/fiscalyears_db.inc</strong> lines 188-210:<br /></p><div class="codebox"><pre><code>function delete_attachments_and_comments($type_no, $trans_no)
{
    
    $sql = &quot;SELECT * FROM &quot;.TB_PREF.&quot;attachments WHERE type_no = $type_no AND trans_no = $trans_no&quot;;
    $result = db_query($sql, &quot;Could not retrieve attachments&quot;);
    $delflag = false;
    while ($row = db_fetch($result))
    {
        $delflag = true;
        $dir =  company_path(). &quot;/attachments&quot;;
        if (file_exists($dir.&quot;/&quot;.$row[&#039;unique_name&#039;]))
            unlink($dir.&quot;/&quot;.$row[&#039;unique_name&#039;]);
    }
    if ($delflag)
    {
        $sql = &quot;DELETE FROM &quot;.TB_PREF.&quot;attachments WHERE  type_no = $type_no AND trans_no = $trans_no&quot;;
        db_query($sql, &quot;Could not delete attachment&quot;);
    }    
    $sql = &quot;DELETE FROM &quot;.TB_PREF.&quot;comments WHERE  type = $type_no AND id = $trans_no&quot;;
    db_query($sql, &quot;Could not delete comments&quot;);
    $sql = &quot;DELETE FROM &quot;.TB_PREF.&quot;refs WHERE  type = $type_no AND id = $trans_no&quot;;
    db_query($sql, &quot;Could not delete refs&quot;);
}    </code></pre></div><p>Only if the attachment file is deleted will the entry get removed from the attachments table - this may not always be the case if the attachment got deleted from the folder earlier say through some command line usage / SFTP. </p><p>Is this the intended functionality?</p><p>Will it not be better to keep separate folders for attachments for each fiscal_year? </p><p>We need to keep in mind that not all transactions finish completely within the fiscal_year.</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2016-07-20T20:04:02Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=25831#p25831</id>
		</entry>
</feed>
