Skip to content
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

Missing database tables on Multisite #859

Open
hupe13 opened this issue Jan 22, 2025 · 6 comments · May be fixed by #865
Open

Missing database tables on Multisite #859

hupe13 opened this issue Jan 22, 2025 · 6 comments · May be fixed by #865
Labels
[Type] Bug An existing feature is broken
Milestone

Comments

@hupe13
Copy link

hupe13 commented Jan 22, 2025

I have Plugin Check installed on a multisite installation and activated it on site 19. I see many errors in debug log about non existing tables in the database.

WordPress database error Table 'database.wp_19_pc_blogs' doesn't exist for query
WordPress database error Table 'database.wp_19_pc_sitemeta' doesn't exist for query
WordPress database error Table 'database.wp_19_pc_usermeta' doesn't exist for query
WordPress database error Table 'database.wp_19_pc_users' doesn't exist for query

Apparently these tables are not created.

@swissspidy swissspidy changed the title wp_19_pc_users, wp_19_pc_blogs and more Missing database tables on Multisite Jan 22, 2025
@swissspidy
Copy link
Member

These are actually standard tables created by WordPress itself. There seems to be something wrong with your Multisite installation.

Also note that PCP doesn't have full Multisite support at the moment, see #64.

@hupe13
Copy link
Author

hupe13 commented Jan 22, 2025

The tables wp_blogs, wp_sitemeta, wp_usermeta and wp_users exist, but not with "_19_pc" in the name.

@dd32
Copy link
Member

dd32 commented Jan 23, 2025

This sounds like PCP not setting the base_prefix correctly during it's table_prefix switching for runtime tests;

// Set the new prefix.
$old_prefix = $wpdb->set_prefix( $table_prefix . 'pc_' );

@davidperezgar
Copy link
Member

Yes! It seems that's the problem.

@davidperezgar davidperezgar linked a pull request Jan 23, 2025 that will close this issue
@swissspidy swissspidy added the [Type] Bug An existing feature is broken label Jan 28, 2025
@swissspidy
Copy link
Member

This sounds like PCP not setting the base_prefix correctly during it's table_prefix switching for runtime tests;

plugin-check/includes/Checker/Runtime_Environment_Setup.php

Lines 43 to 44 in a1ecb29

// Set the new prefix.
$old_prefix = $wpdb->set_prefix( $table_prefix . 'pc_' );

@felixarntz maybe that's one for your to look into? #860 looks like a start

@felixarntz
Copy link
Member

felixarntz commented Jan 28, 2025

@dd32 I'm looking into what's wrong here for Multisite. Maybe you can double check?

  • In ms-settings.php, the $table_prefix global (as defined in e.g. wp-config.php) is first passed to wpdb::set_prefix(), which then sets the wpdb::$base_prefix property to it.
  • Then wpdb::set_blog_id() is called, correctly setting the table names based on the base prefix.
  • Afterwards, the $table_prefix global is overwritten to be the table prefix for the current blog.
  • The current bug happens because the blog specific prefix in the $table_prefix global is now used even for the global tables, as seen in the bug report: These tables should be using wp_pc_users etc. instead of wp_19_pc_users etc.

It feels a bit confusing to me that in Multisite $table_prefix is first the value that's defined in wp-config.php (effectively wpdb::$base_prefix, but later becomes the value of wpdb::get_blog_prefix(). So the global is used for two different things. But anyway, we obviously cannot change that without breaking backward compatibility.

So if I understand the code correctly, what we need to do here is to call $wpdb->set_prefix( $wpdb->base_prefix . 'pc_' ) instead of $wpdb->set_prefix( $table_prefix . 'pc_' ) , since otherwise (currently) it would append pc_ to the current blog's prefix rather than the overall base prefix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Bug An existing feature is broken
Projects
None yet
5 participants