Topic: Attachments deletion may leave orphan entries
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 admin/db/fiscalyears_db.inc lines 188-210:
function delete_attachments_and_comments($type_no, $trans_no)
{
$sql = "SELECT * FROM ".TB_PREF."attachments WHERE type_no = $type_no AND trans_no = $trans_no";
$result = db_query($sql, "Could not retrieve attachments");
$delflag = false;
while ($row = db_fetch($result))
{
$delflag = true;
$dir = company_path(). "/attachments";
if (file_exists($dir."/".$row['unique_name']))
unlink($dir."/".$row['unique_name']);
}
if ($delflag)
{
$sql = "DELETE FROM ".TB_PREF."attachments WHERE type_no = $type_no AND trans_no = $trans_no";
db_query($sql, "Could not delete attachment");
}
$sql = "DELETE FROM ".TB_PREF."comments WHERE type = $type_no AND id = $trans_no";
db_query($sql, "Could not delete comments");
$sql = "DELETE FROM ".TB_PREF."refs WHERE type = $type_no AND id = $trans_no";
db_query($sql, "Could not delete refs");
}
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.
Is this the intended functionality?
Will it not be better to keep separate folders for attachments for each fiscal_year?
We need to keep in mind that not all transactions finish completely within the fiscal_year.