ElkArte Community

Project Support => Support => Topic started by: radu81 on January 07, 2015, 01:31:58 pm

Title: mysql - Removing some old bbcode
Post by: radu81 on January 07, 2015, 01:31:58 pm
I have managed to change some old bbcode not used anymore on elkarte. I used
Code: [Select]
UPDATE [icode]elkarte_messages[/icode] SET [icode]body[/icode] = REPLACE([icode]body[/icode],'text1','text2')
I had an old version of tapatalk that was not supporting emoticons and now I have some bbcode like [emoji2] or [emoji123]

How could I remove all these old bbcodes? Thank you
Title: Re: mysql - Removing some old bbcode
Post by: emanuele on January 07, 2015, 02:27:09 pm
Do you want to replace them with something or just nothing?
Title: Re: mysql - Removing some old bbcode
Post by: radu81 on January 07, 2015, 03:14:30 pm
I would like to remove them.
Title: Re: mysql - Removing some old bbcode
Post by: emanuele on January 07, 2015, 04:10:39 pm
I forgot regex do not work on replace in mysql... darn.
I guess you have two options:
1) hide them via a function (for example some kind of replacement in parse_bbc) (I'm just throwing out ideas, don't worry about the implementation. ;))
2) for each tag do the replacement like you did in the other cases
3) write a php script to run on the db to convert the codes.
Title: Re: mysql - Removing some old bbcode
Post by: radu81 on January 07, 2015, 04:13:39 pm
too complicate, I thought there was a simply way to do this. I'll do a simple search and use the method in the first post for every smiley ;)
Title: Re: mysql - Removing some old bbcode
Post by: Spuds on January 07, 2015, 09:15:47 pm
What @emanuele said ...

To my knowledge you can not use wildcards on an update  :(   So your options are if there are just a few combo's you would have to do each one as its own update.  Otherwise its a script that goes post by post and does the wildcard search and remove.
Title: Re: mysql - Removing some old bbcode
Post by: emanuele on January 08, 2015, 08:11:11 am
Well, the parse_bbc code would look something like:
Code: [Select]
function replace_tapatalk_bbcode($message)
{
    return preg_replace('~\[emoji\d+\]~i', '', $message);
}
Nothing too complex. ;)
Title: Re: mysql - Removing some old bbcode
Post by: radu81 on January 08, 2015, 03:44:02 pm
I solved this, it took me almost an hour but I replaced manually about 90% of smileys from Tapatalk with my own smileys. I removed the rest of them ;)
Title: Re: mysql - Removing some old bbcode
Post by: emanuele on January 08, 2015, 04:44:29 pm
A heck of a job! :(
Title: Re: mysql - Removing some old bbcode
Post by: radu81 on January 08, 2015, 04:58:17 pm
maybe I was not so clear, I did not edit the post one by one, but I searched the forum for [emoji* and then used the sql command UPDATE.. REPLACE ;) not an elegant solution but I solve it ;)