Skip to content

Commit 89175c4

Browse files
committed
fix(Builder) too early is_blog_installed run
This changes the logic put in place in [this commit](fba6dc4) to keep the spirit (avoid a db query on each run of the `Builder::up()` method, but avoid the call to `is_blog_installed` that, when fired too early in multisite installations, would kill the database. What is the issue? The `Builder::up` is called, by means of the `Builder::update_blog_tables` on `switch_blog`. The `switch_blog` function is called during the creation of blogs as well, in the `wp_initialize_site` function. The blog **is being installed**, it's not installed yet. Running `is_blog_installed()` in this phase will kill the site as it will find a broken db: the `users` table is there (it' common to all blogs), but the `options` table is not. This PR handles this scenario, delaying the creation of the tables to the `activate_blog` or `switch_blog` calls following the creation of the site or future requests.
1 parent 09dac4b commit 89175c4

File tree

4 files changed

+160
-66
lines changed

4 files changed

+160
-66
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. This projec
44

55
## [unreleased] Unreleased
66

7+
## [1.1.10] 2025-07-18
8+
9+
* Fix - Avoid dead db in multisite installations with too early checks.
10+
711
## [1.1.9] 2025-02-26
812

913
* Tweak - Add @throws tags from the [stellarwp/db](https://github.com/stellarwp/db) library and better generics.

src/Schema/Builder.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,25 @@ public function register_custom_tables_names() {
263263
* @return array<mixed> A list of each creation or update result.
264264
*/
265265
public function up( $force = false ) {
266-
if ( ! is_blog_installed() || wp_installing() ) {
266+
if ( doing_action( 'switch_blog' ) ) {
267+
/*
268+
* The `switch_blog` action can be called by the `wp_initialize_site` function, before the blog exists.
269+
* Running `is_blog_installed()` in this case will kill the site with a dead db message since the
270+
* `users` table will be found (it's common for all blogs), but the `options` table will not be found for
271+
* the blog.
272+
* If the blog does not exist, the value will not be cached yet and the value will be `false`.
273+
* Else we can just use the value; this will be the case for a normal `switch_blog` action that does not
274+
* fire while creating the site.
275+
*
276+
* When is the next chance to create the tables? Likely in the `activate_blog` action that will be fired
277+
* in the same request following the site blog creation, or in the next `switch_blog` action.
278+
*/
279+
$is_blog_installed = wp_cache_get( 'is_blog_installed' );
280+
} else {
281+
$is_blog_installed = is_blog_installed();
282+
}
283+
284+
if ( ! $is_blog_installed || wp_installing() ) {
267285
return [];
268286
}
269287

tests/_data/wpunit/dump.sql

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ DROP TABLE IF EXISTS `wp_commentmeta`;
2525
CREATE TABLE `wp_commentmeta` (
2626
`meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
2727
`comment_id` bigint(20) unsigned NOT NULL DEFAULT 0,
28-
`meta_key` varchar(255) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
29-
`meta_value` longtext COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
28+
`meta_key` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
29+
`meta_value` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL,
3030
PRIMARY KEY (`meta_id`),
3131
KEY `comment_id` (`comment_id`),
3232
KEY `meta_key` (`meta_key`(191))
33-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
33+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3434
/*!40101 SET character_set_client = @saved_cs_client */;
3535

3636
--
@@ -52,17 +52,17 @@ DROP TABLE IF EXISTS `wp_comments`;
5252
CREATE TABLE `wp_comments` (
5353
`comment_ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
5454
`comment_post_ID` bigint(20) unsigned NOT NULL DEFAULT 0,
55-
`comment_author` tinytext COLLATE utf8mb4_unicode_520_ci NOT NULL,
56-
`comment_author_email` varchar(100) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
57-
`comment_author_url` varchar(200) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
58-
`comment_author_IP` varchar(100) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
55+
`comment_author` tinytext COLLATE utf8mb4_unicode_ci NOT NULL,
56+
`comment_author_email` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
57+
`comment_author_url` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
58+
`comment_author_IP` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
5959
`comment_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
6060
`comment_date_gmt` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
61-
`comment_content` text COLLATE utf8mb4_unicode_520_ci NOT NULL,
61+
`comment_content` text COLLATE utf8mb4_unicode_ci NOT NULL,
6262
`comment_karma` int(11) NOT NULL DEFAULT 0,
63-
`comment_approved` varchar(20) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '1',
64-
`comment_agent` varchar(255) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
65-
`comment_type` varchar(20) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT 'comment',
63+
`comment_approved` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '1',
64+
`comment_agent` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
65+
`comment_type` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'comment',
6666
`comment_parent` bigint(20) unsigned NOT NULL DEFAULT 0,
6767
`user_id` bigint(20) unsigned NOT NULL DEFAULT 0,
6868
PRIMARY KEY (`comment_ID`),
@@ -71,7 +71,7 @@ CREATE TABLE `wp_comments` (
7171
KEY `comment_date_gmt` (`comment_date_gmt`),
7272
KEY `comment_parent` (`comment_parent`),
7373
KEY `comment_author_email` (`comment_author_email`(10))
74-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
74+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
7575
/*!40101 SET character_set_client = @saved_cs_client */;
7676

7777
--
@@ -92,21 +92,21 @@ DROP TABLE IF EXISTS `wp_links`;
9292
/*!50503 SET character_set_client = utf8mb4 */;
9393
CREATE TABLE `wp_links` (
9494
`link_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
95-
`link_url` varchar(255) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
96-
`link_name` varchar(255) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
97-
`link_image` varchar(255) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
98-
`link_target` varchar(25) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
99-
`link_description` varchar(255) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
100-
`link_visible` varchar(20) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT 'Y',
95+
`link_url` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
96+
`link_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
97+
`link_image` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
98+
`link_target` varchar(25) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
99+
`link_description` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
100+
`link_visible` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'Y',
101101
`link_owner` bigint(20) unsigned NOT NULL DEFAULT 1,
102102
`link_rating` int(11) NOT NULL DEFAULT 0,
103103
`link_updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
104-
`link_rel` varchar(255) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
105-
`link_notes` mediumtext COLLATE utf8mb4_unicode_520_ci NOT NULL,
106-
`link_rss` varchar(255) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
104+
`link_rel` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
105+
`link_notes` mediumtext COLLATE utf8mb4_unicode_ci NOT NULL,
106+
`link_rss` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
107107
PRIMARY KEY (`link_id`),
108108
KEY `link_visible` (`link_visible`)
109-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
109+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
110110
/*!40101 SET character_set_client = @saved_cs_client */;
111111

112112
--
@@ -127,13 +127,13 @@ DROP TABLE IF EXISTS `wp_options`;
127127
/*!50503 SET character_set_client = utf8mb4 */;
128128
CREATE TABLE `wp_options` (
129129
`option_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
130-
`option_name` varchar(191) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
131-
`option_value` longtext COLLATE utf8mb4_unicode_520_ci NOT NULL,
132-
`autoload` varchar(20) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT 'yes',
130+
`option_name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
131+
`option_value` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
132+
`autoload` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'yes',
133133
PRIMARY KEY (`option_id`),
134134
UNIQUE KEY `option_name` (`option_name`),
135135
KEY `autoload` (`autoload`)
136-
) ENGINE=InnoDB AUTO_INCREMENT=139 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
136+
) ENGINE=InnoDB AUTO_INCREMENT=139 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
137137
/*!40101 SET character_set_client = @saved_cs_client */;
138138

139139
--
@@ -156,12 +156,12 @@ DROP TABLE IF EXISTS `wp_postmeta`;
156156
CREATE TABLE `wp_postmeta` (
157157
`meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
158158
`post_id` bigint(20) unsigned NOT NULL DEFAULT 0,
159-
`meta_key` varchar(255) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
160-
`meta_value` longtext COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
159+
`meta_key` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
160+
`meta_value` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL,
161161
PRIMARY KEY (`meta_id`),
162162
KEY `post_id` (`post_id`),
163163
KEY `meta_key` (`meta_key`(191))
164-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
164+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
165165
/*!40101 SET character_set_client = @saved_cs_client */;
166166

167167
--
@@ -185,31 +185,31 @@ CREATE TABLE `wp_posts` (
185185
`post_author` bigint(20) unsigned NOT NULL DEFAULT 0,
186186
`post_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
187187
`post_date_gmt` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
188-
`post_content` longtext COLLATE utf8mb4_unicode_520_ci NOT NULL,
189-
`post_title` text COLLATE utf8mb4_unicode_520_ci NOT NULL,
190-
`post_excerpt` text COLLATE utf8mb4_unicode_520_ci NOT NULL,
191-
`post_status` varchar(20) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT 'publish',
192-
`comment_status` varchar(20) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT 'open',
193-
`ping_status` varchar(20) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT 'open',
194-
`post_password` varchar(255) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
195-
`post_name` varchar(200) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
196-
`to_ping` text COLLATE utf8mb4_unicode_520_ci NOT NULL,
197-
`pinged` text COLLATE utf8mb4_unicode_520_ci NOT NULL,
188+
`post_content` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
189+
`post_title` text COLLATE utf8mb4_unicode_ci NOT NULL,
190+
`post_excerpt` text COLLATE utf8mb4_unicode_ci NOT NULL,
191+
`post_status` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'publish',
192+
`comment_status` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'open',
193+
`ping_status` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'open',
194+
`post_password` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
195+
`post_name` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
196+
`to_ping` text COLLATE utf8mb4_unicode_ci NOT NULL,
197+
`pinged` text COLLATE utf8mb4_unicode_ci NOT NULL,
198198
`post_modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
199199
`post_modified_gmt` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
200-
`post_content_filtered` longtext COLLATE utf8mb4_unicode_520_ci NOT NULL,
200+
`post_content_filtered` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
201201
`post_parent` bigint(20) unsigned NOT NULL DEFAULT 0,
202-
`guid` varchar(255) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
202+
`guid` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
203203
`menu_order` int(11) NOT NULL DEFAULT 0,
204-
`post_type` varchar(20) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT 'post',
205-
`post_mime_type` varchar(100) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
204+
`post_type` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'post',
205+
`post_mime_type` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
206206
`comment_count` bigint(20) NOT NULL DEFAULT 0,
207207
PRIMARY KEY (`ID`),
208208
KEY `post_name` (`post_name`(191)),
209209
KEY `type_status_date` (`post_type`,`post_status`,`post_date`,`ID`),
210210
KEY `post_parent` (`post_parent`),
211211
KEY `post_author` (`post_author`)
212-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
212+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
213213
/*!40101 SET character_set_client = @saved_cs_client */;
214214

215215
--
@@ -235,7 +235,7 @@ CREATE TABLE `wp_term_relationships` (
235235
`term_order` int(11) NOT NULL DEFAULT 0,
236236
PRIMARY KEY (`object_id`,`term_taxonomy_id`),
237237
KEY `term_taxonomy_id` (`term_taxonomy_id`)
238-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
238+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
239239
/*!40101 SET character_set_client = @saved_cs_client */;
240240

241241
--
@@ -257,14 +257,14 @@ DROP TABLE IF EXISTS `wp_term_taxonomy`;
257257
CREATE TABLE `wp_term_taxonomy` (
258258
`term_taxonomy_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
259259
`term_id` bigint(20) unsigned NOT NULL DEFAULT 0,
260-
`taxonomy` varchar(32) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
261-
`description` longtext COLLATE utf8mb4_unicode_520_ci NOT NULL,
260+
`taxonomy` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
261+
`description` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
262262
`parent` bigint(20) unsigned NOT NULL DEFAULT 0,
263263
`count` bigint(20) NOT NULL DEFAULT 0,
264264
PRIMARY KEY (`term_taxonomy_id`),
265265
UNIQUE KEY `term_id_taxonomy` (`term_id`,`taxonomy`),
266266
KEY `taxonomy` (`taxonomy`)
267-
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
267+
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
268268
/*!40101 SET character_set_client = @saved_cs_client */;
269269

270270
--
@@ -287,12 +287,12 @@ DROP TABLE IF EXISTS `wp_termmeta`;
287287
CREATE TABLE `wp_termmeta` (
288288
`meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
289289
`term_id` bigint(20) unsigned NOT NULL DEFAULT 0,
290-
`meta_key` varchar(255) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
291-
`meta_value` longtext COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
290+
`meta_key` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
291+
`meta_value` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL,
292292
PRIMARY KEY (`meta_id`),
293293
KEY `term_id` (`term_id`),
294294
KEY `meta_key` (`meta_key`(191))
295-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
295+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
296296
/*!40101 SET character_set_client = @saved_cs_client */;
297297

298298
--
@@ -313,13 +313,13 @@ DROP TABLE IF EXISTS `wp_terms`;
313313
/*!50503 SET character_set_client = utf8mb4 */;
314314
CREATE TABLE `wp_terms` (
315315
`term_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
316-
`name` varchar(200) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
317-
`slug` varchar(200) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
316+
`name` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
317+
`slug` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
318318
`term_group` bigint(10) NOT NULL DEFAULT 0,
319319
PRIMARY KEY (`term_id`),
320320
KEY `slug` (`slug`(191)),
321321
KEY `name` (`name`(191))
322-
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
322+
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
323323
/*!40101 SET character_set_client = @saved_cs_client */;
324324

325325
--
@@ -342,12 +342,12 @@ DROP TABLE IF EXISTS `wp_usermeta`;
342342
CREATE TABLE `wp_usermeta` (
343343
`umeta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
344344
`user_id` bigint(20) unsigned NOT NULL DEFAULT 0,
345-
`meta_key` varchar(255) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
346-
`meta_value` longtext COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
345+
`meta_key` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
346+
`meta_value` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL,
347347
PRIMARY KEY (`umeta_id`),
348348
KEY `user_id` (`user_id`),
349349
KEY `meta_key` (`meta_key`(191))
350-
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
350+
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
351351
/*!40101 SET character_set_client = @saved_cs_client */;
352352

353353
--
@@ -369,20 +369,20 @@ DROP TABLE IF EXISTS `wp_users`;
369369
/*!50503 SET character_set_client = utf8mb4 */;
370370
CREATE TABLE `wp_users` (
371371
`ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
372-
`user_login` varchar(60) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
373-
`user_pass` varchar(255) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
374-
`user_nicename` varchar(50) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
375-
`user_email` varchar(100) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
376-
`user_url` varchar(100) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
372+
`user_login` varchar(60) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
373+
`user_pass` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
374+
`user_nicename` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
375+
`user_email` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
376+
`user_url` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
377377
`user_registered` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
378-
`user_activation_key` varchar(255) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
378+
`user_activation_key` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
379379
`user_status` int(11) NOT NULL DEFAULT 0,
380-
`display_name` varchar(250) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
380+
`display_name` varchar(250) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
381381
PRIMARY KEY (`ID`),
382382
KEY `user_login_key` (`user_login`),
383383
KEY `user_nicename` (`user_nicename`),
384384
KEY `user_email` (`user_email`)
385-
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
385+
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
386386
/*!40101 SET character_set_client = @saved_cs_client */;
387387

388388
--

tests/wpunit/BuilderTest.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,4 +365,76 @@ public function update() {
365365
Register::remove_table( $klutz_table );
366366
Register::remove_table( $zorps_table );
367367
}
368+
369+
/**
370+
* @test
371+
*/
372+
public function should_not_create_tables_during_switch_blog_if_blog_not_installed(): void {
373+
// Register the table.
374+
$table = $this->get_simple_table();
375+
Register::table( $table );
376+
$table->drop();
377+
// Sanity check.
378+
$this->assertFalse( $table->exists() );
379+
// Set up as if switching to a blog before it's installed, during its creeation.
380+
wp_cache_delete( 'is_blog_installed' );
381+
// Remove all other filters to avoid side-effects.
382+
remove_all_filters( 'switch_blog' );
383+
384+
$builder = Schema::builder();
385+
386+
add_action( 'switch_blog', [ $builder, 'update_blog_tables' ] );
387+
388+
do_action( 'switch_blog', 66 );
389+
390+
$this->assertFalse( $table->exists() );
391+
}
392+
393+
/**
394+
* @test
395+
*/
396+
public function should_create_tables_during_switch_blog_if_blog_installed(): void {
397+
// Register the table.
398+
$table = $this->get_simple_table();
399+
Register::table( $table );
400+
$table->drop();
401+
// Sanity check.
402+
$this->assertFalse( $table->exists() );
403+
// Set up as if switching to a blog after it's installed.
404+
wp_cache_set( 'is_blog_installed', true );
405+
// Remove all other filters to avoid side-effects.
406+
remove_all_filters( 'switch_blog' );
407+
408+
$builder = Schema::builder();
409+
410+
add_action( 'switch_blog', [ $builder, 'update_blog_tables' ] );
411+
412+
do_action( 'switch_blog', 66 );
413+
414+
$this->assertTrue( $table->exists() );
415+
}
416+
417+
/**
418+
* @test
419+
*/
420+
public function should_create_tables_during_activate_blog(): void {
421+
// Register the table.
422+
$table = $this->get_simple_table();
423+
Register::table( $table );
424+
$table->drop();
425+
// Sanity check.
426+
$this->assertFalse( $table->exists() );
427+
// Set up as if switching to a blog after it's installed.
428+
wp_cache_set( 'is_blog_installed', true );
429+
// Remove all other filters to avoid side-effects.
430+
remove_all_filters( 'activate_blog' );
431+
432+
$builder = Schema::builder();
433+
434+
add_action( 'activate_blog', [ $builder, 'update_blog_tables' ] );
435+
436+
do_action( 'activate_blog', 66 );
437+
438+
$this->assertTrue( $table->exists() );
439+
}
368440
}

0 commit comments

Comments
 (0)