wp-cli / search-replace-command
在数据库中搜索并替换字符串。
Requires
- wp-cli/wp-cli: ^2.5
Requires (Dev)
- wp-cli/db-command: ^1.3 || ^2
- wp-cli/entity-command: ^1.3 || ^2
- wp-cli/extension-command: ^1.2 || ^2
- wp-cli/wp-cli-tests: ^4
- dev-main / 2.x-dev
- v2.1.7
- v2.1.6
- v2.1.5
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.20
- v2.0.19
- v2.0.18
- v2.0.17
- v2.0.16
- v2.0.15
- v2.0.14
- v2.0.13
- v2.0.12
- v2.0.11
- v2.0.10
- v2.0.9
- v2.0.8
- v2.0.7
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.3.1
- v1.3.0
- v1.2.0
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-bump-framework-2-11
- dev-bump-travis-server-to-xenial
This package is auto-updated.
Last update: 2024-09-06 06:25:21 UTC
README
在数据库中搜索并替换字符串。
使用
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>]
搜索选定表中的所有行,并用第二个字符串替换第一个字符串的出现。
默认情况下,该命令使用注册到$wpdb
对象中的表。在多站点中,这将是当前网站的表,除非指定了--network
。
搜索/替换智能处理PHP序列化数据,并且不更改主键值。
选项
<old>
A string to search for within the database.
<new>
Replace instances of the first string with this new string.
[<table>...]
List of database tables to restrict the replacement to. Wildcards are
supported, e.g. `'wp_*options'` or `'wp_post*'`.
[--dry-run]
Run the entire search/replace operation and show report, but don't save
changes to the database.
[--network]
Search/replace through all the tables registered to $wpdb in a
multisite install.
[--all-tables-with-prefix]
Enable replacement on any tables that match the table prefix even if
not registered on $wpdb.
[--all-tables]
Enable replacement on ALL tables in the database, regardless of the
prefix, and even if not registered on $wpdb. Overrides --network
and --all-tables-with-prefix.
[--export[=<file>]]
Write transformed data as SQL file instead of saving replacements to
the database. If <file> is not supplied, will output to STDOUT.
[--export_insert_size=<rows>]
Define number of rows in single INSERT statement when doing SQL export.
You might want to change this depending on your database configuration
(e.g. if you need to do fewer queries). Default: 50
[--skip-tables=<tables>]
Do not perform the replacement on specific tables. Use commas to
specify multiple tables. Wildcards are supported, e.g. `'wp_*options'` or `'wp_post*'`.
[--skip-columns=<columns>]
Do not perform the replacement on specific columns. Use commas to
specify multiple columns.
[--include-columns=<columns>]
Perform the replacement on specific columns. Use commas to
specify multiple columns.
[--precise]
Force the use of PHP (instead of SQL) which is more thorough,
but slower.
[--recurse-objects]
Enable recursing into objects to replace strings. Defaults to true;
pass --no-recurse-objects to disable.
[--verbose]
Prints rows to the console as they're updated.
[--regex]
Runs the search using a regular expression (without delimiters).
Warning: search-replace will take about 15-20x longer when using --regex.
[--regex-flags=<regex-flags>]
Pass PCRE modifiers to regex search-replace (e.g. 'i' for case-insensitivity).
[--regex-delimiter=<regex-delimiter>]
The delimiter to use for the regex. It must be escaped if it appears in the search string. The default value is the result of `chr(1)`.
[--regex-limit=<regex-limit>]
The maximum possible replacements for the regex per row (or per unserialized data bit per row). Defaults to -1 (no limit).
[--format=<format>]
Render output in a particular format.
---
default: table
options:
- table
- count
---
[--report]
Produce report. Defaults to true.
[--report-changed-only]
Report changed fields only. Defaults to false, unless logging, when it defaults to true.
[--log[=<file>]]
Log the items changed. If <file> is not supplied or is "-", will output to STDOUT.
Warning: causes a significant slow down, similar or worse to enabling --precise or --regex.
[--before_context=<num>]
For logging, number of characters to display before the old match and the new replacement. Default 40. Ignored if not logging.
[--after_context=<num>]
For logging, number of characters to display after the old match and the new replacement. Default 40. Ignored if not logging.
示例
# Search and replace but skip one column
$ wp search-replace 'http://example.test' 'http://example.com' --skip-columns=guid
# Run search/replace operation but dont save in database
$ wp search-replace 'foo' 'bar' wp_posts wp_postmeta wp_terms --dry-run
# Run case-insensitive regex search/replace operation (slow)
$ wp search-replace '\[foo id="([0-9]+)"' '[bar id="\1"' --regex --regex-flags='i'
# Turn your production multisite database into a local dev database
$ wp search-replace --url=example.com example.com example.test 'wp_*options' wp_blogs wp_site --network
# Search/replace to a SQL file without transforming the database
$ wp search-replace foo bar --export=database.sql
# Bash script: Search/replace production to development url (multisite compatible)
#!/bin/bash
if $(wp --url=http://example.com core is-installed --network); then
wp search-replace --url=http://example.com 'http://example.com' 'http://example.test' --recurse-objects --network --skip-columns=guid --skip-tables=wp_users
else
wp search-replace 'http://example.com' 'http://example.test' --recurse-objects --skip-columns=guid --skip-tables=wp_users
fi
安装
此包包含在WP-CLI本身中,无需额外安装。
要安装此包的最新版本,而不仅仅是WP-CLI中包含的版本,请运行
wp package install [email protected]:wp-cli/search-replace-command.git
贡献
我们感谢您主动为这个项目做出贡献。
贡献不仅限于代码。我们鼓励您以最适合您能力的方式做出贡献,例如撰写教程、在当地聚会中展示、帮助其他用户解决支持问题或修订我们的文档。
要了解更多信息,请查看WP-CLI贡献指南。此包遵循那些政策和指南。
报告错误
认为您找到了错误?我们希望您能帮助我们修复它。
在创建新问题之前,您应该搜索现有问题,以查看是否有现有解决方案,或者它是否已经在新版本中修复。
一旦您进行了搜索,发现没有针对您的错误的开放或已修复问题,请创建一个新问题。请提供尽可能多的详细信息,并在可能的情况下提供清晰的复现步骤。有关更多指导,请审查我们的错误报告文档。
创建拉取请求
想贡献一个新功能?请首先创建一个新问题来讨论此功能是否适合本项目。
一旦您决定投入时间看到您的拉取请求得到实现,请遵循我们创建拉取请求的指南以确保这是一个愉快的体验。有关在此包本地工作的详细信息,请参阅"设置"。
支持
GitHub问题不是用于一般支持问题,但您可以尝试其他途径: https://wp-cli.org/#support
此README.md文件是通过项目代码库动态生成的,使用wp scaffold package-readme
命令(文档)。如需提出修改建议,请向代码库的相应部分提交pull request。