From 1f981c86a1dd43f220c69384b1287e8eceb467c2 Mon Sep 17 00:00:00 2001 From: scribu Date: Tue, 16 Jul 2013 23:20:28 +0300 Subject: [PATCH] introduce `wp core multisite-install` (doesn't work yet) --- features/core.feature | 13 ++++++++++++ php/WP_CLI/Runner.php | 4 +++- php/commands/core.php | 58 +++++++++++++++++++++++++++++++++++++-------------- 3 files changed, 58 insertions(+), 17 deletions(-) diff --git a/features/core.feature b/features/core.feature index eda3c15b..cc48e7ef 100644 --- a/features/core.feature +++ b/features/core.feature @@ -125,6 +125,19 @@ Feature: Manage WordPress installation When I try `wp core install-network --title='test network'` Then the return code should be 1 + Scenario: Install multisite from scrath + Given a WP multisite install + And I run `wp db reset --yes` + + When I run `wp core multisite-install --title=Test --admin_email=admin@example.com --admin_password=1` + Then STDOUT should not be empty + + When I run `wp eval 'var_export( is_multisite() );'` + Then STDOUT should be: + """ + true + """ + Scenario: Custom wp-content directory Given a WP install And a custom wp-content directory diff --git a/php/WP_CLI/Runner.php b/php/WP_CLI/Runner.php index abce2046..85a0563d 100644 --- a/php/WP_CLI/Runner.php +++ b/php/WP_CLI/Runner.php @@ -360,7 +360,9 @@ class Runner { } if ( - $this->cmd_starts_with( array( 'core', 'install' ) ) + count( $this->arguments ) >= 2 && + $this->arguments[0] == 'core' && + in_array( $this->arguments[1], array( 'install', 'multisite-install' ) ) ) { define( 'WP_INSTALLING', true ); diff --git a/php/commands/core.php b/php/commands/core.php index 1efda9f0..0f9f2d57 100644 --- a/php/commands/core.php +++ b/php/commands/core.php @@ -131,6 +131,37 @@ class Core_Command extends WP_CLI_Command { * @synopsis --url= --title= [--admin_name=] --admin_email= --admin_password= */ public function install( $args, $assoc_args ) { + $this->_install( $assoc_args ); + WP_CLI::success( 'WordPress installed successfully.' ); + } + + /** + * Transform a single-site install into a multi-site install. + * + * @subcommand multisite-convert + * @alias install-network + * @synopsis --title= [--base=] + */ + public function multisite_convert( $args, $assoc_args ) { + if ( is_multisite() ) + WP_CLI::error( 'This already is a multisite install.' ); + + $this->_multisite_convert( $assoc_args ); + } + + /** + * Install multisite from scratch. + * + * @subcommand multisite-install + * @synopsis --url= [--base=] --title= [--admin_name=] --admin_email= --admin_password= + */ + public function multisite_install( $args, $assoc_args ) { + $this->_install( $assoc_args ); + WP_CLI::log( 'Created single site database tables.' ); + $this->_multisite_convert( $assoc_args ); + } + + private function _install( $assoc_args ) { require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); if ( is_blog_installed() ) { @@ -150,21 +181,10 @@ class Core_Command extends WP_CLI_Command { if ( is_wp_error( $result ) ) { WP_CLI::error( 'Installation failed (' . WP_CLI::error_to_string($result) . ').' ); - } else { - WP_CLI::success( 'WordPress installed successfully.' ); } } - /** - * Transform a single-site install into a multi-site install. - * - * @subcommand install-network - * @synopsis --title= [--base=] [--subdomains] - */ - public function install_network( $args, $assoc_args ) { - if ( is_multisite() ) - WP_CLI::error( 'This already is a multisite install.' ); - + private function _multisite_convert( $assoc_args ) { global $wpdb; require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); @@ -181,17 +201,21 @@ class Core_Command extends WP_CLI_Command { $subdomain_install = isset( $assoc_args['subdomains'] ); install_network(); + WP_CLI::log( 'Created multisite database tables.' ); $result = populate_network( 1, $hostname, get_option( 'admin_email' ), $assoc_args['title'], $base, $subdomain_install ); - if ( is_wp_error( $result ) ) { + if ( true === $result ) { + WP_CLI::log( 'Populated multisite options.' ); + } else if ( is_wp_error( $result ) ) { if ( $result->get_error_codes() === array( 'no_wildcard_dns' ) ) WP_CLI::warning( __( 'Wildcard DNS may not be configured correctly.' ) ); else WP_CLI::error( $result ); } - ob_start(); + if ( !defined( 'MULTISITE' ) ) { + ob_start(); ?> define('MULTISITE', true); define('SUBDOMAIN_INSTALL', ); @@ -202,9 +226,11 @@ define('SITE_ID_CURRENT_SITE', 1); define('BLOG_ID_CURRENT_SITE', 1);