Repository navigation
Cache multisite installations like single site installations #382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -498,6 +498,52 @@ Feature: Test that WP-CLI Behat steps work as expected | |
| When I run `wp core is-installed --network` | ||
| Then the return code should be 0 | ||
|
|
||
| @require-wp | ||
| Scenario: Create a site on a cached multisite subdomain installation | ||
| Given a WP multisite subdomain installation | ||
| When I run `wp eval 'echo is_subdomain_install() ? "subdomain" : "subdirectory";'` | ||
| Then STDOUT should be: | ||
| """ | ||
| subdomain | ||
| """ | ||
|
|
||
| When I run `wp eval 'wpmu_create_blog( "first.example.com", "/", "First", 1 );'` | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use Windows-compatible command arguments. On Windows,
|
||
| And I run `wp eval 'echo get_sites( "count=1" );'` | ||
| Then STDOUT should be: | ||
| """ | ||
| 2 | ||
| """ | ||
|
|
||
| @require-wp | ||
| Scenario: Restore a cached multisite subdirectory installation | ||
| Given a WP multisite subdirectory installation | ||
| When I run `wp eval 'echo is_subdomain_install() ? "subdomain" : "subdirectory";'` | ||
| Then STDOUT should be: | ||
| """ | ||
| subdirectory | ||
| """ | ||
|
|
||
| When I run `wp eval 'echo get_sites( "count=1" );'` | ||
| Then STDOUT should be: | ||
| """ | ||
| 1 | ||
| """ | ||
|
|
||
| @require-wp | ||
| Scenario: Restore a cached multisite subdomain installation without earlier changes | ||
| Given a WP multisite subdomain installation | ||
| When I run `wp eval 'echo is_subdomain_install() ? "subdomain" : "subdirectory";'` | ||
| Then STDOUT should be: | ||
| """ | ||
| subdomain | ||
| """ | ||
|
|
||
| When I run `wp eval 'echo get_sites( "count=1" );'` | ||
| Then STDOUT should be: | ||
| """ | ||
| 1 | ||
| """ | ||
|
|
||
| @require-wp | ||
| Scenario: Test misconfigured WP_CONTENT_DIR | ||
| Given a WP installation | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1913,8 +1913,9 @@ public function create_config( $subdir = '', $extra_php = false ): void { | |
| /** | ||
| * @param string $subdir | ||
| * @param string $version | ||
| * @param string $network Multisite type to install on top, either 'subdirectory' or 'subdomain'. Empty for a single site. | ||
| */ | ||
| public function install_wp( $subdir = '', $version = '' ): void { | ||
| public function install_wp( $subdir = '', $version = '', $network = '' ): void { | ||
| $wp_version = $version ?: getenv( 'WP_VERSION' ); | ||
| $wp_version_suffix = $wp_version ? "-$wp_version" : ''; | ||
| self::$install_cache_dir = sys_get_temp_dir() . '/wp-cli-test-core-install-cache' . $wp_version_suffix; | ||
|
|
@@ -1951,7 +1952,7 @@ public function install_wp( $subdir = '', $version = '' ): void { | |
|
|
||
| $run_dir = '' !== $subdir ? ( $this->variables['RUN_DIR'] . "/$subdir" ) : $this->variables['RUN_DIR']; | ||
|
|
||
| $install_cache_path = self::$install_cache_dir . '/install_' . md5( implode( ':', $install_args ) . ':subdir=' . $subdir . ':object_cache=' . getenv( 'WP_CLI_TEST_OBJECT_CACHE' ) ); | ||
| $install_cache_path = self::$install_cache_dir . '/install_' . md5( implode( ':', $install_args ) . ':subdir=' . $subdir . ':object_cache=' . getenv( 'WP_CLI_TEST_OBJECT_CACHE' ) . ( $network ? ':network=' . $network : '' ) ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Build the network cache from a clean installation. If a scenario first creates a single-site installation, changes an option, and then requests the first multisite installation of that type, this new key misses. Restore a clean single-site snapshot before building a network cache entry.
|
||
|
|
||
| // The cache includes the SQLite database, stored under "wp-content/database". | ||
| if ( is_dir( $install_cache_path ) ) { | ||
|
|
@@ -1964,6 +1965,14 @@ public function install_wp( $subdir = '', $version = '' ): void { | |
| } else { | ||
| $this->proc( 'wp core install', $install_args, $subdir )->run_check(); | ||
|
|
||
| if ( $network ) { | ||
| $network_args = [ | ||
| 'title' => 'WP CLI Network', | ||
| 'subdomains' => 'subdomain' === $network ? 1 : 0, | ||
| ]; | ||
| $this->proc( 'wp core install-network', $network_args, $subdir )->run_check(); | ||
| } | ||
|
|
||
| if ( ! is_dir( $install_cache_path ) ) { | ||
| mkdir( $install_cache_path ); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gate these scenarios by WordPress version.
wp_insert_site()requires WordPress 5.1, andget_sites()requires 4.6. The current tags allow these scenarios to run on older versions, where they fail with undefined-function errors. (developer.wordpress.org)Add
@require-wp-5.1to the first scenario and@require-wp-4.6to the other two, or use compatible APIs.Also applies to: 517-517, 532-532