21282 Posts in 5730 Topics by 2601 members
|Go to End|
4 April 2012 at 9:40pm
I have a 2.4 Ss site here that's been around for a while. The assets/Uploads directory is a bit of a mess, and the owner would like to organize these images logically now.
So I have written a script that loops through all images in the assets/Uploads directory, gets an id from the File table, and checks for any usage of that id in some pre-defined image fields for a set of pages.
The script then copies the original image to it's new logical location, updates the File table (just the Filename field) with the new path, and deletes the original image.
Note: There are hundreds of images.
All of this appears to be working on the surface. Copying is correct, the update to the table is correct. However when I refresh a page containing a (resized) image I know has been moved, the page is still using the same Uploads/_resampled cached item rather than a new cache image in the Uploads/new_directory/_resampled directory.
I have manually deleted the cache item, but the system simply recreates it on refresh.
1. Am I wrong in assume that using the new folder's _resampled directory would be the expected behavior? Images that are uploaded through the CMS to that directory certainly do.
2. It just dawned on me that I did not update the "LastEdited" field in the Files table when I update the path. I did this manually to no avail however. Should this be updated when the path changes?
3. Is there a better way (other than the DnD interface in Files and Images) to manually move assets in this fashion.
Cheers for any help
9 April 2012 at 3:04pm Last edited: 9 April 2012 3:17pm
Found the solution to this, so for future reference and searches:
The setWidth() method in the Image class that creates thumbnails uses another method in that class called cacheFilename(). This creates the filename for saving the cached thumbnail.
The filename for the cache uses the ParentID of the image to generate a path (which in this case is the original folder the image was in - assets/Uploads). It does NOT use the new path of the actual file itself.
Solution: When manually moving images in this way, get the ID of the new destination folder where you are moving each image to, and update the ParentID for the image in the File table to be that ID.
|Go to Top|