We have a client using Modx for their website for some years now. At launch, we never successfully locked down the client’s users in the File System to the “assets” folder. As a consequence, we’ve got their uploaded images all over the place - in web root, in folders in web root, in assets. The client never fully got the hang of which folder to select in the Media Browser. Could any of you helpful Modx folks help us work out how we’d:
-
Rewrite all images to somewhere in assets, and also the respective updating TV value / Migx TV paths.
-
How to correctly limit the client user to uploading to assets folder without breaking anything, bearing in mind the site and client user accounts are a few years old.
-
Work out which images are actively being used by the front end TVs, i.e. which images are referred to as a path in an ‘Image’ input type tv or Migx TV.
Ideally we want to get the assets folder over to AWS S3, as storage requirements now are massive and we have a VPS far bigger than we need. Also, having the client wandering around the entire Modx filesystem is not good.
The site is currently Modx 3.06, php 8.2, MySQL 8.0. Thaks
I don’t think there is an easy way to achieve this.
The TV values are stored in the database table modx_site_tmplvar_contentvalues. (The column “tmplvarid” is the ID of the TV, “contentid” is the ID of the resource and “value” contains the value of the TV.)
Also for image TVs, the stored value is the image path relative to the path of the media source (that is used by the TV).
For MIGX TVs the stored value is a JSON string with all the data. (So the image paths are somewhere in this JSON string.)
My guess is, that you have to write a custom script that checks every value that is stored for your image/MIGX TVs, then moves the file if necessary and adjusts the stored value accordingly. This won’t be easy, especially for MIGX TVs.
Did you use different Media Sources on this site?
I guess you could give the client user only access to a certain media source, so it won’t be possible to upload the files to any abitrary folder.
There exists also a media source type for S3.
Thanks for the reply, Harry. We have one media source at the moment for the Client Editors, which is the whole of the install directory. We have another Media Source for Admins, which is exactly the same! Based on your reply, we think our approach is:
- Map all TVs and their IDs which are used for images / uploads. Map out the same for MIGX TVs, along with JSON keys used for any image / file uploads.
- Map out what images and uploads have been dumped where (many are contained within folders, thankfully). SSH in, and move them to the new folder location in /assets/newfolderName.
- Lock down Client Editors’ media source to this new folder.
- Run SQL queries to rewrite TV paths or JSON key value paths to the new location, correct for the new Media Source basePath.
- Test, run broken link / image crawl
If we get that far, then we should be in a position to move the new folder contents to S3 and set up a new S3 media source.
One thing we notice is, ( because we still have a separate Media Source for Admins, ) when the Client Editor is locked down to the new folder, when entering Media → Media Browser, the Client Editor still sees the Admin Media Source as the default in the dropdown. It has a label of “1” & error of “permission denied”. The Client Editor can select their media source from the dropdown and all is ok, but is there a way of removing the “1” Admin filesystem from the dropdown or defaulting the Client Editor media source to their own?
You could try adding a setting default_media_source to the user or the user group. This setting should then overwrite the system setting with the same name for the user (or the users in the group). Maybe this fixes the dropdown in the media browser.
Hi Harry, That works, many thanks!