Hello, I have a website that has been abused for years and has many people adding, editing and deleting images from pages, news articles and various modules but they never remove them from the image manager or file manager so there are lots of unused files that I need to clean up! Is there a way (or module) to run a check through the database to find unused/orphaned files that have no references in the database and delete them? At least list them so I can manually clean them?
Thanks for the help!
FYI I'm currently running cmsms 1.12
Cleaning up old images or files (orphaned files)
Re: Cleaning up old images or files (orphaned files)
In the database there are no tables for images/files actually.
Images can be 'included' from multiple places like page's content blocks, specific content fields ({content_image}) other modules content/fields etc. etc.
I don't think it would be easy to come up with some 100% working method. Maybe easiest way is to dump database to flat file (e.g. .sql) and search that file for *.[jpg|png|gif] (pseudo-example) using some regular expression.
Images can be 'included' from multiple places like page's content blocks, specific content fields ({content_image}) other modules content/fields etc. etc.
I don't think it would be easy to come up with some 100% working method. Maybe easiest way is to dump database to flat file (e.g. .sql) and search that file for *.[jpg|png|gif] (pseudo-example) using some regular expression.
Re: Cleaning up old images or files (orphaned files)
Thanks velden, thats what I was thinking, some way to just find all the references to .jpg, .gif etc. in the database. Then I can go in and delete any that are not in the list. I don't think I'm using any modules that wouldn't reference the actual file name so I think that could work. Now I just need some sort of way to pull out all the names and possibly locations of all the images... some sort of script that I can run in the terminal maybe...
-
- Support Guru
- Posts: 8169
- Joined: Tue Oct 19, 2004 6:44 pm
- Location: Fernie British Columbia, Canada
Re: Cleaning up old images or files (orphaned files)
Parsing all of that data out of the database is not realistic. And often times images are not even in the database... unless they are directly addressed in some HTML somewhere.
The simplest way to generate a list of images you can at least investigate (as no matter what you do this could not be automated reliably). would be to parse your access logs for a month or two, parse them into a file list, and compare it to the files on your site.
If you parse your access logs, grabbing all of the image requests... trim it down to just the URL requested... and convert it into a path name from the site root.
Then generate a list of all of the images on your site (from the site root).
Then you could easily cross reference that list with the list of files on your site, come up with a list of files (images) that were not accessed... and make decisions.
This same script or two (that you will have to write) would be useful to help you find images you shouldn't have deleted, and orphaned ones. and can be run regularly.
The simplest way to generate a list of images you can at least investigate (as no matter what you do this could not be automated reliably). would be to parse your access logs for a month or two, parse them into a file list, and compare it to the files on your site.
If you parse your access logs, grabbing all of the image requests... trim it down to just the URL requested... and convert it into a path name from the site root.
Then generate a list of all of the images on your site (from the site root).
Then you could easily cross reference that list with the list of files on your site, come up with a list of files (images) that were not accessed... and make decisions.
This same script or two (that you will have to write) would be useful to help you find images you shouldn't have deleted, and orphaned ones. and can be run regularly.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.