How can we delete file stored in file attachment system and it's corresponding key stored in the database under osticket_file table?

Is there any table filed(s) in common in between osticket_file table and ticket(s) table(s), so when we delete tickets directly from the database the corresponding file stored in file system and database is deleted at once.

@KevinTheJedi

  • KevinTheJedi replied to this.
  • st512

    It’s not that simple unfortunately. We deduplicate attachments. Meaning a single file can be attached to many different things. So when deleting a file (especially images) you need to ensure they are not attached to anything else or you will receive errors for eternity. You would need to check thread entry bodies, faq bodies, canned response bodies, etc. to ensure they aren’t inline anywhere.

    Once you have determined there are no other references you can delete the related _attachment record, delete the _file record, then delete the file on the file system. You could simply let it be handled automatically by the system. Let’s say a thread has an attachment and that attachment only exists there. When you delete the ticket the system will mark the file as orphaned (not attached to anything) and it will be deleted after 24 hours via cron cleanup scripts.

    Cheers.

    st512

    It’s not that simple unfortunately. We deduplicate attachments. Meaning a single file can be attached to many different things. So when deleting a file (especially images) you need to ensure they are not attached to anything else or you will receive errors for eternity. You would need to check thread entry bodies, faq bodies, canned response bodies, etc. to ensure they aren’t inline anywhere.

    Once you have determined there are no other references you can delete the related _attachment record, delete the _file record, then delete the file on the file system. You could simply let it be handled automatically by the system. Let’s say a thread has an attachment and that attachment only exists there. When you delete the ticket the system will mark the file as orphaned (not attached to anything) and it will be deleted after 24 hours via cron cleanup scripts.

    Cheers.

    18 days later

    I have deleted the tickets directly from the database, will the recron.php script delete the orphaned attachment files or else do I need to do something to the script please?

      st512

      Read above. If you did it through database you must manually delete associated records and do lookups for any others references for the file inline somewhere.

      Cheers.

      Write a Reply...