News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

MySQL Search and Replace Query?

Started by Segnali, June 02, 2020, 02:48:46 AM

Previous topic - Next topic

Segnali

Hi guys

I have moved the forum to another domain but cannot find anymore the SQL query I used years ago to change all urls in forum posts and everything else.

I tried using Google but I am getting lots of different queries for Wordpress and I am not sure if I can use that stuff for the forum too.

Does anyone know the right query?

Thank you

Doug Heffernan

Quote from: Segnali on June 02, 2020, 02:48:46 AM
Hi guys

I have moved the forum to another domain but cannot find anymore the SQL query I used years ago to change all urls in forum posts and everything else.

I tried using Google but I am getting lots of different queries for Wordpress and I am not sure if I can use that stuff for the forum too.

Does anyone know the right query?

Thank you

UPDATE `smf_messages`
SET `body` = REPLACE(`body`, 'text_to_be_replaced', 'text_to_replace_with');



m4z

"Faith is what you have in things that don't exist."
--Homer Simpson

Es gibt hier im Forum ein deutsches Support-Board!

Arantor



vbgamer45

Might be a neat feature to add to repair_settings update all post urls. Only issue is timeouts on large forums.
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Arantor

I'd definitely encourage it for 2.1, making use of the background task system to do it in batches.

Kindred

Luckily, changes to repair_settings.php are not branch dependent. :D
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Arantor

I didn't just arbitrarily suggest doing it in background tasks without consideration. Doing it in repair_settings.php means making repair_settings.php suddenly cope with a lot of things that it never had to cope with before - because you can't just attempt to do 'find replace' in a single query in repair settings, you really can't. On even a slightly busy site, that can take the site down for the duration.

Doing it in smaller batches will slow the site down but it shouldn't take it down entirely for the duration, and it has infinitely better coping ability to resume where it got to - as opposed to leaving repair_settings.php in place which is flat out a security risk to leave it there any longer than necessary.

Personally I'd ditch repair_settings.php entirely and fix up some of the internals to not be so fragile... instead of theme_dir being a real path all the time, there's nothing stopping it being defined as $boarddir/Themes/default if that's where it lives. Ditto for theme_url and images_url, make the defaults be relative paths and all this problem goes away. If you want/need to use absolute paths/URLs (e.g. like sm.org does), no harm, no foul, just don't push sm.org's requirements onto everyone else.

Ditto also for $sourcedir, and if you do that measure of moving Sources outside of webroot (it's not nearly the security risk people claim), that can still work by making it absolute rather than just using relative by default.

shawnb61

I use this script when building test environments.  It will swap out all URLs and paths:
https://github.com/sbulen/sjrbTools/blob/master/SMF_URLs_Paths.php

Use with extreme caution...

It will update values throughout settings, themes, PMs, messages, & even member signatures.
Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp

vbgamer45

Nice forgot about that one! Maybe a new tool to link to on this site?
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

m4z

Quote from: doug_ips on June 02, 2020, 01:26:54 PM
Quote from: m4z on June 02, 2020, 12:26:37 PM
You probably want to use https://wiki.simplemachines.org/smf/Repair_settings.php

You can't recommed repair_settings.php for just about anything lol :D

Well, Segnali asked to "change all urls in forum posts and everything else" (and as Arantor noted, I overlooked the post part), so that's repair_settings territory. ::)
"Faith is what you have in things that don't exist."
--Homer Simpson

Es gibt hier im Forum ein deutsches Support-Board!

Segnali


Advertisement: