WordPress内のテーブルをまたいで置換をする

## 

WordPressはmeta情報なんかをシリアライズして持ってるので、SQLで直接アップデートがしにくいのだけれど、この世は地獄なので、どうしても置換したいことが出てくる。でも、毎日発生する作業ではなくて、すぐ忘れるため、ここに `wp search-replace` を記す。

参考はこの辺

https://developer.wordpress.org/cli/commands/search-replace/

```bash
# 必ず --dry-run を試す
# --regex つけると正規表現が使える
# これはdockerコンテナ内なのだけれど、rootで実行する場合、 --allow-root つけないと怒ってくる
root@945cd8d078a8:/var/www/html# wp search-replace 'http:\/\/example\.com' 'http://target.example.com' --regex --dry-run --allow-root
+------------------+-----------------------+--------------+------+
| Table            | Column                | Replacements | Type |
+------------------+-----------------------+--------------+------+
| wp_commentmeta   | meta_key              | 0            | PHP  |
| wp_commentmeta   | meta_value            | 0            | PHP  |
| wp_comments      | comment_author        | 0            | PHP  |
| wp_comments      | comment_author_email  | 0            | PHP  |
| wp_comments      | comment_author_url    | 0            | PHP  |
| wp_comments      | comment_author_IP     | 0            | PHP  |
| wp_comments      | comment_content       | 0            | PHP  |
| wp_comments      | comment_approved      | 0            | PHP  |
| wp_comments      | comment_agent         | 0            | PHP  |
| wp_comments      | comment_type          | 0            | PHP  |
| wp_links         | link_url              | 0            | PHP  |
| wp_links         | link_name             | 0            | PHP  |
| wp_links         | link_image            | 0            | PHP  |
| wp_links         | link_target           | 0            | PHP  |
| wp_links         | link_description      | 0            | PHP  |
| wp_links         | link_visible          | 0            | PHP  |
| wp_links         | link_rel              | 0            | PHP  |
| wp_links         | link_notes            | 0            | PHP  |
| wp_links         | link_rss              | 0            | PHP  |
| wp_options       | option_name           | 0            | PHP  |
| wp_options       | option_value          | 2            | PHP  |
| wp_options       | autoload              | 0            | PHP  |
| wp_postmeta      | meta_key              | 0            | PHP  |
| wp_postmeta      | meta_value            | 0            | PHP  |
| wp_posts         | post_content          | 19           | PHP  |
| wp_posts         | post_title            | 0            | PHP  |
| wp_posts         | post_excerpt          | 0            | PHP  |
| wp_posts         | post_status           | 0            | PHP  |
| wp_posts         | comment_status        | 0            | PHP  |
| wp_posts         | ping_status           | 0            | PHP  |
| wp_posts         | post_password         | 0            | PHP  |
| wp_posts         | post_name             | 0            | PHP  |
| wp_posts         | to_ping               | 0            | PHP  |
| wp_posts         | pinged                | 0            | PHP  |
| wp_posts         | post_content_filtered | 0            | PHP  |
| wp_posts         | guid                  | 69           | PHP  |
| wp_posts         | post_type             | 0            | PHP  |
| wp_posts         | post_mime_type        | 0            | PHP  |
| wp_term_taxonomy | taxonomy              | 0            | PHP  |
| wp_term_taxonomy | description           | 0            | PHP  |
| wp_termmeta      | meta_key              | 0            | PHP  |
| wp_termmeta      | meta_value            | 0            | PHP  |
| wp_terms         | name                  | 0            | PHP  |
| wp_terms         | slug                  | 0            | PHP  |
| wp_usermeta      | meta_key              | 0            | PHP  |
| wp_usermeta      | meta_value            | 0            | PHP  |
| wp_users         | user_login            | 0            | PHP  |
| wp_users         | user_nicename         | 0            | PHP  |
| wp_users         | user_email            | 0            | PHP  |
| wp_users         | user_url              | 0            | PHP  |
| wp_users         | user_activation_key   | 0            | PHP  |
| wp_users         | display_name          | 0            | PHP  |
+------------------+-----------------------+--------------+------+
```

```bash
# 置換実行
root@945cd8d078a8:/var/www/html# wp search-replace 'http:\/\/example\.com' 'http://target.example.com' --regex --allow-root
+------------------+-----------------------+--------------+------+
| Table            | Column                | Replacements | Type |
+------------------+-----------------------+--------------+------+
| wp_commentmeta   | meta_key              | 0            | PHP  |
| wp_commentmeta   | meta_value            | 0            | PHP  |
| wp_comments      | comment_author        | 0            | PHP  |
| wp_comments      | comment_author_email  | 0            | PHP  |
| wp_comments      | comment_author_url    | 0            | PHP  |
| wp_comments      | comment_author_IP     | 0            | PHP  |
| wp_comments      | comment_content       | 0            | PHP  |
| wp_comments      | comment_approved      | 0            | PHP  |
| wp_comments      | comment_agent         | 0            | PHP  |
| wp_comments      | comment_type          | 0            | PHP  |
| wp_links         | link_url              | 0            | PHP  |
| wp_links         | link_name             | 0            | PHP  |
| wp_links         | link_image            | 0            | PHP  |
| wp_links         | link_target           | 0            | PHP  |
| wp_links         | link_description      | 0            | PHP  |
| wp_links         | link_visible          | 0            | PHP  |
| wp_links         | link_rel              | 0            | PHP  |
| wp_links         | link_notes            | 0            | PHP  |
| wp_links         | link_rss              | 0            | PHP  |
| wp_options       | option_name           | 0            | PHP  |
| wp_options       | option_value          | 2            | PHP  |
| wp_options       | autoload              | 0            | PHP  |
| wp_postmeta      | meta_key              | 0            | PHP  |
| wp_postmeta      | meta_value            | 0            | PHP  |
| wp_posts         | post_content          | 19           | PHP  |
| wp_posts         | post_title            | 0            | PHP  |
| wp_posts         | post_excerpt          | 0            | PHP  |
| wp_posts         | post_status           | 0            | PHP  |
| wp_posts         | comment_status        | 0            | PHP  |
| wp_posts         | ping_status           | 0            | PHP  |
| wp_posts         | post_password         | 0            | PHP  |
| wp_posts         | post_name             | 0            | PHP  |
| wp_posts         | to_ping               | 0            | PHP  |
| wp_posts         | pinged                | 0            | PHP  |
| wp_posts         | post_content_filtered | 0            | PHP  |
| wp_posts         | guid                  | 69           | PHP  |
| wp_posts         | post_type             | 0            | PHP  |
| wp_posts         | post_mime_type        | 0            | PHP  |
| wp_term_taxonomy | taxonomy              | 0            | PHP  |
| wp_term_taxonomy | description           | 0            | PHP  |
| wp_termmeta      | meta_key              | 0            | PHP  |
| wp_termmeta      | meta_value            | 0            | PHP  |
| wp_terms         | name                  | 0            | PHP  |
| wp_terms         | slug                  | 0            | PHP  |
| wp_usermeta      | meta_key              | 0            | PHP  |
| wp_usermeta      | meta_value            | 0            | PHP  |
| wp_users         | user_login            | 0            | PHP  |
| wp_users         | user_nicename         | 0            | PHP  |
| wp_users         | user_email            | 0            | PHP  |
| wp_users         | user_url              | 0            | PHP  |
| wp_users         | user_activation_key   | 0            | PHP  |
| wp_users         | display_name          | 0            | PHP  |
+------------------+-----------------------+--------------+------+
Success: Made 90 replacements.
```