unclecheese/silverstripe-kickassets

Uncaught exception when moving or deleting files that aren't fysically available

Friksel opened this issue · 2 comments

After trying to remove a file from within the CMS that is not fysically available (anymore) for some reason, the layout of the module breaks in the breadcrumbs; it's not showing the path anymore, just the homeicon.

An uncaught exception is raised:

[Error] Uncaught Exception: Cannot move [Error] Uncaught Exception: Cannot move /website.nl/public_html/assets/Uploads/HomeblocksImages/myimage.svg to /website.nl/public_html/assets/myimage.svg -
/website.nl/public_html/assets/Uploads/HomeblocksImages/myimage.svg doesn't exist
/website.nl/public_html/framework/filesystem/File.php:581 

Before installing the module there was this syncronise-files functionality that synchronises fysical files with the database. But this seem to be gone since the module is installed. Maybe I look in the wrong place, but I can't find it anywhere in the module.

The assets sync task is part of silverstripe/cms, though it has been removed on master. You should be able to run this task directly with the path /dev/tasks/FilesystemSyncTask, though keep in mind that it's fairly aggressive - deleting files and breaking relationships without asking.

For what it's worth, If you're wanting to fix your assets rather than just blindly update them against the disk, I wrote an interactive assets fixer script a while ago that looks for files that might have moved within the assets directory and lists files that are completely missing.

Use environment file '/Users/foo/Sites/bar/_ss_environment.php'? [Y/n]

Matches found for missing 'assets/playthegame.png':

  0: assets/Promotions/playthegame.png

  Enter the number of the file to update the DB record with, or empty to skip: 0

Report:
No matches found: 2
Updated: 1
Failed or skipped: 0
No matches found in filesystem:
  2719  assets/PDFs/some-file.pdf
  2693  assets/Uploads/foo-bar-9630.jpg

@unclecheese Thanks for your quick response. I didn't know about that Task. You're right, it's better to leave the sync-files-button outside of the CMS. I was just afraid that it wasn't available anywhere at all.

I didn't have problems using this function, but I've heard people having issues with it. I don't have an overview in how aggressive it is, but indeed it would be welcome to have control over its delete-actions as developer. I'll take a look at your script. Thanks for that!