Skip to content

Commit f514c0b

Browse files
committed
For multisite installs, reconstruct WP schema for all sites
1 parent 2c3c1b7 commit f514c0b

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

tests/WP_SQLite_Information_Schema_Reconstructor_Tests.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public static function setUpBeforeClass(): void {
3939
if ( ! defined( 'ABSPATH' ) ) {
4040
define( 'ABSPATH', __DIR__ );
4141
}
42-
if ( ! function_exists( 'wp_installing' ) ) {
43-
function wp_installing() {
42+
if ( ! function_exists( 'is_multisite' ) ) {
43+
function is_multisite() {
4444
return false;
4545
}
4646
}

wp-includes/sqlite-ast/class-wp-sqlite-information-schema-reconstructor.php

+16
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,23 @@ private function get_wp_create_table_statements(): array {
145145
throw new Exception( 'The "wp_get_db_schema()" function was not defined.' );
146146
}
147147

148+
// Get schema for global tables and the main site.
148149
$schema = wp_get_db_schema();
150+
151+
// For multisite installs, add schema definitions for all sites.
152+
if ( is_multisite() ) {
153+
$site_ids = get_sites(
154+
array(
155+
'fields' => 'ids',
156+
'number' => PHP_INT_MAX,
157+
)
158+
);
159+
foreach ( $site_ids as $site_id ) {
160+
$schema .= wp_get_db_schema( 'blog', $site_id );
161+
}
162+
}
163+
164+
// Parse the schema.
149165
$parser = $this->driver->create_parser( $schema );
150166
while ( $parser->next_query() ) {
151167
$ast = $parser->get_query_ast();

0 commit comments

Comments
 (0)