Skip to content

Commit b71179a

Browse files
committed
Merge branch 'main' into callback-104
2 parents 6176cb0 + b82e722 commit b71179a

6 files changed

Lines changed: 321 additions & 37 deletions

File tree

.github/workflows/code-quality.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ on:
66
branches:
77
- main
88
- master
9+
schedule:
10+
- cron: '17 2 * * *' # Run every day on a seemly random time.
911

1012
jobs:
1113
code-quality:

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

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

1818
steps:
1919
- name: Checkout code
20-
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
20+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
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'
@@ -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@3cf229dc2919194e9e36783941438d17239e8520 # v3
39+
uses: ramsey/composer-install@a35c6ebd3d08125aaf8852dff361e686a1a67947 # v3
4240
env:
4341
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
4442
with:

README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Quick links: [Using](#using) | [Installing](#installing) | [Contributing](#contr
1010
## Using
1111

1212
~~~
13-
wp search-replace <old> <new> [<table>...] [--dry-run] [--network] [--all-tables-with-prefix] [--all-tables] [--export[=<file>]] [--export_insert_size=<rows>] [--skip-tables=<tables>] [--skip-columns=<columns>] [--include-columns=<columns>] [--precise] [--recurse-objects] [--verbose] [--regex] [--regex-flags=<regex-flags>] [--regex-delimiter=<regex-delimiter>] [--regex-limit=<regex-limit>] [--format=<format>] [--report] [--report-changed-only] [--log[=<file>]] [--before_context=<num>] [--after_context=<num>]
13+
wp search-replace [<old>] [<new>] [<table>...] [--old=<value>] [--new=<value>] [--dry-run] [--network] [--all-tables-with-prefix] [--all-tables] [--export[=<file>]] [--export_insert_size=<rows>] [--skip-tables=<tables>] [--skip-columns=<columns>] [--include-columns=<columns>] [--precise] [--recurse-objects] [--verbose] [--regex] [--regex-flags=<regex-flags>] [--regex-delimiter=<regex-delimiter>] [--regex-limit=<regex-limit>] [--format=<format>] [--report] [--report-changed-only] [--log[=<file>]] [--before_context=<num>] [--after_context=<num>]
1414
~~~
1515

1616
Searches through all rows in a selection of tables and replaces
@@ -25,16 +25,24 @@ change primary key values.
2525

2626
**OPTIONS**
2727

28-
<old>
28+
[<old>]
2929
A string to search for within the database.
3030

31-
<new>
31+
[<new>]
3232
Replace instances of the first string with this new string.
3333

3434
[<table>...]
3535
List of database tables to restrict the replacement to. Wildcards are
3636
supported, e.g. `'wp_*options'` or `'wp_post*'`.
3737

38+
[--old=<value>]
39+
An alternative way to specify the search string. Use this when the
40+
search string starts with '--' (e.g., --old='--some-text').
41+
42+
[--new=<value>]
43+
An alternative way to specify the replacement string. Use this when the
44+
replacement string starts with '--' (e.g., --new='--other-text').
45+
3846
[--dry-run]
3947
Run the entire search/replace operation and show report, but don't save
4048
changes to the database.
@@ -141,6 +149,9 @@ change primary key values.
141149
# Search/replace to a SQL file without transforming the database
142150
$ wp search-replace foo bar --export=database.sql
143151

152+
# Search/replace string containing hyphens
153+
$ wp search-replace --old='--old-string' --new='new-string'
154+
144155
# Use precise mode for complex serialized data
145156
$ wp search-replace 'oldurl.com' 'newurl.com' --precise
146157

features/search-replace.feature

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,45 @@ Feature: Do global search/replace
238238
| key | value |
239239
| header_image_data | {"url":"https:\/\/example.com\/foo.jpg"} |
240240

241+
@require-mysql
242+
Scenario: Search and replace handles JSON-encoded URLs in post content
243+
Given a WP install
244+
245+
When I run `wp post create --post_content='{"src":"http:\/\/example.com\/wp-content\/uploads\/fonts\/test.woff2","fontWeight":"400"}' --post_status=publish --porcelain`
246+
Then save STDOUT as {POST_ID}
247+
248+
When I run `wp post get {POST_ID} --field=post_content`
249+
Then STDOUT should contain:
250+
"""
251+
http:\/\/example.com
252+
"""
253+
254+
When I run `wp search-replace 'http://example.com' 'http://newdomain.com' wp_posts --include-columns=post_content`
255+
Then STDOUT should be a table containing rows:
256+
| Table | Column | Replacements | Type |
257+
| wp_posts | post_content | 1 | SQL |
258+
259+
When I run `wp post get {POST_ID} --field=post_content`
260+
Then STDOUT should contain:
261+
"""
262+
http:\/\/newdomain.com
263+
"""
264+
And STDOUT should not contain:
265+
"""
266+
http:\/\/example.com
267+
"""
268+
269+
When I run `wp search-replace 'http://newdomain.com' 'http://example.com' wp_posts --include-columns=post_content --precise`
270+
Then STDOUT should be a table containing rows:
271+
| Table | Column | Replacements | Type |
272+
| wp_posts | post_content | 1 | PHP |
273+
274+
When I run `wp post get {POST_ID} --field=post_content`
275+
Then STDOUT should contain:
276+
"""
277+
http:\/\/example.com
278+
"""
279+
241280
@require-mysql
242281
Scenario: Search and replace with quoted strings
243282
Given a WP install
@@ -1392,3 +1431,145 @@ Feature: Do global search/replace
13921431
"""
13931432
Success: Made 0 replacements.
13941433
"""
1434+
1435+
@require-mysql
1436+
Scenario: Search/replace strings starting with hyphens using --old and --new flags
1437+
Given a WP install
1438+
And I run `wp post create --post_title="Test Post" --post_content="This is --old-content and more text" --porcelain`
1439+
Then save STDOUT as {POST_ID}
1440+
1441+
When I run `wp search-replace --old='--old-content' --new='--new-content'`
1442+
Then STDOUT should contain:
1443+
"""
1444+
wp_posts
1445+
"""
1446+
And the return code should be 0
1447+
1448+
When I run `wp post get {POST_ID} --field=post_content`
1449+
Then STDOUT should contain:
1450+
"""
1451+
--new-content
1452+
"""
1453+
And STDOUT should not contain:
1454+
"""
1455+
--old-content
1456+
"""
1457+
1458+
@require-mysql
1459+
Scenario: Error when neither positional args nor flags provided
1460+
Given a WP install
1461+
1462+
When I try `wp search-replace`
1463+
Then STDERR should contain:
1464+
"""
1465+
Please provide both <old> and <new> arguments
1466+
"""
1467+
And STDERR should contain:
1468+
"""
1469+
--old
1470+
"""
1471+
And STDERR should contain:
1472+
"""
1473+
--new
1474+
"""
1475+
And the return code should be 1
1476+
1477+
@require-mysql
1478+
Scenario: Error when only --old flag provided without --new
1479+
Given a WP install
1480+
1481+
When I try `wp search-replace --old='test-value'`
1482+
Then STDERR should contain:
1483+
"""
1484+
Please provide the <new> argument
1485+
"""
1486+
And the return code should be 1
1487+
1488+
@require-mysql
1489+
Scenario: Error when only --new flag provided without --old
1490+
Given a WP install
1491+
1492+
When I try `wp search-replace --new='test-value'`
1493+
Then STDERR should contain:
1494+
"""
1495+
Please provide the <old> argument
1496+
"""
1497+
And the return code should be 1
1498+
1499+
@require-mysql
1500+
Scenario: Error when both flags and positional arguments provided
1501+
Given a WP install
1502+
1503+
When I try `wp search-replace --old='flag-old' --new='flag-new' 'positional-arg'`
1504+
Then STDERR should contain:
1505+
"""
1506+
Cannot use both positional arguments and --old/--new flags
1507+
"""
1508+
And the return code should be 1
1509+
1510+
@require-mysql
1511+
Scenario: Error when empty string provided via --old flag
1512+
Given a WP install
1513+
1514+
When I try `wp search-replace --old='' --new='replacement'`
1515+
Then STDERR should contain:
1516+
"""
1517+
Please provide the <old> argument
1518+
"""
1519+
And the return code should be 1
1520+
1521+
@require-mysql
1522+
Scenario: No error when empty string provided via --new flag
1523+
Given a WP install
1524+
1525+
When I try `wp search-replace --old='search' --new=''`
1526+
Then STDERR should not contain:
1527+
"""
1528+
Please provide the <new> argument
1529+
"""
1530+
1531+
@require-mysql
1532+
Scenario: Search/replace string starting with single hyphen works with positional args
1533+
Given a WP install
1534+
And I run `wp post create --post_title="Test Post" --post_content="This is -single-hyphen content" --porcelain`
1535+
Then save STDOUT as {POST_ID}
1536+
1537+
When I run `wp search-replace '-single-hyphen' '-replaced-hyphen'`
1538+
Then STDOUT should contain:
1539+
"""
1540+
wp_posts
1541+
"""
1542+
And the return code should be 0
1543+
1544+
When I run `wp post get {POST_ID} --field=post_content`
1545+
Then STDOUT should contain:
1546+
"""
1547+
-replaced-hyphen
1548+
"""
1549+
And STDOUT should not contain:
1550+
"""
1551+
-single-hyphen
1552+
"""
1553+
1554+
@require-mysql
1555+
Scenario: Allow mixing one flag with one positional argument
1556+
Given a WP install
1557+
And I run `wp post create --post_title="Test Post" --post_content="This is --old-content text" --porcelain`
1558+
Then save STDOUT as {POST_ID}
1559+
1560+
When I run `wp search-replace --old='--old-content' 'new-content'`
1561+
Then STDOUT should contain:
1562+
"""
1563+
wp_posts
1564+
"""
1565+
And the return code should be 0
1566+
1567+
When I run `wp post get {POST_ID} --field=post_content`
1568+
Then STDOUT should contain:
1569+
"""
1570+
new-content
1571+
"""
1572+
And STDOUT should not contain:
1573+
"""
1574+
--old-content
1575+
"""

0 commit comments

Comments
 (0)