wp-cli / search-replace-command

Searches/replaces strings in the database.
MIT License
57 stars 45 forks source link

Flag --no-recurse-objects is ignored #136

Closed figureone closed 10 months ago

figureone commented 4 years ago

Bug Report

Describe the current, buggy behavior

Aloha, although the docs describe a --no-recurse-objects flag:

[--recurse-objects] Enable recursing into objects to replace strings. Defaults to true; pass –no-recurse-objects to disable.

https://developer.wordpress.org/cli/commands/search-replace/

it doesn't seem to be respected. We tried variants of --recurse-objects=false but there doesn't seem to be a way to get a falsey value into the flag.

Describe how other contributors can replicate this bug

On vanilla WordPress:

$ wp search-replace "This is an example" "Replacement" wp_posts --report-changed-only --dry-run --no-recurse-objects
+----------+--------------+--------------+------+
| Table    | Column       | Replacements | Type |
+----------+--------------+--------------+------+
| wp_posts | post_content | 2            | PHP  |
+----------+--------------+--------------+------+
Success: 2 replacements to be made.

Describe what you would expect as the correct outcome

Note the replacement type is still PHP; it should be SQL since the --no-recurse-objects flag is present.

Let us know what environment you are running this on

$ wp cli info
OS: Linux 4.15.0-91-generic #92-Ubuntu SMP Fri Feb 28 11:09:48 UTC 2020 x86_64
Shell:  /bin/bash
PHP binary: /usr/bin/php7.2
PHP version:    7.2.24-0ubuntu0.18.04.3
php.ini used:   /etc/php/7.2/cli/php.ini
WP-CLI root dir:    phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:  phar://wp-cli.phar/vendor
WP_CLI phar path:   /var/www/html
WP-CLI packages dir:
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 2.4.0

Provide a possible solution

Probably just add the flag in Search_Replace_Command.php:invoke(), below the flag vars:

        if ( \WP_CLI\Utils\get_flag_value( $assoc_args, 'no-recurse-objects' ) ) {
            $this->recurse_objects = false;
        }

Though this isn't tested.

planetahuevo commented 3 years ago

I was going to open another issue, but it is related to this, so I will add my comment here. When reading the description [--recurse-objects] Enable recursing into objects to replace strings. Defaults to true; pass –no-recurse-objects to disable.

I understand that adding the flag will make the search and replace to Enable recursing. And just not adding that flag will disable the recursing into objects. So this part is confusing: "Defaults to true; pass –no-recurse-objects to disable."

Can someone explain if the search and replace command include by default the "recursing into objects to replace strings" when no flag is added?

Thanks

danielbachhuber commented 10 months ago

Note the replacement type is still PHP; it should be SQL since the --no-recurse-objects flag is present.

This is incorrect. When --no-recurse-objects is used, wp search-replace will skip any serialized objects it finds, not forcefully replace them with SQL (https://github.com/wp-cli/wp-cli/pull/2222).

Can someone explain if the search and replace command include by default the "recursing into objects to replace strings" when no flag is added?

Yes, this is the default behavior.