Jump to:

23551 Posts in 19348 Topics by 2891 members

General Questions

SilverStripe Forums » General Questions » Assets Tidy Up - Manually moving images en-masse

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

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

Page: 1
Go to End
Author Topic: 610 Views
  • Double-A-Ron
    Avatar
    Community Member
    604 Posts

    Assets Tidy Up - Manually moving images en-masse Link to this post

    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

  • Double-A-Ron
    Avatar
    Community Member
    604 Posts

    Re: Assets Tidy Up - Manually moving images en-masse Link to this post

    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

    610 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.