Search-replace does not replace keys in serialized values
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 52/100
Hướng nghiên cứu
Start in src/WP_CLI/SearchReplacer.php at lines 91-93 and reproduce the documented wp search-replace command against serialized wp_options data. Inspect how serialized array keys are traversed and consider the proposed --replace-keys behavior, including its unintended-consequence concern. Done means the expected sidebar key replacement is handled and covered by the relevant project tests.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Bug Report
- Yes, I reviewed the contribution guidelines.
- Yes, more specifically, I reviewed the guidelines on how to write clear bug reports.
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
- Do a basic install of WordPress 5.3.2
- Set up wp-cli 2.4.0
- Log in the WordPress site and activate the theme "Twenty Seventeen", then activate the theme "Twenty Twenty". This forces a write of the data for the theme to the
wp_optionstable for the theme's customization information. - Looking at the database, the
wp_optionstable has anoption_namevaluetheme_mods_twentytwentywith anoption_valuelikea: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-1andsidebar-2. - In this particular case, say we have added a new sidebar location to the theme, but we do not want to have to re-add all of the widgets to this new sidebar. We want to do a rewrite of the sidebar key value for
sidebar-1tomy-sidebar-1. - Run
wp search-replace "sidebar-1" "my-sidebar-1" --dry-run --all-tables. - The results will not include any values in the
wp_optionstable 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
vagrant@ubuntu-bionic:/var/www/html$ wp --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: /home/vagrant/.wp-cli/config.yml
WP-CLI project config:
WP-CLI version: 2.4.0
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 a search-replace?
- Ngôn ngữ chính
- Gherkin
- Star
- 61
- Fork
- 47
- Merge trung bình
- 8 phút
- Pull request đã merge (30 ngày)
- 1
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của wp-cli/search-replace-command
-
bug command:search-replace scope:distribution state:unconfirmed
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
wp-cli/search-replace-command#231 · 5 bình luận ·
-
command:search-replace
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
wp-cli/search-replace-command#194 · 1 bình luận ·
-
command:search-replace contributor-day
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
wp-cli/search-replace-command#186 · 2 bình luận · 11 reaction ·
-
command:search-replace
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
wp-cli/search-replace-command#142 · 5 bình luận · 2 reaction ·
-
Progress bar Đang mởcommand:search-replace
wp-cli/search-replace-command#134 · 1 bình luận · 6 reaction · 1 người được giao ·
Tất cả issue của wp-cli/search-replace-command
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
from:qa priority:P2 reliability tech-debt
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
spec-kitty/spec-kitty#4874 ·
-
0. Needs triage bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
nextcloud/fulltextsearch#1011 ·
-
[deep-report] Docs: collapse advanced install options below Day-one commands table in cli.md Đang mởautomation code-quality cookie deep-report documentation improvement quick-win task-mining
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100