Automattic / go-search-replace

🚀 Search & replace URLs in WordPress SQL files.
https://wpvip.com/2018/03/28/data-sync-on-vip-go/
GNU General Public License v3.0
90 stars 19 forks source link

Replacing "subdomain." prefix with empty string "" #32

Open rivaros opened 3 years ago

rivaros commented 3 years ago

Have recently come across your wonderful script to cure Wordpress database copies between domains.

Have one more challenge - I just need to replace "staging." subdomain in all urls mentioned in sql file (including serialized PHP objects).

So replacement is just empty string (""). My wordpress installation is multi-site, so there are multiple subsiteX.maindomain.com urls as well as staging.subsiteX.maindomain.com on staging server.

While migrating from staging to production we need to delete away the "staging." subdomain.

rivaros commented 3 years ago

@joshbetz In your code you check that replacement is at least 2 chars

                to = args[(i*2)+1]
        if !validInput(to, minOutLength) {
            fmt.Fprintln(os.Stderr, "Invalid <to>, minimum length is 2")
            os.Exit(3)
            return
        }

Could this be a problem if that check is removed?

joshbetz commented 3 years ago

Can you replace staging.subsiteX.maindomain.com with subsiteX.maindomain.com?