Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

search-replace fails to match URLs escaped with backslashes #3753

Closed
tedmasterweb opened this issue Jan 20, 2017 · 4 comments

Comments

@tedmasterweb
Copy link

commented Jan 20, 2017

Summary
The search-replace command fails to match URLs that have been escaped with Backslashes. This is common with the revslider plugin (wp_revslider_slides table) and probably with any plugin that prints URLs in JavaScript.

Sample input is:
http:\/\/localhost\/~tedsr\/client\/wp-content\/uploads\/revslider\/home-slider-1\/home-slider-1.jpg

For this report, I'm using revslider as an example.

Preconditions

  • Revslider is installed and at least one slider exists with two or more slides.
  • Slides use background images that have (probably) been uploaded via revslider.
  • We are moving the site to production and under SSL

Steps to Reproduce

  1. wp search-replace --all-tables 'http://localhost/~tedsr' 'https://mydomain.com'

Expected Result

  • URLs in wp_revslider_slides are updated

Actual Result

  • URLs in wp_revslider_slides are not found

Workaround
--regex=??? (not sure how to escape the backslash, how many times etc.)

Notes
I know this may be out of scope so feel free to change this from a bug to a feature request if so desired.

@danielbachhuber

This comment has been minimized.

Copy link
Member

commented Jan 20, 2017

Thanks for the amazingly detailed report, @tedmasterweb

As painful of an experience as this is, it's expected behavior. wp search-replace is a literal string search and replace procedure (or regex, if you're using the --regex flag). It's not smart enough to know what's a URL, or the different ways a URL can be stored in the database.

@raptor235

This comment has been minimized.

Copy link

commented Jun 7, 2018

Would be nice to get a sample code on how to do this... @tedmasterweb did you figure it out by any chance?

@tedmasterweb

This comment has been minimized.

Copy link
Author

commented Jun 9, 2018

As is often the case, the problem seems to have vanished with time… Revslider has an importer and exporter. In the end we just exported the slides and imported them independent of the rest of the database. IINM, this is only a problem (only manifests) when URLs are stored in serialized arrays (meta, mostly). wp-cli actually deserializes these values and does a search and replace in PHP. If you pass the --regex flag, you should be able to construct a pattern that will match these backslashed values.

For example, given http://localhost/ should be changed to https://anotherdomain/ and that the input has a raw value of http:\/\/localhost\/ when trying to match via regex, then the pattern should probably be http:\\/\\/localhost\\/ (note the double backslash).

Please note, I have not tested this but it should point you in the right direction. Good luck!

@turnermike

This comment has been minimized.

Copy link

commented May 23, 2019

I had this same problem with my deployment pipeline when migrating the database. Solution was to use the following plugin which extends wp-cli:

https://github.com/Nikschavan/revslider-search-replace

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
4 participants
You can’t perform that action at this time.