entity-command
entity-command copied to clipboard
Passing an invalid multisite subdirectory defaults to subsite 1
Bug Report
When using commands such as wp option update siteurl on a multisite, passing a --url parameter of a non-existent domain or subdomain will return an error. But passing a --url parameter of a non-existent subdirectory will not return an error and will instead apply the command to subsite 1. This means that a typo in a command targeting subsite 2 will inadvertently change subsite 1, which can cause a site to break.
Describe how other contributors can replicate this bug
Here is an example log where the subdirectory is info but I omit the o.
$ wp site list
+---------+---------------------+---------------------+------------------------+
| blog_id | url | last_updated | registered |
+---------+---------------------+---------------------+------------------------+
| 1 | https://xyzzy-com-d | 2019-08-26 16:47:12 | 2019-06-25 15:44:38 |
| | evelop.wp-cli.net/ | | |
| 2 | https://xyzzy-com-d | 2019-07-15 17:45:07 | 2019-06-25 22:45:29 |
| | evelop.wp-cli.net/i | | |
| | nfo/ | | |
+---------+---------------------+---------------------+------------------------+
$ wp option get siteurl --url=example.com
Error: Site 'example.com' not found. Verify `--url=` matches an existing site.
$ wp option update siteurl https://example.com --url=example.com
Error: Site 'example.com' not found. Verify `--url=` matches an existing site.
$ wp option get siteurl --url=xyzzy-com-develop.wp-cli.net/info/
https://xyzzy-com-develop.wp-cli.net/info
$ wp option get siteurl --url=xyzzy-com-develop.wp-cli.net/inf
https://xyzzy-com-develop.wp-cli.net
$ wp option update siteurl example.com --url=xyzzy-com-develop.wp-cli.net/inf
Success: Value passed for 'siteurl' option is unchanged.
$ wp option update siteurl https://example.com --url=xyzzy-com-develop.wp-cli.net/inf
Success: Updated 'siteurl' option.
$ wp site list
+---------+---------------------+---------------------+------------------------+
| blog_id | url | last_updated | registered |
+---------+---------------------+---------------------+------------------------+
| 1 | https://example.com | 2019-08-26 16:47:12 | 2019-06-25 15:44:38 |
| | / | | |
| 2 | https://xyzzy-com-d | 2019-07-15 17:45:07 | 2019-06-25 22:45:29 |
| | evelop.wp-cli.net/i | | |
| | nfo/ | | |
+---------+---------------------+---------------------+------------------------+
$ wp option update siteurl https://xyzzy-com-develop.wp-cli.net/
Success: Updated 'siteurl' option.
$ wp site list
+---------+---------------------+---------------------+------------------------+
| blog_id | url | last_updated | registered |
+---------+---------------------+---------------------+------------------------+
| 1 | https://xyzzy-com-d | 2019-08-26 16:47:12 | 2019-06-25 15:44:38 |
| | evelop.wp-cli.net/ | | |
| 2 | https://xyzzy-com-d | 2019-07-15 17:45:07 | 2019-06-25 22:45:29 |
| | evelop.wp-cli.net/i | | |
| | nfo/ | | |
+---------+---------------------+---------------------+------------------------+
Desired behavior
The command
wp option update siteurl https://example.com --url=xyzzy-com-develop.wp-cli.net/inf
would return
Error: Site 'xyzzy-com-develop.wp-cli.net/inf' not found. Verify `--url=` matches an existing site.
Environment
I have replicated this experience in two environments:
MAMP
OS: Darwin 17.7.0 Darwin Kernel Version 17.7.0: Sun Jun 2 20:31:42 PDT 2019; root:xnu-4570.71.46~1/RELEASE_X86_64 x86_64
Shell: /bin/bash
PHP binary: /Applications/MAMP/bin/php/php7.3.1/bin/php
PHP version: 7.3.1
php.ini used: /Applications/MAMP/bin/php/php7.3.1/conf/php.ini
WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir: phar://wp-cli.phar/vendor
WP_CLI phar path: /Users/kgagne/Sites/wp
WP-CLI packages dir:
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 2.3.0
And WPVIP:
OS: Linux 4.9.0-9-amd64 #1 SMP Debian 4.9.168-1+deb9u2 (2019-05-13) x86_64
Shell: /bin/bash
PHP binary: /root/roles/nginx-php/usr/local/php7.3/bin.stretch/php
PHP version: 7.3.9
php.ini used: /usr/local/php7.3/conf/php.ini
WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir: phar://wp-cli.phar/vendor
WP_CLI phar path: /home/vipdev
WP-CLI packages dir:
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 2.2.0