Simple Machines Community Forum

SMF Support => SMF 2.0.x Support => Topic started by: efk on January 11, 2018, 06:37:46 PM

Title: Autosearch and replace
Post by: efk on January 11, 2018, 06:37:46 PM
Hey guys, I'm thinking to remove some old links (ex domains) from 2 different forums. Example, for subtitles for movies for text files (like srt, txt, notepad) there is an option to replace characters or words (Edit/Replace/Find What/Replace With) , so I'm wondering if there is something like that on smf? Or if I enter in word censoring exact word or domain, will it remove existing word/domain and without causing some mess? Replacing with something else will be awesome.
Title: Re: Autosearch and replace
Post by: Aleksi "Lex" Kilpinen on January 12, 2018, 11:42:32 AM
You can use the word censoring, I've done that sometimes as a temporary measure. A real search and replace would have to be done through the database though.
Title: Re: Autosearch and replace
Post by: efk on January 12, 2018, 11:57:01 AM
Quote from: Aleksi "Lex" Kilpinen on January 12, 2018, 11:42:32 AM
You can use the word censoring, I've done that sometimes as a temporary measure. A real search and replace would have to be done through the database though.
Is that simple to do, or very complex thing?
Title: Re: Autosearch and replace
Post by: Illori on January 12, 2018, 11:57:59 AM
which part?
Title: Re: Autosearch and replace
Post by: efk on January 12, 2018, 04:14:14 PM
Quote from: Illori on January 12, 2018, 11:57:59 AM
which part?
This?
QuoteA real search and replace would have to be done through the database though.
Title: Re: Autosearch and replace
Post by: aegersz on January 13, 2018, 08:46:30 PM
If you have access to the DB unload, this is how I do a DB search and replace (in Linux but you may adapt it)  - this example builds my clone DB and imports it:

# Unload the current database
mysqldump -u root -passwd smf209 > /SQL/database_smf209_`date '+%d-%m-%Y'`.sql

# Convert the table prefix to the clone
sed 's/`smf209_/`smfclone1_/g' /SQL/database_smf209_`date '+%d-%m-%Y'`.sql > /SQL/smfclone1.sql

# Drop and Recreate the clone database
mysql -u root -passwd < /root/data/mysql.batch

# Reload the clone database
mysql -u root -passwd smfclone1 < /SQL/smfclone1.sql (drop database smfclone1; create database smfclone1;)
   
Title: Re: Autosearch and replace
Post by: Kindred on January 13, 2018, 08:53:36 PM
Ummm.... what?   That has nothing to do with what the op is asking.

Efk...    something like

UPDATE smf_messages SET body REPLACE(body,'original string','new string');
Title: Re: Autosearch and replace
Post by: aegersz on January 13, 2018, 09:07:34 PM
 :-[  :-[

i just glanced at the previous post about seraching and replacing data in the DB.

please delete my posts.

long night ... whoops.
Title: Re: Autosearch and replace
Post by: shawnb61 on January 13, 2018, 09:35:23 PM
I have a utility that I use to setup test environments after restoring the DB from prod.  I got sick of clicking on a link in test & finding myself on my prod site. 

It does ***ALL*** paths ***AND*** URLs in the settings table, the themes table, the messages table, the PMs table & even member signatures (some folks on my forum actually promote their own "tips & tricks" threads in their signatures). 

It has a "do it" flag, which if set to "no" can be used to preview the changes. 

It is extremely helpful.  OTOH, it is extremely dangerous & should be used with extreme caution.  Uh... backup your DB first.   Then back it up again...   

I have it up on Github.  Link here:
https://github.com/sbulen/sjrbTools/blob/master/SMF_URLs_Paths.php
Title: Re: Autosearch and replace
Post by: Kindred on January 13, 2018, 09:50:25 PM
Shawn,   It think that the op was looking to replace URLs in messages not the system URLs and paths
Title: Re: Autosearch and replace
Post by: shawnb61 on January 13, 2018, 10:08:52 PM
Yes, it does messages too.  It can be pared back.
Title: Re: Autosearch and replace
Post by: a10 on January 14, 2018, 05:57:25 AM
Been doing this by exporting the single message table, then notepad++ and using the excellent find \ replace functions then reuploading the table.

As always, the start of of any table or db editing process is a backup :O)
Title: Re: Autosearch and replace
Post by: Kindred on January 14, 2018, 09:30:14 PM
A10,doing it Inline, in phpmyadmin is 1000 Times simpler and faster
Title: Re: Autosearch and replace
Post by: efk on January 15, 2018, 08:10:34 PM
Thank you guys. :)
Title: Re: Autosearch and replace
Post by: Aleksi "Lex" Kilpinen on January 17, 2018, 12:25:21 AM
As always, any time you do anything directly to your database - Backup, backup and backup again. :)
Did you get all the answers you needed, or is there something we can still help you with?
Title: Re: Autosearch and replace
Post by: efk on January 17, 2018, 06:48:51 PM
I guess this is all. In about 2-4 weeks my colleague will read this topic and will work on it.  :)
Title: Re: Autosearch and replace
Post by: Aleksi "Lex" Kilpinen on January 18, 2018, 12:57:05 AM
I'll mark this solved for now then, but you are free to mark this not solved again if you want to continue from here later. :)