Skip to content

Commit 9a2facf

Browse files
authored
Merge branch 'main' into copilot/add-progress-bar-indicator
2 parents b3f2da1 + 8b94d6e commit 9a2facf

File tree

6 files changed

+255
-20
lines changed

6 files changed

+255
-20
lines changed

.gitattributes

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/.actrc export-ignore
2+
/.distignore export-ignore
3+
/.editorconfig export-ignore
4+
/.github export-ignore
5+
/.gitignore export-ignore
6+
/.typos.toml export-ignore
7+
/AGENTS.md export-ignore
8+
/behat.yml export-ignore
9+
/features export-ignore
10+
/phpcs.xml.dist export-ignore
11+
/phpstan.neon.dist export-ignore
12+
/phpunit.xml.dist export-ignore
13+
/tests export-ignore
14+
/wp-cli.yml export-ignore

.github/workflows/copilot-setup-steps.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@ jobs:
2121

2222
- name: Check existence of composer.json file
2323
id: check_composer_file
24-
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3
25-
with:
26-
files: "composer.json"
24+
run: echo "files_exists=$(test -f composer.json && echo true || echo false)" >> "$GITHUB_OUTPUT"
2725

2826
- name: Set up PHP environment
2927
if: steps.check_composer_file.outputs.files_exists == 'true'
30-
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # v2
28+
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # v2
3129
with:
3230
php-version: 'latest'
3331
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
@@ -38,7 +36,7 @@ jobs:
3836

3937
- name: Install Composer dependencies & cache dependencies
4038
if: steps.check_composer_file.outputs.files_exists == 'true'
41-
uses: ramsey/composer-install@a35c6ebd3d08125aaf8852dff361e686a1a67947 # v3
39+
uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # v3
4240
env:
4341
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
4442
with:

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ multisite, this will just be the tables for the current site unless
2323
Search/replace intelligently handles PHP serialized data, and does not
2424
change primary key values.
2525

26+
Tables without a primary key are skipped. To check whether a table has a
27+
primary key, run `wp db query 'DESCRIBE <table>'` and look for 'PRI' in
28+
the Key column.
29+
2630
**OPTIONS**
2731

2832
[<old>]
@@ -75,11 +79,13 @@ change primary key values.
7579

7680
[--skip-columns=<columns>]
7781
Do not perform the replacement on specific columns. Use commas to
78-
specify multiple columns.
82+
specify multiple columns. Table-qualified column names ("table.column")
83+
are supported to apply the skip to a specific table only.
7984

8085
[--include-columns=<columns>]
8186
Perform the replacement on specific columns. Use commas to
82-
specify multiple columns.
87+
specify multiple columns. Table-qualified column names ("table.column")
88+
are supported to apply the inclusion to a specific table only.
8389

8490
[--precise]
8591
Force the use of PHP (instead of SQL) for all columns. By default, the command
@@ -193,6 +199,10 @@ Want to contribute a new feature? Please first [open a new issue](https://github
193199

194200
Once you've decided to commit the time to seeing your pull request through, [please follow our guidelines for creating a pull request](https://make.wordpress.org/cli/handbook/pull-requests/) to make sure it's a pleasant experience. See "[Setting up](https://make.wordpress.org/cli/handbook/pull-requests/#setting-up)" for details specific to working on this package locally.
195201

202+
### License
203+
204+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
205+
196206
## Support
197207

198208
GitHub issues aren't for general support questions, but there are other venues you can try: https://wp-cli.org/#support

features/search-replace.feature

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ Feature: Do global search/replace
4141
| Table | Column | Replacements | Type |
4242
| wp_posts | post_content | 0 | SQL |
4343

44+
When I run `wp search-replace foo bar --skip-columns=wp_posts.guid`
45+
Then STDOUT should not contain:
46+
"""
47+
guid
48+
"""
49+
50+
When I run `wp search-replace foo bar --include-columns=wp_posts.post_content`
51+
Then STDOUT should be a table containing rows:
52+
| Table | Column | Replacements | Type |
53+
| wp_posts | post_content | 0 | SQL |
54+
4455
@require-mysql
4556
Scenario: Multisite search/replace
4657
Given a WP multisite install
@@ -68,6 +79,31 @@ Feature: Do global search/replace
6879
wp_awesome
6980
"""
7081

82+
@require-mysql
83+
Scenario: Skip views during search/replace
84+
Given a WP install
85+
And I run `wp db query "CREATE VIEW wp_posts_view AS SELECT ID, post_title FROM wp_posts;"`
86+
87+
When I run `wp search-replace foo bar --all-tables-with-prefix`
88+
Then STDOUT should contain:
89+
"""
90+
wp_posts_view
91+
"""
92+
And STDOUT should contain:
93+
"""
94+
skipped (view)
95+
"""
96+
97+
When I run `wp search-replace foo bar --all-tables`
98+
Then STDOUT should contain:
99+
"""
100+
wp_posts_view
101+
"""
102+
And STDOUT should contain:
103+
"""
104+
skipped (view)
105+
"""
106+
71107
@require-mysql
72108
Scenario: Run on unregistered, unprefixed tables with --all-tables flag
73109
Given a WP install
@@ -185,6 +221,8 @@ Feature: Do global search/replace
185221
1 rows affected
186222
"""
187223

224+
# See https://github.com/wp-cli/search-replace-command/issues/190
225+
@skip-sqlite
188226
Scenario: Regex search/replace
189227
Given a WP install
190228
When I run `wp search-replace '(Hello)\s(world)' '$2, $1' --regex`
@@ -238,6 +276,45 @@ Feature: Do global search/replace
238276
| key | value |
239277
| header_image_data | {"url":"https:\/\/example.com\/foo.jpg"} |
240278

279+
@require-mysql
280+
Scenario: Search and replace handles JSON-encoded URLs in post content
281+
Given a WP install
282+
283+
When I run `wp post create --post_content='{"src":"http:\/\/example.com\/wp-content\/uploads\/fonts\/test.woff2","fontWeight":"400"}' --post_status=publish --porcelain`
284+
Then save STDOUT as {POST_ID}
285+
286+
When I run `wp post get {POST_ID} --field=post_content`
287+
Then STDOUT should contain:
288+
"""
289+
http:\/\/example.com
290+
"""
291+
292+
When I run `wp search-replace 'http://example.com' 'http://newdomain.com' wp_posts --include-columns=post_content`
293+
Then STDOUT should be a table containing rows:
294+
| Table | Column | Replacements | Type |
295+
| wp_posts | post_content | 1 | SQL |
296+
297+
When I run `wp post get {POST_ID} --field=post_content`
298+
Then STDOUT should contain:
299+
"""
300+
http:\/\/newdomain.com
301+
"""
302+
And STDOUT should not contain:
303+
"""
304+
http:\/\/example.com
305+
"""
306+
307+
When I run `wp search-replace 'http://newdomain.com' 'http://example.com' wp_posts --include-columns=post_content --precise`
308+
Then STDOUT should be a table containing rows:
309+
| Table | Column | Replacements | Type |
310+
| wp_posts | post_content | 1 | PHP |
311+
312+
When I run `wp post get {POST_ID} --field=post_content`
313+
Then STDOUT should contain:
314+
"""
315+
http:\/\/example.com
316+
"""
317+
241318
@require-mysql
242319
Scenario: Search and replace with quoted strings
243320
Given a WP install
@@ -884,6 +961,8 @@ Feature: Do global search/replace
884961
"""
885962
And STDERR should be empty
886963

964+
# See https://github.com/wp-cli/search-replace-command/issues/190
965+
@skip-sqlite
887966
Scenario: Logging with regex replace
888967
Given a WP install
889968

@@ -1246,6 +1325,8 @@ Feature: Do global search/replace
12461325
[field_count] => 2
12471326
"""
12481327

1328+
# See https://github.com/wp-cli/search-replace-command/issues/190
1329+
@skip-sqlite
12491330
Scenario: Regex search/replace with `--regex-limit=1` option
12501331
Given a WP install
12511332
And I run `wp post create --post_content="I have a pen, I have an apple. Pen, pine-apple, apple-pen."`
@@ -1256,6 +1337,8 @@ Feature: Do global search/replace
12561337
I have a pen, I have an orange. Pen, pine-apple, apple-pen.
12571338
"""
12581339

1340+
# See https://github.com/wp-cli/search-replace-command/issues/190
1341+
@skip-sqlite
12591342
Scenario: Regex search/replace with `--regex-limit=2` option
12601343
Given a WP install
12611344
And I run `wp post create --post_content="I have a pen, I have an apple. Pen, pine-apple, apple-pen."`
@@ -1266,6 +1349,8 @@ Feature: Do global search/replace
12661349
I have a pen, I have an orange. Pen, pine-orange, apple-pen.
12671350
"""
12681351

1352+
# See https://github.com/wp-cli/search-replace-command/issues/190
1353+
@skip-sqlite
12691354
Scenario: Regex search/replace with incorrect or default `--regex-limit`
12701355
Given a WP install
12711356
When I try `wp search-replace '(Hello)\s(world)' '$2, $1' --regex --regex-limit=asdf`
@@ -1560,3 +1645,21 @@ Feature: Do global search/replace
15601645
"""
15611646
--old-content
15621647
"""
1648+
1649+
1650+
@require-mysql
1651+
Scenario: Warn when updating a table fails due to a database error
1652+
Given a WP install
1653+
And I run `wp db query "CREATE TABLE wp_readonly_test ( id int(11) unsigned NOT NULL AUTO_INCREMENT, data TEXT, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"`
1654+
And I run `wp db query "INSERT INTO wp_readonly_test (data) VALUES ('old-value');"`
1655+
And I run `wp db query "CREATE TRIGGER prevent_update BEFORE UPDATE ON wp_readonly_test FOR EACH ROW SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Table is read-only';"`
1656+
1657+
When I try `wp search-replace old-value new-value --all-tables-with-prefix`
1658+
Then STDERR should contain:
1659+
"""
1660+
Error updating column 'data' in table 'wp_readonly_test'
1661+
"""
1662+
And STDERR should contain:
1663+
"""
1664+
Table is read-only
1665+
"""

0 commit comments

Comments
 (0)