WordPress.org

Plugin Directory

Changeset 476406


Ignore:
Timestamp:
12/16/11 15:01:32 (2 years ago)
Author:
bradt
Message:

deploy from git

Location:
wp-migrate-db/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wp-migrate-db/trunk/readme.txt

    r442667 r476406  
    44Tags: database, migrate, backup, mysql 
    55Requires at least: 2.0.3 
    6 Tested up to: 3.2 
    7 Stable tag: 0.2.2 
     6Tested up to: 3.3 
     7Stable tag: 0.3 
    88 
    99Exports your database, does a find and replace on URLs and file paths, then allows you to save it to your computer. 
     
    1919== Installation == 
    2020 
    21 1. Download wp-migrate-db.<version>.zip 
    22 2. Unzip the archive 
    23 3. Upload the wp-migrate-db folder to your wp-content/plugins directory 
    24 4. Activate the plugin through the WordPress admin interface 
    25 5. Access the WP Migrate DB menu option in Settings 
    26  
    27 Enjoy! 
     211. Use WordPress' built-in installer 
     222. Access the WP Migrate DB menu option under Tools 
    2823 
    2924== Screenshots == 
     
    3328 
    3429== Changelog == 
     30 
     31= 0.3 - 2011-12-16 = 
     32* Bug fix: [Null formatting error](http://plugins.trac.wordpress.org/ticket/1430) 
     33* Bug fix: [Deprecated capability](http://plugins.trac.wordpress.org/ticket/1431) 
     34* Bug fix: Serialized string lengths incorrect when string contains double quotes 
    3535 
    3636= 0.2.2 - 2011-09-23 = 
  • wp-migrate-db/trunk/wp-migrate-db.php

    r442667 r476406  
    55Description: Exports your database as a MySQL data dump (much like phpMyAdmin), does a find and replace on URLs and file paths, then allows you to save it to your computer. 
    66Author: Brad Touesnard 
    7 Version: 0.2.2 
     7Version: 0.3 
    88Author URI: http://bradt.ca/ 
    99*/ 
     
    262262 
    263263    function replace_sql_strings($search, $replace, $subject) { 
    264         $search = mysql_real_escape_string($search); 
    265  
    266         $regex = '@s\:([0-9]+)\:"([^"]*' . preg_quote($search) . '[^"]*)"@'; 
    267         //echo $regex, '<br />'; 
    268  
    269         $count = preg_match_all($regex, $subject, $matches); 
    270  
    271         $this->replaced['serialized']['count'] += $count; 
    272  
    273         if ($count) { 
    274             for ($i = 0; $i < count($matches[0]); $i++) { 
    275                 $old_line = $matches[0][$i]; 
    276                 $str = str_replace($search, $replace, $matches[2][$i]); 
    277  
    278                 $new_line = sprintf('s:%s:"%s"', strlen($str), mysql_real_escape_string($str)); 
    279                 //str_replace($matches[0][$i], ) 
    280  
    281                 $subject = str_replace($old_line, $new_line, $subject, $count); 
    282  
    283                 if ($count) { 
    284                     $this->replaced['serialized']['strings'] .= $old_line . "\n"; 
    285                     $this->replaced['serialized']['strings'] .= $new_line . "\n\n"; 
    286                 } 
     264        $search_esc = mysql_real_escape_string($search); 
     265        $replace_esc = mysql_real_escape_string($replace); 
     266 
     267        $regex = '@s:([0-9]+):"(.*?)' . preg_quote($search_esc, '@') . '(.*?)";@'; 
     268         
     269        if ( preg_match_all( $regex, $subject, $matches, PREG_SET_ORDER ) ) { 
     270            foreach ( $matches as $match ) { 
     271                /* 
     272                 For some reason, the ungreedy regex above is not working as 
     273                 you'd expect ungreedy to work and is matching strings with 
     274                 multiple serialized strings (PHP 5.3.2). So we need to to 
     275                 isolate each. 
     276                */ 
     277                if ( preg_match_all( '@s:([0-9]+):"(.*?)";@', $match[0], $finds, PREG_SET_ORDER ) ) { 
     278                    foreach ( $finds as $find ) { 
     279                        if ( false === strpos( $find[0], $search_esc ) ) continue; 
     280                         
     281                        list( $old_line, $old_strlen, $old_str) = $find; 
     282                         
     283                        $new_str = str_replace( $search_esc, $replace_esc, $old_str); 
     284                        $new_strlen = strlen($new_str) - strlen($old_str) + $old_strlen; 
     285                        $new_line = sprintf('s:%s:"%s";', $new_strlen, $new_str); 
     286 
     287                        $subject = str_replace($old_line, $new_line, $subject, $count); 
     288         
     289                        if ($count) { 
     290                            $this->replaced['serialized']['strings'] .= $old_line . "\n"; 
     291                            $this->replaced['serialized']['strings'] .= $new_line . "\n\n"; 
     292 
     293                            $this->replaced['serialized']['count'] += $count; 
     294                        } 
     295                    } 
     296                } 
    287297            } 
    288298        } 
    289299 
    290         $subject = str_replace($search, $replace, $subject, $count); 
     300        $subject = str_replace($search_esc, $replace_esc, $subject, $count); 
    291301 
    292302        $this->replaced['nonserialized']['count'] += $count; 
     
    405415                                $values[] = ( '' === $value ) ? "''" : $value; 
    406416                            } else { 
    407                                 $values[] = "'" . str_replace($search, $replace, $this->sql_addslashes($value)) . "'"; 
     417                                if(null === $value) $values[] = 'NULL'; 
     418                                else $values[] = "'" . str_replace($search, $replace, $this->sql_addslashes($value)) . "'"; 
    408419                            } 
    409420                        } 
     
    556567    function admin_menu() { 
    557568        if (function_exists('add_management_page')) { 
    558             add_management_page('WP Migrate DB','WP Migrate DB',8,'wp-migrate-db',array($this, 'options_page')); 
     569            add_management_page('WP Migrate DB','WP Migrate DB','level_8','wp-migrate-db',array($this, 'options_page')); 
    559570        } 
    560571    } 
Note: See TracChangeset for help on using the changeset viewer.