MODX revo – Update wrong path in Galleries or Images loaded from TV’s

Today, a my customer, that is an howner of a real estate website, had loaded abut 100 properties.
When he had created the single property , had loaded all property images, in a wrong “`value` = CONCAT(‘./media/’, SUBSTR(`value`, 3))”.
Now i have the root f the site that is full of images..
I don’t want to update every single property by hand, so, i try to update all wrong path by queries in phpmyadmin ( directly in the db ).
So, open yoour phpMyAdmin and make a full backup. ( don’ t missing this step, if something go wrong, is foundamental that you have a backup copy for reload it ).

Localize the table ” mdx_site_tmplva_contentvalues “, this is the table where all the TV value are stored. ( the ” mdx_ ” value can change form modx installation to modx installation ).

Here are the queries that we run in our db :


SELECT `value` FROM mdx_site_tmplvar_contentvalues WHERE `value` like './%'

UPDATE mdx_site_tmplvar_contentvalues SET `value` = CONCAT(‘./media/’, SUBSTR(`value`, 3)) WHERE `value` like ‘./%’

 

The first one ” Select ” all value, that are stored in the site root ( WHERE `value` like ‘./%’ )

The Second one ” Update ” all value with the new path ( `value` = CONCAT(‘./media/’, SUBSTR(`value`, 3)) ).

That’s all , if you don’t have error message, all be done.

 

Connect to your site by FTP, and move the file loaded in wrong location to the new location.

Connect to the manager, refresh cache, and try to navigate on front-end, you should see all images in a correct ” Media Source ”

 

 

P.s

 

Other example of query :

 

SELECT `value` FROM mdx_site_tmplvar_contentvalues WHERE `value` like './%'

UPDATE mdx_site_tmplvar_contentvalues SET `value` = CONCAT('./media/', `value`) WHERE `value` like './%'

SELECT `value` FROM mdx_site_tmplvar_contentvalues WHERE `value` like '%.png' AND `value` not like './%' AND `value` not like 'media/%' AND `value` not like 'assets/img/%'