View Full Version : 5.62 Moving images can overwrite existing images
December 20th, 2006, 06:31 AM
A problem that pops up frequently and is really annoying for our users:
In PP filenames are unique per category. So if you upload an image called foo.jpg to a category which already does contain an image with that filename, it gets renamed to foo1.jpg.
This automatic renaming doesn't exist if you move a file from one category into another. Then, the physical file get's overwritten.
So please check the filenames on moving and rename the moved image if necessary to prevent data loss.
December 20th, 2006, 09:16 AM
I dont think Michael has come up with a backward compatible way to do this on moving a photo but I do know we removed the per category check and made it a global check a long time ago. Thus it is people with older systems who might move older photos that would have this issue.
December 20th, 2006, 09:37 AM
Maybe a script that scans the complete database and checks for duplicate names would do it? That could be used for "older systems" and no changes to the current code would be necessary.
December 20th, 2006, 09:54 AM
In 5.62, we look for filenames that match regardless of which category they are in - if an image within the system has the same name, then it gets a new name; which would prevent any overwriting in the future.
There was a bug in a prior 5.5 release that did check explicitly for category names before renaming a file and that was fixed in an update. While uploading, you should not end up with two files with the same name in any category; as for existing duplications, we do not have a mechanism for that.
December 20th, 2006, 09:59 AM
Ok, I understand that, but we have about 90.000 images that have been uploaded with PP < 5.5 and that might be moved around. So the question is how to address the inconsistent data that has been caused by this bug. That's why I proposed a "cleanup" script to address this issue.
December 20th, 2006, 10:40 AM
I'll see what I can do. To see if this effects other images, try this query (be sure to use your table prefix):
SELECT bigimage, count(*) AS c FROM photos WHERE storecat > 0 GROUP BY bigimage HAVING c > 1 ORDER BY C DESC
Only results with more than 1 are actual duplicates and, also keep in mind that queries are not case sensitive; so its possible to have two filenames that don't overwrite one another on Linux systems.
December 20th, 2006, 10:44 AM
Query returned 1,892 total.
December 20th, 2006, 10:53 AM
Might be helpful for others. This query returns only results with more than 1 duplicate:
SELECT bigimage, count(id) AS c FROM photos WHERE storecat > 0
GROUP BY bigimage
having c > 1 ORDER BY C DESC
On my installation, this are 873 total
December 20th, 2006, 12:48 PM
Okay, I've attached a script I wrote and tested in my viperalley.com website which cleaned up about 60 duplicate filenames.
I make no warrenties for this script and it's use; the code seems proper and it worked on my site for the 60 dupes I had. I suggest you check it yourself and backup your photos table before you run it (and even your data directory).
There is error checking built-in - but again, you should review it for yourself and be sure you understand what it is doing before running it.
December 20th, 2006, 01:06 PM
Thanks Michael, I'll test it on Saturday and report back to you.
December 24th, 2006, 07:05 PM
Worked like a charm, thank you!
December 25th, 2006, 12:00 AM
vBulletin® v3.8.1, Copyright ©2000-2014, Jelsoft Enterprises Ltd.