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
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`
* @synopsis --url=<url> --title=<site-title> [--admin_name=<username>] --admin_email=<email> --admin_password=<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.' );
+ }
}
/**
$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." );
+ }
}
/**
* @synopsis --url=<url> --title=<site-title> [--base=<url-path>] [--subdomains] [--admin_name=<username>] --admin_email=<email> --admin_password=<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'] );
}
}
- $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().
}
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',
if ( is_wp_error( $result ) ) {
WP_CLI::error( 'Installation failed (' . WP_CLI::error_to_string($result) . ').' );
}
+
+ return true;
}
private function _multisite_convert( $assoc_args ) {
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() ) {
}
wp_mkdir_p( WP_CONTENT_DIR . '/blogs.dir' );
+
+ return true;
}
// copied from populate_network()