Skip to content

Commit a3176e6

Browse files
swissspidyclaude
andcommitted
Merge branch 'main' into callback-104
Conflicts in src/Search_Replace_Command.php and src/WP_CLI/SearchReplacer.php: - Keep main's single-scan column stats, views skipping and table-qualified include/skip columns; pass the --where clauses to php_handle_col and sql_handle_col and to the serialized-data probe. - Do not use the whole-table column stats for a table that has --where clauses, since the stats would count rows outside the selection. - Keep main's ArrayAccess handling and pass the callback options through. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UWTd5pwpi2xQfDA6mUYkkx
2 parents 8d4954a + 17063d6 commit a3176e6

14 files changed

Lines changed: 597 additions & 162 deletions

‎.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/actionlint.yml‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Configuration for actionlint, run by the `actionlint` job in
2+
# `.github/workflows/reusable-code-quality.yml`.
3+
paths:
4+
.github/workflows/**/*.{yml,yaml}:
5+
ignore:
6+
# `copilot-requests` is a real permission scope - it is what lets a
7+
# workflow authenticate the Copilot CLI with the built-in `GITHUB_TOKEN`
8+
# instead of a personal access token - but actionlint's hard-coded scope
9+
# list has not caught up with it yet, so it reports every use as unknown.
10+
# Drop this entry once actionlint ships the scope, and it will go back to
11+
# catching genuine typos in permission names.
12+
# See https://docs.github.com/en/copilot/how-tos/copilot-cli/use-copilot-cli-in-actions
13+
- 'unknown permission scope "copilot-requests"'
14+
# Steps can run in parallel through the `background`, `wait`, `wait-all`,
15+
# `cancel` and `parallel` keywords, but actionlint does not know them yet:
16+
# it rejects `background` as an unexpected key, and a `wait-all` or
17+
# `parallel` step as one that has neither `run` nor `uses`. Drop these
18+
# entries once actionlint supports the keywords. Until then, a step that is
19+
# genuinely missing both `run` and `uses` is no longer reported.
20+
# See https://docs.github.com/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsparallel
21+
- 'unexpected key "background" for step'
22+
- 'step must run script with "run" section or run action with "uses" section'

‎.github/dependabot.yml‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,29 @@ updates:
77
open-pull-requests-limit: 10
88
labels:
99
- scope:distribution
10+
cooldown:
11+
default-days: 7
12+
# Packages from our own org are trusted, so they are updated immediately.
13+
exclude:
14+
- "wp-cli/*"
15+
# Only wp-cli-tests carries a package.json, holding the pinned version of the
16+
# Gherkin linter. This is a no-op in every other repository.
17+
- package-ecosystem: npm
18+
directory: "/"
19+
schedule:
20+
interval: daily
21+
open-pull-requests-limit: 10
22+
labels:
23+
- scope:distribution
24+
cooldown:
25+
default-days: 7
1026
- package-ecosystem: github-actions
1127
directory: "/"
1228
schedule:
1329
interval: daily
1430
open-pull-requests-limit: 10
1531
labels:
1632
- scope:distribution
33+
cooldown:
34+
default-days: 7
1735

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

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,60 @@ on:
99
paths:
1010
- .github/workflows/copilot-setup-steps.yml
1111

12+
permissions:
13+
contents: read
14+
1215
jobs:
1316
copilot-setup-steps:
17+
name: Setup environment
1418
runs-on: ubuntu-latest
1519
permissions:
1620
contents: read
1721

22+
env:
23+
MYSQL_HOST: 127.0.0.1
24+
MYSQL_TCP_PORT: 3306
25+
WP_CLI_TEST_DBROOTUSER: root
26+
WP_CLI_TEST_DBROOTPASS: root
27+
WP_CLI_TEST_DBNAME: wp_cli_test
28+
WP_CLI_TEST_DBUSER: wp_cli_test
29+
WP_CLI_TEST_DBPASS: password1
30+
WP_CLI_TEST_DBHOST: 127.0.0.1:3306
31+
1832
steps:
1933
- name: Checkout code
20-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
34+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
35+
with:
36+
persist-credentials: false
2137

2238
- name: Check existence of composer.json file
2339
id: check_composer_file
2440
run: echo "files_exists=$(test -f composer.json && echo true || echo false)" >> "$GITHUB_OUTPUT"
2541

42+
# Without a database the Behat runner silently falls back to SQLite, so the
43+
# agent's test runs are not the ones CI will do. Mirrors the setup in
44+
# reusable-functional.yml.
45+
- name: Check existence of behat.yml file
46+
id: check_behat_file
47+
run: echo "files_exists=$(test -f behat.yml && echo true || echo false)" >> "$GITHUB_OUTPUT"
48+
49+
# Not run in the background: Copilot code review builds its workflow from
50+
# these steps and failed validation while they used `background` and
51+
# `wait-all`. Also, the action unpacks its binaries with the system `tar`,
52+
# which fails to load libpcre2 while setup-php upgrades it with apt.
53+
- name: Setup MySQL Server
54+
if: steps.check_behat_file.outputs.files_exists == 'true'
55+
uses: shogo82148/actions-setup-mysql@13a38f2af408e58a0c80168fc620a63a15357339 # v1
56+
with:
57+
mysql-version: '8.0' # Standard MySQL version for these tests
58+
auto-start: true
59+
root-password: ${{ env.WP_CLI_TEST_DBROOTPASS }}
60+
user: ${{ env.WP_CLI_TEST_DBUSER }}
61+
password: ${{ env.WP_CLI_TEST_DBPASS }}
62+
2663
- name: Set up PHP environment
2764
if: steps.check_composer_file.outputs.files_exists == 'true'
28-
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # v2
65+
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # v2
2966
with:
3067
php-version: 'latest'
3168
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
@@ -36,9 +73,14 @@ jobs:
3673

3774
- name: Install Composer dependencies & cache dependencies
3875
if: steps.check_composer_file.outputs.files_exists == 'true'
39-
uses: ramsey/composer-install@a35c6ebd3d08125aaf8852dff361e686a1a67947 # v3
76+
uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0
4077
env:
4178
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
42-
with:
43-
# Bust the cache at least once a month - output format: YYYY-MM.
44-
custom-cache-suffix: $(date -u "+%Y-%m")
79+
80+
- name: Remove system MySQL binary
81+
if: steps.check_behat_file.outputs.files_exists == 'true'
82+
run: sudo rm -f /usr/bin/mysql /usr/bin/mysqldump
83+
84+
- name: Prepare test database
85+
if: steps.check_behat_file.outputs.files_exists == 'true'
86+
run: composer prepare-tests

‎.github/workflows/issue-triage.yml‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,17 @@ name: Issue and PR Triage
1616
permissions:
1717
issues: write
1818
pull-requests: write
19-
actions: write
2019
contents: read
21-
models: read
20+
# A caller can only cap a reusable workflow's permissions, so the scope the
21+
# Copilot CLI needs has to be granted here too. `models: read` was for the
22+
# GitHub Models provider, which `actions/ai-inference` v3 removed.
23+
copilot-requests: write
24+
# A caller can only cap a reusable workflow's permissions, never raise them,
25+
# so `actions: write` has to be granted here for the dispatch job downstream
26+
# to work at all. The reusable workflow narrows it to that single job, so the
27+
# `pull_request_target` job does not receive it. Removing it here breaks
28+
# dispatching (see #271/#272); narrow it there instead.
29+
actions: write
2230

2331
jobs:
2432
issue-triage:
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
name: Milestone Merged Pull Requests
3+
4+
'on':
5+
pull_request_target:
6+
types: [closed]
7+
branches:
8+
- main
9+
- master
10+
11+
permissions:
12+
issues: write
13+
pull-requests: write
14+
15+
jobs:
16+
milestone:
17+
uses: wp-cli/.github/.github/workflows/reusable-milestone-merged-prs.yml@main

‎AGENTS.md‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
This package is part of WP-CLI, the official command line interface for WordPress. For a detailed explanation of the project structure and development workflow, please refer to the main @README.md file.
44

5+
If the repository contains an @AGENTS.local.md file, read it as well. It holds instructions specific to this repository and takes precedence over this file where the two disagree.
6+
57
## Best Practices for Code Contributions
68

79
When contributing to this package, please adhere to the following guidelines:
@@ -13,9 +15,27 @@ When contributing to this package, please adhere to the following guidelines:
1315

1416
### Building and running
1517

16-
Before submitting any changes, it is crucial to validate them by running the full suite of static code analysis and tests. To run the full suite of checks, execute the following command: `composer test`.
18+
Run the narrowest check that covers your change:
19+
20+
| You changed | Run |
21+
| --- | --- |
22+
| Any PHP file | `composer phpcs -- <file>` and `composer phpstan` |
23+
| Logic with unit test coverage | `composer phpunit -- --filter <TestName>` |
24+
| One feature file | `composer behat -- features/<name>.feature` |
25+
| One scenario | `composer behat -- features/<name>.feature:<line>` |
26+
27+
After a failure, `composer behat-rerun` re-runs only the scenarios that failed, and `composer behat -- --stop-on-failure` bails out at the first one instead of working through the rest.
28+
29+
`composer test` runs every suite, the whole Behat suite included. In most packages that means installing WordPress from scratch once per scenario, which takes tens of minutes and needs `jq`, a MySQL or MariaDB client with a prepared test database, and network access to WordPress.org. Run it before opening a pull request when you have touched something cross-cutting. Do not run it to check a two-line change.
30+
31+
Set these first, so the tools report problems compactly instead of drawing progress bars and ANSI color into output you are going to read back:
32+
33+
```bash
34+
export NO_COLOR=1
35+
export WP_CLI_TEST_QUIET=1
36+
```
1737

18-
This single command ensures that your changes meet all the quality gates of the project. While you can run the individual steps separately, it is highly recommended to use this single command to ensure a comprehensive validation.
38+
Note that a green `composer test` is not the same as a green CI. `actionlint` and `typos` also run on every pull request and are not part of it.
1939

2040
### Useful Composer Commands
2141

@@ -24,6 +44,7 @@ The project uses Composer to manage dependencies and run scripts. The following
2444
* `composer install`: Install dependencies.
2545
* `composer test`: Run the full test suite, including linting, code style checks, static analysis, and unit/behavior tests.
2646
* `composer lint`: Check for syntax errors.
47+
* `composer lint-gherkin`: Check the Behat feature files for style violations.
2748
* `composer phpcs`: Check for code style violations.
2849
* `composer phpcbf`: Automatically fix code style violations.
2950
* `composer phpstan`: Run static analysis.

‎README.md‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ wp-cli/search-replace-command
33

44
Searches/replaces strings in the database.
55

6-
[![Testing](https://github.com/wp-cli/search-replace-command/actions/workflows/testing.yml/badge.svg)](https://github.com/wp-cli/search-replace-command/actions/workflows/testing.yml)
6+
[![Testing](https://github.com/wp-cli/search-replace-command/actions/workflows/testing.yml/badge.svg)](https://github.com/wp-cli/search-replace-command/actions/workflows/testing.yml) [![Code Coverage](https://codecov.io/gh/wp-cli/search-replace-command/branch/main/graph/badge.svg)](https://codecov.io/gh/wp-cli/search-replace-command/tree/main)
77

88
Quick links: [Using](#using) | [Installing](#installing) | [Contributing](#contributing) | [Support](#support)
99

@@ -23,6 +23,15 @@ 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+
The JSON-encoded form of the search string is replaced as well, so a
27+
search for `https://example.com` also matches `https:\/\/example.com`
28+
in JSON stored in the database. This does not apply with `--regex`,
29+
where the pattern itself has to account for escaped slashes.
30+
31+
Tables without a primary key are skipped. To check whether a table has a
32+
primary key, run `wp db query 'DESCRIBE <table>'` and look for 'PRI' in
33+
the Key column.
34+
2635
**OPTIONS**
2736

2837
[<old>]
@@ -41,7 +50,8 @@ change primary key values.
4150

4251
[--new=<value>]
4352
An alternative way to specify the replacement string. Use this when the
44-
replacement string starts with '--' (e.g., --new='--other-text').
53+
replacement string starts with '--' (e.g., --new='--other-text') or is
54+
empty.
4555

4656
[--dry-run]
4757
Run the entire search/replace operation and show report, but don't save
@@ -75,11 +85,13 @@ change primary key values.
7585

7686
[--skip-columns=<columns>]
7787
Do not perform the replacement on specific columns. Use commas to
78-
specify multiple columns.
88+
specify multiple columns. Table-qualified column names ("table.column")
89+
are supported to apply the skip to a specific table only.
7990

8091
[--include-columns=<columns>]
8192
Perform the replacement on specific columns. Use commas to
82-
specify multiple columns.
93+
specify multiple columns. Table-qualified column names ("table.column")
94+
are supported to apply the inclusion to a specific table only.
8395

8496
[--precise]
8597
Force the use of PHP (instead of SQL) for all columns. By default, the command
@@ -152,6 +164,9 @@ change primary key values.
152164
# Search/replace string containing hyphens
153165
$ wp search-replace --old='--old-string' --new='new-string'
154166

167+
# Remove a string by replacing it with an empty value
168+
$ wp search-replace --old='remove-me' --new=''
169+
155170
# Use precise mode for complex serialized data
156171
$ wp search-replace 'oldurl.com' 'newurl.com' --precise
157172

@@ -193,9 +208,13 @@ Want to contribute a new feature? Please first [open a new issue](https://github
193208

194209
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.
195210

211+
### License
212+
213+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
214+
196215
## Support
197216

198-
GitHub issues aren't for general support questions, but there are other venues you can try: https://wp-cli.org/#support
217+
GitHub issues aren't for general support questions. For support resources and next steps, see the WP-CLI Support page: https://make.wordpress.org/cli/handbook/support/
199218

200219

201220
*This README.md is generated dynamically from the project's codebase using `wp scaffold package-readme` ([doc](https://github.com/wp-cli/scaffold-package-command#wp-scaffold-package-readme)). To suggest changes, please submit a pull request against the corresponding part of the codebase.*

‎codecov.yml‎

Whitespace-only changes.

‎composer.json‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
}
1313
],
1414
"require": {
15-
"wp-cli/wp-cli": "^2.12"
15+
"wp-cli/wp-cli": "^3.0"
1616
},
1717
"require-dev": {
18-
"wp-cli/db-command": "^1.3 || ^2",
19-
"wp-cli/entity-command": "^1.3 || ^2",
20-
"wp-cli/extension-command": "^1.2 || ^2",
18+
"wp-cli/db-command": "^1.3 || ^2 || ^3",
19+
"wp-cli/entity-command": "^1.3 || ^2 || ^3",
20+
"wp-cli/extension-command": "^1.2 || ^2 || ^3",
2121
"wp-cli/wp-cli-tests": "^5"
2222
},
2323
"config": {
@@ -32,7 +32,7 @@
3232
},
3333
"extra": {
3434
"branch-alias": {
35-
"dev-main": "2.x-dev"
35+
"dev-main": "3.x-dev"
3636
},
3737
"bundled": true,
3838
"commands": [
@@ -53,13 +53,15 @@
5353
"behat": "run-behat-tests",
5454
"behat-rerun": "rerun-behat-tests",
5555
"lint": "run-linter-tests",
56+
"lint-gherkin": "run-gherkin-lint-tests",
5657
"phpcs": "run-phpcs-tests",
5758
"phpstan": "run-phpstan-tests",
5859
"phpcbf": "run-phpcbf-cleanup",
5960
"phpunit": "run-php-unit-tests",
6061
"prepare-tests": "install-package-tests",
6162
"test": [
6263
"@lint",
64+
"@lint-gherkin",
6365
"@phpcs",
6466
"@phpstan",
6567
"@phpunit",

0 commit comments

Comments
 (0)