Skip to content

Commit 1d7fd9b

Browse files
committed
--skip-tables implemented.
1 parent 8dd8cd2 commit 1d7fd9b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/Search_Replace_Command.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Search_Replace_Command extends WP_CLI_Command {
99
private $regex;
1010
private $regex_flags;
1111
private $regex_delimiter;
12+
private $skip_tables;
1213
private $skip_columns;
1314
private $include_columns;
1415
private $format;
@@ -74,6 +75,10 @@ class Search_Replace_Command extends WP_CLI_Command {
7475
* You might want to change this depending on your database configuration
7576
* (e.g. if you need to do fewer queries). Default: 50
7677
*
78+
* [--skip-tables=<tables>]
79+
* : Do not perform the replacement on specific tables. Use commas to
80+
* specify multiple tables.
81+
*
7782
* [--skip-columns=<columns>]
7883
* : Do not perform the replacement on specific columns. Use commas to
7984
* specify multiple columns.
@@ -148,9 +153,9 @@ class Search_Replace_Command extends WP_CLI_Command {
148153
* # Bash script: Search/replace production to development url (multisite compatible)
149154
* #!/bin/bash
150155
* if $(wp --url=http://example.com core is-installed --network); then
151-
* wp search-replace --url=http://example.com 'http://example.com' 'http://example.dev' --recurse-objects --network --skip-columns=guid
156+
* wp search-replace --url=http://example.com 'http://example.com' 'http://example.dev' --recurse-objects --network --skip-columns=guid --skip-tables=wp_users
152157
* else
153-
* wp search-replace 'http://example.com' 'http://example.dev' --recurse-objects --skip-columns=guid
158+
* wp search-replace 'http://example.com' 'http://example.dev' --recurse-objects --skip-columns=guid --skip-tables=wp_users
154159
* fi
155160
*/
156161
public function __invoke( $args, $assoc_args ) {
@@ -195,6 +200,7 @@ public function __invoke( $args, $assoc_args ) {
195200
}
196201

197202
$this->skip_columns = explode( ',', \WP_CLI\Utils\get_flag_value( $assoc_args, 'skip-columns' ) );
203+
$this->skip_tables = explode( ',', \WP_CLI\Utils\get_flag_value( $assoc_args, 'skip-tables' ) );
198204
$this->include_columns = array_filter( explode( ',', \WP_CLI\Utils\get_flag_value( $assoc_args, 'include-columns' ) ) );
199205

200206
if ( $old === $new && ! $this->regex ) {
@@ -271,6 +277,10 @@ public function __invoke( $args, $assoc_args ) {
271277
$tables = \WP_CLI\Utils\wp_get_table_names( $args, $assoc_args );
272278
foreach ( $tables as $table ) {
273279

280+
if ( in_array( $table, $this->skip_tables ) ) {
281+
continue;
282+
}
283+
274284
$table_sql = self::esc_sql_ident( $table );
275285

276286
if ( $this->export_handle ) {

0 commit comments

Comments
 (0)