From: scribu Date: Tue, 23 Jul 2013 15:59:08 +0000 (+0300) Subject: don't fail if the site is already installed X-Git-Tag: v0.11.0~23^2~1 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=398bc1ff7577cd492cac331a73d4bfd222228d43;p=wvm%2Fwvm.git don't fail if the site is already installed --- diff --git a/features/core.feature b/features/core.feature index 5da719cc..27818a62 100644 --- a/features/core.feature +++ b/features/core.feature @@ -104,6 +104,10 @@ Feature: Manage WordPress installation true """ + # Can complain that it's already installed, but don't exit with an error code + When I try `wp core install --url='localhost:8001' --title='Test' --admin_email=admin@example.com --admin_password=1` + Then the return code should be 0 + Scenario: Convert install to multisite Given a WP install @@ -140,6 +144,10 @@ Feature: Manage WordPress installation foobar.org """ + # Can complain that it's already installed, but don't exit with an error code + When I try `wp core multisite-install --url=foobar.org --title=Test --admin_email=admin@example.com --admin_password=1` + Then the return code should be 0 + Scenario: Install multisite from scratch, with MULTISITE already set in wp-config.php Given a WP multisite install And I run `wp db reset --yes` diff --git a/php/commands/core.php b/php/commands/core.php index 0867d875..3781181a 100644 --- a/php/commands/core.php +++ b/php/commands/core.php @@ -131,8 +131,11 @@ 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.' ); + if ( $this->_install( $assoc_args ) ) { + WP_CLI::success( 'WordPress installed successfully.' ); + } else { + WP_CLI::log( 'WordPress is already installed.' ); + } } /** @@ -151,8 +154,9 @@ class Core_Command extends WP_CLI_Command { $assoc_args['title'] = sprintf( _x('%s Sites', 'Default network name' ), get_option( 'blogname' ) ); } - $this->_multisite_convert( $assoc_args ); - WP_CLI::success( "Network installed. Don't forget to set up rewrite rules." ); + if ( $this->_multisite_convert( $assoc_args ) ) { + WP_CLI::success( "Network installed. Don't forget to set up rewrite rules." ); + } } /** @@ -162,8 +166,11 @@ class Core_Command extends WP_CLI_Command { * @synopsis --url= --title= [--base=] [--subdomains] [--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.' ); + if ( $this->_install( $assoc_args ) ) { + WP_CLI::log( 'Created single site database tables.' ); + } else { + WP_CLI::log( 'Single site database tables already present.' ); + } $assoc_args = self::_set_multisite_defaults( $assoc_args ); $assoc_args['title'] = sprintf( _x('%s Sites', 'Default network name' ), $assoc_args['title'] ); @@ -182,7 +189,9 @@ class Core_Command extends WP_CLI_Command { } } - $this->_multisite_convert( $assoc_args ); + if ( !$this->_multisite_convert( $assoc_args ) ) { + return; + } // Do the steps that were skipped by populate_network(), // which checks is_multisite(). @@ -215,12 +224,12 @@ class Core_Command extends WP_CLI_Command { } private function _install( $assoc_args ) { - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); - if ( is_blog_installed() ) { - WP_CLI::error( 'WordPress is already installed.' ); + return false; } + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); + extract( wp_parse_args( $assoc_args, array( 'title' => '', 'admin_name' => 'admin', @@ -235,6 +244,8 @@ class Core_Command extends WP_CLI_Command { if ( is_wp_error( $result ) ) { WP_CLI::error( 'Installation failed (' . WP_CLI::error_to_string($result) . ').' ); } + + return true; } private function _multisite_convert( $assoc_args ) { @@ -261,10 +272,19 @@ class Core_Command extends WP_CLI_Command { if ( true === $result ) { WP_CLI::log( 'Set up multisite database tables.' ); } else if ( is_wp_error( $result ) ) { - if ( $result->get_error_codes() === array( 'no_wildcard_dns' ) ) + switch ( $result->get_error_code() ) { + + case 'siteid_exists': + WP_CLI::log( $result->get_error_message() ); + return false; + + case 'no_wildcard_dns': WP_CLI::warning( __( 'Wildcard DNS may not be configured correctly.' ) ); - else + break; + + default: WP_CLI::error( $result ); + } } if ( !is_multisite() ) { @@ -286,6 +306,8 @@ define('BLOG_ID_CURRENT_SITE', 1); } wp_mkdir_p( WP_CONTENT_DIR . '/blogs.dir' ); + + return true; } // copied from populate_network()