Direct replacement of a URL within ANY table Moodle 2.8

Direct replacement of a URL within ANY table Moodle 2.8

by Dave Emsley -
Number of replies: 2

Hi there, this may be a strange request but I want to change EVERY occurrence of a URL in a Moodle site wherever it occurs - forums, activities, etc.

Can I do this via MySQL:

update WILDCARD_TABLE_NAME set WILDCARD_FIELD_NAME = replace(WILDCARD_FIELD_NAME, 'www.bad.url', 'www.good.url')
Best Regards

Dave
Average of ratings: -
In reply to Dave Emsley

Re: Direct replacement of a URL within ANY table Moodle 2.8

by AL Rachels -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Hi Dave,

Yes you should be able to do that. Make a backup of the database first, just in case. In fact, I would copy the database, run the update on it first, just to make sure my query was working correctly. If you do this in phpMyAdmin, you could run the query on a copy of the database, change the name of your original for temporary safekeeping, rename the copy to make it the active database, then test to make sure everything is okay. If it's broke, get rid of the copy and rename the original back to its active name. Of course you would want the site to be in maintenance mode while doing all this database renaming and switching around.

Just to note, I have actually done this database name change more than once, and it is quite safe as long you are clear on what your are doing, keep track of which database is which, and be sure your put your site into maintenance mode BEFORE you copy the database. In other words, you want to make sure the duplicate database will be in maintenance mode when it starts up to make sure no one ca come along and log in while you are testing the changes.

Don't forget, Moodle does have a replace tool at yourmoodle/admin/tool/replace/index.php. I admit that, unfortunately in my experience, it will not find all of them. It seems to miss the URL's that are part of some of the settings, like the filter setting for MathJax if you have it installed on your own server.

In reply to Dave Emsley

Re: Direct replacement of a URL within ANY table Moodle 2.8

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

There is also

http...your.moodle/admin/tool/replace/

Average of ratings: Useful (2)