We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6531
    • 154 Posts
    I just found this tip on how to find/replace all instances of a string/value in your database.
    Run this as an SQL statement from your SQL admin:

    UPDATE tablename SET tablefield = replace(tablefield,"findstring","replacestring")

    You can add a WHERE clause onto this as well to limit the search to certain records.

    This was useful in changing the links within a TV for a whole bunch of links when I moved some media files to a new folder:
    UPDATE modx_site_tmplvar_contentvalues SET value = replace(value,"/assets/files/private/Media/","/MEDIA/");
    

    And if you need to set a certain field for a bunch of records :

    UPDATE tablename
    SET field1=value
    WHERE field2 BETWEEN x AND y
    


    For example, I needed to resort the menuindex so I could move some docs around, but too many docs had the same menuindex.
    So I wanted to multiply all the menuindexes by 10 -- that way I could move some docs ’between’ other ones.
    I used this:

    UPDATE modx_site_content
    SET menuindex=menuindex*10
    WHERE menuindex BETWEEN 100 AND 199
    


    Now I could, say, move a doc with menuindex 4 (which is now 40) to ’in between’ 6 (now 60) and 7 (now 70) by making it menuindex = 65!

    (This was necessary for a Ditto-generated page which scanned within subfolders, so the built-in Doc Manager’s ’Sort Menu Items’ wasn’t good enough.)
      • 4310
      • 2,310 Posts
      Thanks for the pointer on the replace feature.
      I kept meaning to read up on it, you’ve saved me the trouble!