<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[FrontAccounting forum — Attachments deletion may leave orphan entries]]></title>
		<link>https://frontaccounting.com/punbb/viewtopic.php?id=6367</link>
		<atom:link href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=6367&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Attachments deletion may leave orphan entries.]]></description>
		<lastBuildDate>Wed, 20 Jul 2016 20:04:02 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Attachments deletion may leave orphan entries]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=25831#p25831</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (apmuthu)]]></author>
			<pubDate>Wed, 20 Jul 2016 20:04:02 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=25831#p25831</guid>
		</item>
	</channel>
</rss>
