Delete old attachments

04/04/2011

Attached files can be deleted manually through the admin interface or automatically on a schedule to prevent disk space filling up. Web to print files can be large in size clogging the hard drive and degrading performance.

File attachments can take up significant amount of storage space over time. Not all files uploaded using the Dynamic File Attachments extension end up as being part of an order. Sometimes customers upload files but never finish the order. Also, after certain period of time most of uploaded files are no longer needed. These files are obsolete and only fill up hard drives. We are handling these files as 2 cases:

  • Orphaned – files that do not belong to an order. They were uploaded but the order was never finalized
  • Old – files that may or may not be part of orders but have been uploaded some time ago

Deletion settings

These settings affect manual and scheduled cron jobs to delete orphaned and old files. Navigate to Magento admin panel > Attachments (top menu) > Attachments Settings (also available through System > Configuration > Attachments Options > Settings) and set number of days for orphaned and old files to be kept before deletion.

By default the extension is set to delete orphaned files after 30 days and not to delete old files at all.

Setting a value of 0 (or leaving the field empty) means that those type of files will never be deleted.

Bare in mind that old files include both orphaned files and files used in orders. If you specify value for old files that is equal or less than the value set for orphaned files, the latter is simply ignored since ALL files will be deleted by the former setting anyway.

Manual deletion of outdated files

Since setting up cron jobs in some environments is not that simple there is the option of running the same process via admin interface.

Navigate to Magento admin panel > Attachments (top menu) > Manage Attachments and chose weather you want to delete all Old or just Orphaned files.

This will fire off same procedure as auto-deleting auto-deleting option. Same periods are taken into account. If there are files old enough to be deleted, you will get a message with number of files being deleted. If there are no old enough files you will get “No old enough files found” message and a link to Attachment Settings page, where you can adjust periods for file deletion.

Manual deletion of selected files

Regardless of weather attachments qualify for scheduled deletion, they can also be deleted from inside Magento admin panel manually.

Navigate to Magento admin panel > Attachments (top menu) > Manage Attachments and click Delete link for the specific attachment file or delete multiple files at once using the bulk actions drop-down.
See also: