WP Migrate DB - Version 0.3

Version Description

  • 2011-12-16 =
  • Bug fix: Null formatting error
  • Bug fix: Deprecated capability
  • Bug fix: Serialized string lengths incorrect when string contains double quotes
Download this release

Release Info

Developer bradt
Plugin Icon 128x128 WP Migrate DB
Version 0.3
Comparing to
See all releases

Code changes from version 0.2.2 to 0.3

Files changed (2) hide show
  1. readme.txt +9 -9
  2. wp-migrate-db.php +38 -27
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: bradt
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5VPMGLLK94XJC
4
  Tags: database, migrate, backup, mysql
5
  Requires at least: 2.0.3
6
- Tested up to: 3.2
7
- Stable tag: 0.2.2
8
 
9
  Exports your database, does a find and replace on URLs and file paths, then allows you to save it to your computer.
10
 
@@ -18,13 +18,8 @@ Example: <code>s:5:"hello"</code> becomes <code>s:11:"hello world"</code>
18
 
19
  == Installation ==
20
 
21
- 1. Download wp-migrate-db.&lt;version&gt;.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!
28
 
29
  == Screenshots ==
30
 
@@ -33,6 +28,11 @@ Enjoy!
33
 
34
  == Changelog ==
35
 
 
 
 
 
 
36
  = 0.2.2 - 2011-09-23 =
37
  * Bug fix: [Breaks Export](http://wordpress.org/support/topic/plugin-wp-migrate-db-breaks-export?replies=1)
38
 
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5VPMGLLK94XJC
4
  Tags: database, migrate, backup, mysql
5
  Requires at least: 2.0.3
6
+ Tested up to: 3.3
7
+ Stable tag: 0.3
8
 
9
  Exports your database, does a find and replace on URLs and file paths, then allows you to save it to your computer.
10
 
18
 
19
  == Installation ==
20
 
21
+ 1. Use WordPress' built-in installer
22
+ 2. Access the WP Migrate DB menu option under Tools
 
 
 
 
 
23
 
24
  == Screenshots ==
25
 
28
 
29
  == 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
35
+
36
  = 0.2.2 - 2011-09-23 =
37
  * Bug fix: [Breaks Export](http://wordpress.org/support/topic/plugin-wp-migrate-db-breaks-export?replies=1)
38
 
wp-migrate-db.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: WP-Migrate-DB
4
  Plugin URI: http://wordpress.org/extend/plugins/wp-migrate-db/
5
  Description: 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.
6
  Author: Brad Touesnard
7
- Version: 0.2.2
8
  Author URI: http://bradt.ca/
9
  */
10
 
@@ -261,33 +261,43 @@ class WP_Migrate_DB {
261
  }
262
 
263
  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
- }
 
 
 
 
 
 
 
 
 
 
287
  }
288
  }
289
 
290
- $subject = str_replace($search, $replace, $subject, $count);
291
 
292
  $this->replaced['nonserialized']['count'] += $count;
293
 
@@ -404,7 +414,8 @@ class WP_Migrate_DB {
404
  $value = ( null === $value || '' === $value) ? $defs[strtolower($key)] : $value;
405
  $values[] = ( '' === $value ) ? "''" : $value;
406
  } else {
407
- $values[] = "'" . str_replace($search, $replace, $this->sql_addslashes($value)) . "'";
 
408
  }
409
  }
410
  $this->stow(" \n" . $entries . implode(', ', $values) . ') ;');
@@ -555,7 +566,7 @@ class WP_Migrate_DB {
555
 
556
  function admin_menu() {
557
  if (function_exists('add_management_page')) {
558
- add_management_page('WP Migrate DB','WP Migrate DB',8,'wp-migrate-db',array($this, 'options_page'));
559
  }
560
  }
561
 
4
  Plugin URI: http://wordpress.org/extend/plugins/wp-migrate-db/
5
  Description: 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.
6
  Author: Brad Touesnard
7
+ Version: 0.3
8
  Author URI: http://bradt.ca/
9
  */
10
 
261
  }
262
 
263
  function replace_sql_strings($search, $replace, $subject) {
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
+ }
297
  }
298
  }
299
 
300
+ $subject = str_replace($search_esc, $replace_esc, $subject, $count);
301
 
302
  $this->replaced['nonserialized']['count'] += $count;
303
 
414
  $value = ( null === $value || '' === $value) ? $defs[strtolower($key)] : $value;
415
  $values[] = ( '' === $value ) ? "''" : $value;
416
  } else {
417
+ if(null === $value) $values[] = 'NULL';
418
+ else $values[] = "'" . str_replace($search, $replace, $this->sql_addslashes($value)) . "'";
419
  }
420
  }
421
  $this->stow(" \n" . $entries . implode(', ', $values) . ') ;');
566
 
567
  function admin_menu() {
568
  if (function_exists('add_management_page')) {
569
+ add_management_page('WP Migrate DB','WP Migrate DB','level_8','wp-migrate-db',array($this, 'options_page'));
570
  }
571
  }
572