OSDN Git Service

Specify any columns to be skipped.
authorDylan Kuhn <dylan.k.kuhn@gmail.com>
Tue, 21 May 2013 03:57:40 +0000 (20:57 -0700)
committerDylan Kuhn <dylan.k.kuhn@gmail.com>
Tue, 21 May 2013 03:57:40 +0000 (20:57 -0700)
man-src/search-replace.txt
man/search-replace.1
php/commands/search-replace.php

index f4ed828..0168065 100644 (file)
@@ -2,7 +2,7 @@
 
 This command will go through all rows in all tables and will replace all appearances of the old string with the new one.
 
-It will correctly handle serialized values.
+It will correctly handle serialized values, and will not change primary key values.
 
 ## OPTIONS
 
@@ -10,12 +10,12 @@ It will correctly handle serialized values.
 
        Show report, but don't perform the changes.
 
-* `--skip-guids`:
+* `--skip-columns=<columns>`:
 
-       Do not perform the replacement in columns named 'guid'. Use to preserve existing GUID values when changing domain names.
+       Do not perform the replacement in the comma-separated columns. Useful to preserve existing guid column values when changing domain names.
 
 ## EXAMPLES
 
-       wp search-replace 'http://example.dev' 'http://example.com' --dry-run
+       wp search-replace 'http://example.dev' 'http://example.com' --dry-run --skip-columns=guid
 
        wp search-replace 'foo' 'bar' wp_posts wp_postmeta wp_terms
index edd227a..c532ce2 100644 (file)
@@ -7,13 +7,13 @@
 \fBwp\-search\-replace\fR \- Search/replace strings in the database\.
 .
 .SH "SYNOPSIS"
-wp search\-replace \fIold\fR \fInew\fR [\fItable\fR\.\.\.] [\-\-dry\-run] [\-\-skip\-guids]
+wp search\-replace \fIold\fR \fInew\fR [\fItable\fR\.\.\.] [\-\-dry\-run] [\-\-skip\-columns=\fIcolumns\fR]
 .
 .SH "DESCRIPTION"
 This command will go through all rows in all tables and will replace all appearances of the old string with the new one\.
 .
 .P
-It will correctly handle serialized values\.
+It will correctly handle serialized values, and will not change primary key values\.
 .
 .SH "OPTIONS"
 .
@@ -24,16 +24,16 @@ It will correctly handle serialized values\.
 Show report, but don\'t perform the changes\.
 .
 .TP
-\fB\-\-skip\-guids\fR:
+\fB\-\-skip\-columns=<columns>\fR:
 .
 .IP
-Do not perform the replacement in columns named \'guid\'\. Use to preserve existing GUID values when changing domain names\.
+Do not perform the replacement in the comma\-separated columns\. Useful to preserve existing guid column values when changing domain names\.
 .
 .SH "EXAMPLES"
 .
 .nf
 
-wp search\-replace \'http://example\.dev\' \'http://example\.com\' \-\-dry\-run
+wp search\-replace \'http://example\.dev\' \'http://example\.com\' \-\-dry\-run \-\-skip\-columns=guid
 
 wp search\-replace \'foo\' \'bar\' wp_posts wp_postmeta wp_terms
 .
index 752b2d5..c5ffbe9 100644 (file)
@@ -10,7 +10,7 @@ class Search_Replace_Command extends WP_CLI_Command {
        /**
         * Search/replace strings in the database.
         *
-        * @synopsis <old> <new> [<table>...] [--dry-run] [--skip-guids]
+        * @synopsis <old> <new> [<table>...] [--dry-run] [--skip-columns=<columns>]
         */
        public function __invoke( $args, $assoc_args ) {
                global $wpdb;
@@ -30,13 +30,16 @@ class Search_Replace_Command extends WP_CLI_Command {
 
                $dry_run = isset( $assoc_args['dry-run'] );
 
-               $skip_guids = isset( $assoc_args['skip-guids'] );
+               if ( isset( $assoc_args['skip-columns'] ) )
+                       $skip_columns = explode( ',', $assoc_args['skip-columns'] );
+               else
+                       $skip_columns = array();
 
                foreach ( $tables as $table ) {
                        list( $primary_key, $columns ) = self::get_columns( $table );
 
                        foreach ( $columns as $col ) {
-                               if ( $skip_guids && 'guid' === $col )
+                               if ( in_array( $col, $skip_columns ) )
                                        continue;
 
                                $count = self::handle_col( $col, $primary_key, $table, $old, $new,