How do you use the "Search and Replace tool" safely?

Re: How do you use the "Search and Replace tool" safely?

by Ken Task -
Number of replies: 7
Picture of Particularly helpful Moodlers

Yes, running some scripts where a protocol is used (http://) the 'slashes' get interpreted by the shell as 'escapes' so one either has to use double quotes around those or escape the escape's ... like http:\/\/ ... the \ in front says next character is literal.

I'd had to do sed that way on some systems.

So in your case using an editor (like nano) on sql dump prior to import of the sql might be best option.

I kinda like that process in that after a do a search and replace I can search again to see if nano got them all (minus the embedded internal links).

Anyhoo, nice that you have options/choices! smile

'SoS', Ken

Average of ratings: Useful (1)
In reply to Ken Task

Re: How do you use the "Search and Replace tool" safely?

by David M -
Thanks, Ken.

Since the Search and Replace tool seemed to be unable to handle hostnames of differing lengths(?!), in the end, I just used sed on the incoming database dump (the sed command needed is explained on the Moodle migration page), imported the updated database dump, and this seems to have worked.
In reply to David M

Re: How do you use the "Search and Replace tool" safely?

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
> the Search and Replace tool seemed to be unable to handle hostnames of differing lengths

New to me. Could you tell us how to reproduce?
In reply to Visvanath Ratnaweera

Re: How do you use the "Search and Replace tool" safely?

by David M -
As per the output from the tool that I quoted previously (OK, so it doesn't like the new URI being longer, perhaps it's OK with shorter URIs?):

The replacement is longer than the original and shortening is not allowed; cannot continue.
In reply to David M

Re: How do you use the "Search and Replace tool" safely?

by Wolf Ventir -

What possible reason could there ever be to limit the replace tool to only searching for things that are longer than the search term?

"The replacement is longer than the original and shortening is not allowed; cannot continue."

This is regex search and replace, what technical reason could drive this limitation?

Edit: After further review there is a --shorten parameter that can make this work per this comment: https://moodle.org/mod/forum/discuss.php?d=337148#p1359035

Why this is not in the wiki documentation on the script? No idea. I have gone ahead and edited the documentation wiki to add it so hopefully new people searching wont have to look like we did.

In reply to Wolf Ventir

Re: How do you use the "Search and Replace tool" safely?

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
You can always dump the database, apply the search-and-replace tool of your choice and restore the modified dump.
In reply to Visvanath Ratnaweera

Re: How do you use the "Search and Replace tool" safely?

by Luis de Vasconcelos -
That's not an option in some of the database engines that Moodle supports, e.g. MS SQL Server (SQLSRV).
Average of ratings: Useful (1)