Skip to content

Conversation

@lucatume
Copy link
Contributor

This changes the logic put in place in this
commit

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.

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.
@lucatume lucatume self-assigned this Jul 18, 2025
@lucatume lucatume marked this pull request as ready for review July 18, 2025 11:02
@lucatume lucatume requested review from borkweb and dpanta94 July 18, 2025 11:02
@lucatume lucatume changed the base branch from main to 2.0.1 July 18, 2025 12:45
@lucatume lucatume merged commit bf88b38 into 2.0.1 Jul 18, 2025
2 checks passed
@lucatume lucatume deleted the fix/multisite-table-up branch July 18, 2025 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants