-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Search-replace does not replace keys in serialized values #137
Comments
Can confirm, I store an array of URLs and configuration for them in update_option(
'my_plugin_configuration'
array(
'https://example.com' => 'conf1,conf3, conf5, conf7',
'https://example.com/page1' => 'conf1',
'https://example.com/category1/page4' => ''
) and running |
Possibly related to #45 |
Hi, any update on this one? I'm experiencing the same issue. I'm using wp search-replace mainly to replace the URL and Yoast stores postmeta with the URL as a key.
which is stored serialized as such:
|
@LjupcheVasilev No update, but you can use a regex like I did in #45 to handle the serialized strings. |
I think it was intentional to ignore keys originally. We could add a Feel free to submit a pull request, if you'd like. Here is some guidance on our pull request best practices, if it's helpful. |
Bug Report
Describe the current, buggy behavior
When running a search-replace on the database and explicitly declaring
--recurse-objects
, the command does not change array keys in serialized strings, only array values. As such, keys get looked over and do not get correctly replaced by this command.Note that this may also occur even if
--recurse-objects
is not explicitly declared, as it appears that this value is true even if not declared as per https://developer.wordpress.org/cli/commands/search-replace/.Describe how other contributors can replicate this bug
wp_options
table for the theme's customization information.wp_options
table has anoption_name
valuetheme_mods_twentytwenty
with anoption_value
likea:3:{s:18:"custom_css_post_id";i:-1;s:16:"sidebars_widgets";a:2:{s:4:"time";i:1585600348;s:4:"data";a:3:{s:19:"wp_inactive_widgets";a:0:{}s:9:"sidebar-1";a:4:{i:0;s:8:"search-2";i:1;s:14:"recent-posts-2";i:2;s:17:"recent-comments-2";i:3;s:10:"calendar-3";}s:9:"sidebar-2";a:3:{i:0;s:10:"archives-2";i:1;s:12:"categories-2";i:2;s:6:"meta-2";}}}s:18:"nav_menu_locations";a:0:{}}
. We are particularly interested in the sidebar names,sidebar-1
andsidebar-2
.sidebar-1
tomy-sidebar-1
.wp search-replace "sidebar-1" "my-sidebar-1" --dry-run --all-tables
.wp_options
table listed above.Describe what you would expect as the correct outcome
When running the above described
wp search-replace
, it should also replace array keys in serialized string values.Let us know what environment you are running this on
Provide a possible solution
The applicable section of the code appears to be https://github.com/wp-cli/search-replace-command/blob/master/src/WP_CLI/SearchReplacer.php#L91-L93
It would be necessary to alter this to also replace keys after the data had been searched and replaced.
Provide additional context/Screenshots
Replacing array keys may have unintended consequences, especially if the key exists elsewhere in the database in a place that the person running this command may be unaware of. Perhaps adding an option such as
--replace-keys
that will ONLY replace array keys in asearch-replace
?The text was updated successfully, but these errors were encountered: