Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#54634 closed defect (bug) (fixed)

Database access on potentially missing table during WP installation

Reported by: schlessera's profile schlessera Owned by: hellofromtonya's profile hellofromTonya
Milestone: 5.9 Priority: high
Severity: normal Version:
Component: Script Loader Keywords: has-patch commit
Focuses: Cc:

Description

When installing a multisite, there is a potential access to a non-existent database table that needs to be skipped to avoid warnings/errors.

001 Scenario: Install WordPress multisite with existing multisite constants in wp-config file                                                                         # features/core-install.feature:204
      When I run `wp core multisite-install --url=foobar.org --title=Test --admin_user=wpcli --admin_email=admin@example.com --admin_password=password --skip-config` # features/core-install.feature:226
        $ wp core multisite-install --url=foobar.org --title=Test --admin_user=wpcli --admin_email=admin@example.com --admin_password=password --skip-config
        WP-CLI test suite: Sent email to admin@example.com.
        Created single site database tables.
        Set up multisite database tables.
        Success: Network installed. Don't forget to set up rewrite rules (and a .htaccess file, if using Apache).

        WordPress database error Table 'wp_cli_test.wp_sitemeta' doesn't exist for query SELECT meta_value FROM wp_sitemeta WHERE meta_key = 'can_compress_scripts' AND site_id = 1 made by require_once('vendor/wp-cli/wp-cli/php/wp-cli.php'), WP_CLI\bootstrap, WP_CLI\Bootstrap\LaunchRunner->process, WP_CLI\Runner->start, WP_CLI\Runner->load_wordpress, require('wp-settings.php'), do_action('init'), WP_Hook->do_action, WP_Hook->apply_filters, register_block_core_file, register_block_type_from_metadata, register_block_script_handle, wp_register_script, wp_scripts, WP_Scripts->__construct, WP_Scripts->init, do_action_ref_array('wp_default_scripts'), WP_Hook->do_action, WP_Hook->apply_filters, wp_default_packages, wp_register_tinymce_scripts, script_concat_settings, get_site_option, get_network_option
        cwd: /tmp/wp-cli-test-run--61ba15774b81d8.03513765/
        run time: 1.1995339393616
        exit status: 0 (RuntimeException)

The problem comes from the script_concat_settings() function (triggered by 'wp_default_scripts' => wp_register_tinymce_scripts()), which tries to retrieve the site option 'can_compress_scripts'.

Change History (8)

This ticket was mentioned in PR #2054 on WordPress/wordpress-develop by schlessera.


3 years ago
#1

  • Keywords has-patch added

When installing a multisite, there is a potential access to a non-existent database table that needs to be skipped to avoid warnings/errors.

001 Scenario: Install WordPress multisite with existing multisite constants in wp-config file                                                                         # features/core-install.feature:204
      When I run `wp core multisite-install --url=foobar.org --title=Test --admin_user=wpcli --admin_email=admin@example.com --admin_password=password --skip-config` # features/core-install.feature:226
        $ wp core multisite-install --url=foobar.org --title=Test --admin_user=wpcli --admin_email=admin@example.com --admin_password=password --skip-config
        WP-CLI test suite: Sent email to admin@example.com.
        Created single site database tables.
        Set up multisite database tables.
        Success: Network installed. Don't forget to set up rewrite rules (and a .htaccess file, if using Apache).

        WordPress database error Table 'wp_cli_test.wp_sitemeta' doesn't exist for query SELECT meta_value FROM wp_sitemeta WHERE meta_key = 'can_compress_scripts' AND site_id = 1 made by require_once('vendor/wp-cli/wp-cli/php/wp-cli.php'), WP_CLI\bootstrap, WP_CLI\Bootstrap\LaunchRunner->process, WP_CLI\Runner->start, WP_CLI\Runner->load_wordpress, require('wp-settings.php'), do_action('init'), WP_Hook->do_action, WP_Hook->apply_filters, register_block_core_file, register_block_type_from_metadata, register_block_script_handle, wp_register_script, wp_scripts, WP_Scripts->__construct, WP_Scripts->init, do_action_ref_array('wp_default_scripts'), WP_Hook->do_action, WP_Hook->apply_filters, wp_default_packages, wp_register_tinymce_scripts, script_concat_settings, get_site_option, get_network_option
        cwd: /tmp/wp-cli-test-run--61ba15774b81d8.03513765/
        run time: 1.1995339393616
        exit status: 0 (RuntimeException)

The problem comes from the script_concat_settings() function (triggered by 'wp_default_scripts' => wp_register_tinymce_scripts()), which tries to retrieve the site option 'can_compress_scripts'.

This PR adapts the code so that it first checks whether WP is installing before trying to retrieve the site option. During WP installation, script compression defaults to false.

This PR also optimizes the check by storing the DB request, instead of executing it twice.

Trac ticket: https://core.trac.wordpress.org/ticket/54634

#2 @schlessera
3 years ago

  • Milestone changed from Awaiting Review to 5.9
  • Priority changed from normal to high

#3 @SergeyBiryukov
3 years ago

  • Component changed from General to Script Loader

This ticket was mentioned in Slack in #core by schlessera. View the logs.


3 years ago

#5 @hellofromTonya
3 years ago

  • Keywords commit added

Hmm, not finding what changed during the 5.9 cycle that caused this problem. That said, it's something to fix. As there's a patch that resolves the issue @schlessera notes, marking PR 2054 for commit.

#6 @hellofromTonya
3 years ago

  • Owner set to hellofromTonya
  • Status changed from new to reviewing

Self-assigning for commit.

#7 @hellofromTonya
3 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 52395:

Script Loader: Skip getting 'can_compress_scripts' option in script_concat_settings() during install.

When installing a multisite, there is a potential access to a non-existent database table that needs to be skipped to avoid warnings/errors. This fix checks is WordPress is not installing before getting the 'can_compress_scripts' option.

Props schlessera.
Fixes #54634.

Note: See TracTickets for help on using tickets.