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
4k stars 855 forks source link

Ignore $subjects that cannot be multibyte split (#239) #266

Closed andrewryantech closed 4 years ago

andrewryantech commented 5 years ago

This appears to occur when the database field contains binary data. Some wordpress plugins do this, eg Wordfence

It appears there are no unit test to cover this case. I considered adding them, but looks like there's a bit of work to get them modernised. Would rather not sink time into that unless the maintainers are on board.

Considered using mb_detect_encoding, but it appears there are cases where mb_detect_encoding can detect a valid encoding for which mb_split still returns false.

Not sure if there are cases where we do really want to modify binary data, but seems like a pretty risky edge case imo.

stakeworks commented 5 years ago
public function get_columns( $table ) {
    $primary_key = array();
    $columns = array( );

    // Get a list of columns in this table
    $fields = $this->db_query( "DESCRIBE {$table}" );
    if ( ! $fields ) {
        $this->add_error( $this->db_error( ), 'db' );
    } else {
        while( $column = $this->db_fetch( $fields ) ) {
            if ( false !== stristr( $column['Type'], 'binary' )){
                $this->add_error( 'Skip field ' . $table . ' - ' . $column[ 'Field' ] . ', fieldtype is ' . $column['Type'] , 'results' );
                continue;
            }

            $columns[] = $column[ 'Field' ];
            if ( $column[ 'Key' ] == 'PRI' )
                $primary_key[] = $column[ 'Field' ];
        }
    }

    return array( $primary_key, $columns );
}
harryfear commented 4 years ago

Great, does this mean the problem's fixed? :)