Make WordPress Core

Opened 5 years ago

Closed 4 years ago

#38856 closed enhancement (fixed)

Backward compat consideration for wp_blogs.archived

Reported by: stephdau Owned by: jeremyfelt
Milestone: 4.9 Priority: normal
Severity: normal Version: 4.7
Component: Networks and Sites Keywords: has-patch
Focuses: multisite Cc:

Description (last modified by stephdau)

The archived column in wp_blogs used to be of the enum data type, but was switched to tinyint 3 years ago, in r25448.

Some older instances might not have migrated to the newer data type (ALTERs on large tables isn't fun).

In class-wp-site-query.php, we use $wpdb->prepare( "archived = %d ", $archived );, which translates to archived = 0|1. Tis works great with tinyint, but fails with the older enum type, as it expects the value to be single quoted.

Since archived = '0|1' works with both data types, @jeremyfelt suggested we move the prepare() statement to using %s and absint() instead: https://wordpress.slack.com/archives/core-multisite/p1479504691000517

Attachments (1)

38856.diff (627 bytes) - added by stephdau 5 years ago.

Download all attachments as: .zip

Change History (5)

5 years ago

#1 @stephdau
5 years ago

  • Description modified (diff)

#3 @jeremyfelt
4 years ago

  • Milestone changed from Awaiting Review to 4.9
  • Owner set to jeremyfelt
  • Status changed from new to reviewing

#4 @jeremyfelt
4 years ago

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

In 41700:

Multisite: Use %s when building query for archived sites in WP_Site_Query.

In [25548], the archived column in wp_blogs was changed from ENUM to TINYINT to match other status fields. When WP_Site_Query was written later, it used %d as a placeholder when formatting the archived status.

It is possible that this query will fail for any installations that did not update the schema for wp_blogs as only single quoted values are accepted for the ENUM type. In this case, '0' or '1' rather than 0 or 1.

We can work around this and support both ENUM and TINYINT in the query by using the %s placeholder and casting the value with absint().

Props stephdau.
Fixes #38856. See #27832.

Note: See TracTickets for help on using tickets.