interconnectit / Search-Replace-DB

This script was made to aid the process of migrating PHP and MySQL based websites. Works with most common CMSes.
https://interconnectit.com/products/search-and-replace-for-wordpress-databases/
GNU General Public License v3.0
3.99k stars 850 forks source link

Array to string conversion when using regex #364

Open devkinetic opened 3 years ago

devkinetic commented 3 years ago

When I check off regex with the tool, I get the ajax error described in the readme. I looked at the XHR response and saw an error where $this->search is used as a string when its an array. When regex is not checked off, $this->search is a string. I was able to fix searching crudely by modifying line 234 of index.php from:

-$this->search = '/' . $this->search . '/' . $mods;
+$this->search = '/' . $this->search[0] . '/' . $mods;

I also ran into the same but different error when replacing and had to use $replace[0] on srdb.class.php:

public function str_replace( $search, $replace, $string, &$count = 0 ) {
        if ( $this->regex ) {
            return preg_replace( $search, $replace[0], $string, - 1, $count );
        } elseif ( function_exists( 'mb_split' ) ) {
            return self::mb_str_replace( $search, $replace[0], $string, $count );
        } else {
            return str_replace( $search, $replace[0], $string, $count );
        }
    }

I highly doubt this is the actual fix, but it shows that the POST is different for a regex, and is broken on the latest version.