Remove old versions of files
Permalink
I have a Concrete 5.6.3.1 site in production that has a bunch of PDFs for each product on the site. When we change the PDF periodically, we replace the file in the File Manager using the "replace" function. However, the old version of the file remains on the filesystem. Because these old versions of the files are left around, Google has the old file url in its index, and people see the old version of the file when they click links from Google.
I tried deleting the old file versions from the File Manager, but this appears to only delete from the database, and not from the file system.
Is there any way to go through and remove the old physical files?
I tried deleting the old file versions from the File Manager, but this appears to only delete from the database, and not from the file system.
Is there any way to go through and remove the old physical files?
Thanks, this definitely helps. I was kind of afraid I'd be stuck writing something like this. It will work, until I replace more files, I'll have to run this every time, which is really inconvenient.
I'll probably turn it into an C5 "automated job", so it can be run easily from the dashboard.
I'll probably turn it into an C5 "automated job", so it can be run easily from the dashboard.
You're welcome. If you do turn this into a c5 job it would be nice to share a copy here.
You could of course pass in a $_GET auth token, program it to run as the Super Admin and run it from a cron job on the host with wget or curl...
The second problem would be to handle the old Google requests and redirect to the active version.
You could of course pass in a $_GET auth token, program it to run as the Super Admin and run it from a cron job on the host with wget or curl...
The second problem would be to handle the old Google requests and redirect to the active version.
I've attached a C5 job that will delete all old file versions, including the physical file from the server.
PLEASE NOTE: If you have hard-coded links to old versions of the file anywhere in the CMS, you will have to fix these links, as they will break after running this script.
I assume no responsibility for this script! Backup your files and test before using this in production.
PLEASE NOTE: If you have hard-coded links to old versions of the file anywhere in the CMS, you will have to fix these links, as they will break after running this script.
I assume no responsibility for this script! Backup your files and test before using this in production.
Does this work on 8.1.0 installs too?
I haven't tested it on newer versions of Concrete. I would back up everything and test it in development first.
Since you already deleted the files from the file manager I'm not sure this will help. You may have to iterate through the /files (excluding cache, tmp, etc) and check that each file is not referenced in the database and then unlink them..
Here's a /tools file that does work otherwise - be sure to read carefully - you must be logged in as Super Admin before running it in the browser.
This could be modified to run from a cron job...
If this helps, I accept Beer donations ;) John