-
Notifications
You must be signed in to change notification settings - Fork 11
[Blueprints v2] Add support for "enableMultisite" step #136
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
Merged
+541
−75
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1de041a
[Blueprints v2] Add support for "enableMultisite" step
JanJakes b3d2dc2
Add "enableMultisite" step to v1-to-v2 blueprint transpiler
JanJakes 0a3f76f
Inject new constants to a better location within "wp-config.php"
JanJakes c43930c
Fix indentation
JanJakes 141e1bd
Fix tests for PHP 7.2 and 7.3
JanJakes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?php | ||
|
||
namespace WordPress\Blueprints\Steps; | ||
|
||
use Symfony\Component\Process\Exception\ProcessFailedException; | ||
use WordPress\Blueprints\Exception\BlueprintExecutionException; | ||
use WordPress\Blueprints\Progress\Tracker; | ||
use WordPress\Blueprints\Runtime; | ||
|
||
/** | ||
* Represents the 'enableMultisite' step. | ||
*/ | ||
class EnableMultisiteStep implements StepInterface { | ||
public function run( Runtime $runtime, Tracker $tracker ) { | ||
$tracker->setCaption( 'Enabling multisite' ); | ||
|
||
$code = | ||
<<<'PHP' | ||
<?php | ||
/* | ||
* This code is mirroring the "wp core multisite-convert" command behavior. | ||
* See: https://github.com/wp-cli/core-command/blob/f157fb37dae1d13fe7318452f932917161e83e53/src/Core_Command.php#L505 | ||
*/ | ||
|
||
require_once getenv( 'DOCROOT' ) . '/wp-load.php'; | ||
require_once getenv( 'DOCROOT' ) . '/wp-admin/includes/upgrade.php'; | ||
|
||
// need to register the multisite tables manually for some reason | ||
foreach ( $wpdb->tables( 'ms_global' ) as $table => $prefixed_table ) { | ||
$wpdb->$table = $prefixed_table; | ||
} | ||
|
||
install_network(); | ||
|
||
// Get multisite arguments | ||
$site_id = 1; | ||
$base = '/'; | ||
$title = sprintf( '%s Sites', get_option( 'blogname' ) ); | ||
$admin_email = get_option( 'admin_email' ); | ||
$subdomains = false; | ||
|
||
// Get the base domain | ||
$siteurl = get_option( 'siteurl' ); | ||
$domain = (string) preg_replace( '|https?://|', '', $siteurl ); | ||
$slash = strpos( $domain, '/' ); | ||
if ( false !== $slash ) { | ||
$domain = substr( $domain, 0, $slash ); | ||
} | ||
|
||
// Eagerly check for custom ports | ||
if ( strpos( $domain, ':' ) !== false ) { | ||
throw new Exception( | ||
sprintf( | ||
'The current host is "%s", but WordPress multisites do not support custom ports.', | ||
$domain | ||
) | ||
); | ||
} | ||
|
||
$result = populate_network( | ||
$site_id, | ||
$domain, | ||
$admin_email, | ||
$title, | ||
$base, | ||
$subdomains | ||
); | ||
|
||
$site_id = $wpdb->get_var( "SELECT id FROM $wpdb->site" ); | ||
$site_id = ( null === $site_id ) ? 1 : (int) $site_id; | ||
|
||
if ( $result instanceof WP_Error ) { | ||
throw new Exception( | ||
sprintf( | ||
'Error: [%s] %s', | ||
$result->get_error_code(), | ||
$result->get_error_message() | ||
) | ||
); | ||
} | ||
|
||
// delete_site_option() cleans the alloptions cache to prevent dupe option | ||
delete_site_option( 'upload_space_check_disabled' ); | ||
update_site_option( 'upload_space_check_disabled', 1 ); | ||
|
||
$wp_config_constants = array( | ||
'WP_ALLOW_MULTISITE' => true, | ||
'MULTISITE' => true, | ||
'SUBDOMAIN_INSTALL' => $subdomains, | ||
'DOMAIN_CURRENT_SITE' => $domain, | ||
'PATH_CURRENT_SITE' => $base, | ||
'SITE_ID_CURRENT_SITE' => $site_id, | ||
'BLOG_ID_CURRENT_SITE' => 1, | ||
); | ||
|
||
append_output( json_encode( $wp_config_constants ) ); | ||
PHP; | ||
|
||
try { | ||
$result = $runtime->evalPhpCodeInSubProcess( $code ); | ||
} catch ( ProcessFailedException $e ) { | ||
throw new BlueprintExecutionException( $e->getMessage() ); | ||
} | ||
|
||
if ( '' === $result->outputFileContent ) { | ||
throw new BlueprintExecutionException( 'Failed to enable multisite' ); | ||
} | ||
|
||
// Reuse DefineConstantsStep to set the multisite constants. | ||
$wpConfigConstants = json_decode( $result->outputFileContent, true ); | ||
$defineConstantsStep = new DefineConstantsStep( $wpConfigConstants ); | ||
$defineConstantsStep->run( $runtime, $tracker ); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.