Forum Discussion

Wendy_S's avatar
9 years ago

Any way to change urls in posts to a new url from the backend/database by an sql statement/similar

Hi All.   Is there any way to bulk change url through a backend process? For example, if posts contain links and those links have changed due to a tool change. The thing that needs to happen i...
  • Claudius's avatar
    9 years ago

    Hi Wendy,

     

    lovely task you are outlining there. Theoretically SQL knows about a REPLACE() function to replace substrings in one call, but unfortunately that never made it to LiQL. Arguably it's not the most common activity on a community dataset :)

     

    You would need to approach this in a script with three steps:

    1. Pull all matching messages and their ID via a SELECT id, body FROM messages WHERE body matches ('yourstring') call 
    2. For each message retrieved in the 1st step perform a substring replace.
    3. Write the updated message back via the UPDATE function

     

    All the needed LiQL functions and parameters are described in the API v2 documentation on the message resource. This can be done as a tool with almost any script language or also realized on platform via a Lithium custom component.

     

    While you are at it you might consider future proofing this approach for the next url update in 3 years ;) For example you could move the urls into a new custom data field that would be easier to update. This would require then to update your message UI to show this additional link in a separate UI element.