diff --git a/components/Blueprints/SiteResolver/class-newsiteresolver.php b/components/Blueprints/SiteResolver/class-newsiteresolver.php index 4ace812aa..7b2ce2b05 100644 --- a/components/Blueprints/SiteResolver/class-newsiteresolver.php +++ b/components/Blueprints/SiteResolver/class-newsiteresolver.php @@ -7,6 +7,7 @@ use WordPress\Blueprints\Exception\BlueprintExecutionException; use WordPress\Blueprints\Progress\Tracker; use WordPress\Blueprints\Runtime; +use WordPress\Blueprints\Steps\DefineConstantsStep; use WordPress\Blueprints\VersionStrings\VersionConstraint; use WordPress\HttpClient\Client; use WordPress\HttpClient\Request; @@ -71,10 +72,6 @@ public static function resolve( Runtime $runtime, Tracker $progress, ?VersionCon // If SQLite integration zip provided, unzip into appropriate folder. if ( 'sqlite' === $runtime->get_configuration()->get_database_engine() ) { - /* - * @TODO: Ensure DB_NAME gets defined in wp-config.php before installing the SQLite plugin. - */ - $progress['resolve_assets']->setCaption( 'Downloading SQLite integration plugin' ); $resolved = $runtime->resolve( $assets['sqlite-integration'] ); if ( ! $resolved instanceof File ) { @@ -116,6 +113,13 @@ public static function resolve( Runtime $runtime, Tracker $progress, ?VersionCon } } + // Database configuration constants must be available when core installation opens its connection. + $blueprint = $runtime->get_blueprint(); + if ( ! empty( $blueprint['constants'] ) && is_array( $blueprint['constants'] ) ) { + $define_constants_step = new DefineConstantsStep( $blueprint['constants'] ); + $define_constants_step->run( $runtime, $progress['install_wordpress'] ); + } + // Perform installation using WP-CLI. // @TODO (low priority): Remove the WP-CLI dependency to lower the download size for blueprints.phar. $progress['install_wordpress']->set( 0.7, 'Installing WordPress' ); diff --git a/components/Blueprints/Tests/Unit/Steps/DefineConstantsStepTest.php b/components/Blueprints/Tests/Unit/Steps/DefineConstantsStepTest.php index b61d36ce7..b22cc4686 100644 --- a/components/Blueprints/Tests/Unit/Steps/DefineConstantsStepTest.php +++ b/components/Blueprints/Tests/Unit/Steps/DefineConstantsStepTest.php @@ -60,6 +60,9 @@ public function testAddNewConstantsToWpConfigWithEditingComment() { execution_context->put_contents( 'test.sql', $sql ); $step = new RunSqlStep( DataReference::create( './test.sql', [ diff --git a/components/Blueprints/Tests/Unit/Steps/StepTestCase.php b/components/Blueprints/Tests/Unit/Steps/StepTestCase.php index 9875880b2..a9d7ed97b 100644 --- a/components/Blueprints/Tests/Unit/Steps/StepTestCase.php +++ b/components/Blueprints/Tests/Unit/Steps/StepTestCase.php @@ -4,7 +4,6 @@ use PHPUnit\Framework\TestCase; use WordPress\Blueprints\DataReference\AbsoluteLocalPath; -use WordPress\Blueprints\DataReference\DataReference; use WordPress\Blueprints\Runner; use WordPress\Blueprints\RunnerConfiguration; use WordPress\Blueprints\Runtime; @@ -65,7 +64,13 @@ public function setUp(): void { ; } - $blueprint = array( 'version' => 2 ); + $blueprint = array( + 'version' => 2, + 'constants' => array( + 'SQLITE_JOURNAL_MODE' => 'DELETE', + 'WP_SQLITE_UNSAFE_ENABLE_UNSUPPORTED_VERSIONS' => true, + ), + ); if ( PHP_VERSION_ID < 70400 ) { $blueprint['wordpressVersion'] = '6.6.2'; } @@ -78,9 +83,6 @@ public function setUp(): void { $config ->set_blueprint( new AbsoluteLocalPath( wp_join_unix_paths( $this->execution_context_path, 'blueprint.json' ) ) ) ->set_database_engine( 'sqlite' ) - ->set_sqlite_integration_plugin( - DataReference::create( 'https://downloads.wordpress.org/plugin/sqlite-database-integration.2.2.23.zip' ) - ) ->set_target_site_url( 'http://127.0.0.1:2456' ); $runner = new Runner( $config );