Database Query Help
Hi guys,
I will be as brief as possible, I converted a 17 yr old vbulletin forum into Xenforo. The importer worked fine but the redirect script didnt. That means any links in the posts that point to other places on forum are now bad links. Here is an example of previous vBulletin thread link Code:
domain.com/forums/showthread.php?69985-daily-news and it needs to change to look like this Code:
domain.com/forums/index.php?threads/.69985 I cant touch 69985 because every thread or post will have a different ID which is fine. So I need to replace showthread.php? with index.php?threads/. which I can and haven't done so yet db table: xf_post db index: message Code:
UPDATE xf_post SET message = REPLACE(message, 'showthread.php?', 'index.php?threads/.'); If I do that, I end up with Code:
domain.com/forums/index.php?threads/.69985-daily-news -daily-news So every thread will have a different ID which I cant remove but I need to remove that thread label. I need a clever way to mass remove all the different labels from different threads. Thanks in advance for any help |
You haven't said which database software you're using, so I'm assuming MariaDB.
You can use regex replace to capture the numeric portion, then append it like so: Code:
REGEX_REPLACE( message , 'showthread\\.php\\?([0-9]+)' , 'index.php?threads/.\\1' ) There's two options for handling the label. One option is to put an ampersand on the end of the replacement: Code:
'index.php?threads/.\\1&' The other option is to change the pattern to include the label: Code:
'showthread.php\\?([0-9]+)-[\w-]+' Another option is to not touch the database at all, and solve this using URL rewriting in your web server - you'd use similar regex patterns and replacements (but with only single backslashes instead of the doubles that MariaDB requires). |
Hi,
Sorry for the late response. Im using mysql57 under centos 7. It looks like there is no double slant escapes used heres one copied from the xenforo forum post table viewed in text editor, this another example post from vbulletin that now sits in xenforo post table and needs converted over, the label does end with a backslash but i think that can be ignored since its trailing. Code:
[URL=\"https://domain/forums/showthread.php?66750-CURRENT-VIP-PAYMENT-PAGE\"] I planned on removing the label entirely cause I thought it would be easier to do to look like this Code:
/forums/index.php?threads/.66750/ but xenforo does allow label as option but it has to be moved before the thread ID number like this and if u dont included it, it redirects to it based on what the current thread title is. Code:
/forums/index.php?threads/current-vip-payment-page.66750/ and viewing the table you are right, there are a lot of threads in table ending in t=thread# Code:
forums/showthread.php?t=66750 |
1 Attachment(s)
So I tried this query
Code:
REGEX_REPLACE( message , 'showthread.php\\?([0-9]+)-[\w-]+' , 'index.php?threads/.\\1&' ) regex drops to a tree, what other info am i suppose to enter there |
any help with this would very much appreciated.
|
Quote:
i.e: Code:
UPDATE xf_post SET message = REPLACE(...) Code:
UPDATE xf_post SET message = REGEX_REPLACE(...) Code:
SELECT message , message2=REGEX_REPLACE(...) FROM xf_post WHERE message LIKE '%showthread.php%' LIMIT 0,10 Another version of that is to duplicate the existing column first, then you can modify the duplicate but still have an easy escape route if things doesn't work. |
To put the title before the id number, you could use something like:
Code:
REGEX_REPLACE( message , 'showthread\\.php\\?([0-9]+)-([\\w-]+)' , 'index.php?threads/\\2.\\1' ) Code:
REGEX_REPLACE( message , '(https://domain/forums/)showthread\\.php\\?([0-9]+)-([\\w-]+)' , '\\1index.php?threads/\\3.\\2' ) |
but I notice you're just using the field name message while the table name is xf_post?
are u for hire? |
Quote:
Quote:
|
I dont see PM button in your profile, I added as friend to see if it allows after. U try Pming me or u can also contact me by email or skype jaystevens5555
gmail |
Quote:
It's your data, the documentation for mysql is excellent. You've been given some excellent suggestions. Make a copy of the data and experiment. Read up on regular expressions. You is spelled y-o-u. |
Hello Scasey,
Ya understood and long time no see. You saved me previously on another DB query that didnt require regex. Well I'm doing something wrong cause pasting in the Regex command will drops down to a tree, I guess I'm not understanding. After searching through the DB, it also appears that I need to be specific with the domain as there's other domain entries not needed for replacement. I need figure out 3 Regex commands and I was perfectly clear. This is exactly what I need to do. Code:
FIND Code:
FIND Code:
FIND |
The interactive sql command is “dropping to a tree” because it’s waiting for the semicolon to terminate the statement.
|
Quote:
Ok, understood but; Code:
TO FIND Use Code:
REGEX_REPLACE( message , '(https://domain1.com/forums/)showthread\\.php\\?([0-9]+)-([\\w-]+)' , '\\1index.php?threads/\\3.\\2' ) db table: xf_post db index: message Shouldn't the table name be included in the Regex command? |
Quote:
Those documents are better than any answer you’ll get here...but we’re here to help if you don’t understand something you find there. That said, #6 is a very complete response. Read it again. Carefully. |
All times are GMT -5. The time now is 02:28 AM. |