Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Assets Tidy Up - Manually moving images en-masse


Go to End


2 Posts   1056 Views

Avatar
Double-A-Ron

Community Member, 607 Posts

4 April 2012 at 9:40pm

Hi all,

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.

Questions:
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
Aaron

Avatar
Double-A-Ron

Community Member, 607 Posts

9 April 2012 at 3:04pm

Edited: 09/04/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.

Nice one
Aaron