Make WordPress Core

Opened 7 years ago

Closed 7 years ago

#42641 closed defect (bug) (fixed)

On multisite upgrade the wp_blog_versions table doesn't get updated

Reported by: lenasterg's profile lenasterg Owned by: flixos90's profile flixos90
Milestone: 4.9.1 Priority: normal
Severity: major Version: 4.9
Component: Upgrade/Install Keywords: has-patch fixed-major
Focuses: multisite Cc:

Description

Hi. Thanks for the great work with WP 4.9.

I noticed that in my multisite installation the wp_blog_versions doesn't get updated.

I manage to isolate the problem to the lines
https://core.trac.wordpress.org/browser/trunk/src/wp-admin/includes/upgrade.php#L438 - line 442.

The code there:

  • adds quotes to the table names and
  • uses the mysql now() as php function which causes php warning

The code there is:

 if ( $wpdb->get_row( $wpdb->prepare( 'SELECT blog_id FROM %s WHERE blog_id = %d', $wpdb->blog_versions, $site_id ) ) ) {
			$wpdb->query( $wpdb->prepare( 'UPDATE %s SET db_version = %d WHERE blog_id = %d', $wpdb->blog_versions, $wp_db_version, $site_id ) );
 	    } else {
			$wpdb->query( $wpdb->prepare( 'INSERT INTO %s ( `blog_id` , `db_version` , `last_updated` ) VALUES ( %d, %d, %s);', $wpdb->blog_versions, $site_id, $wp_db_version, NOW() ) );
 	    }

In my installation the following changes fixed the issue.

if ( $wpdb->get_row( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blog_versions WHERE blog_id = %d",  $site_id ) ) )
 { 
   $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->blog_versions SET db_version = %d WHERE blog_id = %d", $wp_db_version, $site_id ) );
}
 else {
    $now = current_time( 'mysql' );
    $wpdb->query( $wpdb->prepare( "INSERT INTO  $wpdb->blog_versions( `blog_id` , `db_version` ,`last_updated`) VALUES ( %d, %d, %s)", $site_id, $wp_db_version, $now ) );
 }

Since I couldn't find a relavant ticket, I'm not sure if this is a bug or only in my installation (Running PHP 7.0.25).

Bests,
Lena

Attachments (1)

42641.diff (1.2 KB) - added by Mista-Flo 7 years ago.

Download all attachments as: .zip

Change History (9)

#1 @ocean90
7 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 4.9.1
  • Severity changed from normal to major

Hello @lenasterg, thanks for your report!

This was introduced in [41661].

This ticket was mentioned in Slack in #core-multisite by flixos90. View the logs.


7 years ago

#3 @flixos90
7 years ago

  • Owner set to flixos90
  • Status changed from new to assigned

Seems like a rather straightforward fix. I'll take care of it, unless someone beats me to it.

#4 @Mista-Flo
7 years ago

  • Keywords has-patch added; needs-patch removed

Hi,

I have done a patch for this issue, thanks to @lenasterg and @flixos90

@Mista-Flo
7 years ago

#5 @flixos90
7 years ago

  • Status changed from assigned to reviewing

Thanks for the patch @Mista-Flo, and the detailed explanation @lenasterg! This looks like a solid fix.

#6 @flixos90
7 years ago

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

In 42210:

Multisite: Fix broken update blog_versions query after [41661].

Props Mista-Flo, lenasterg.
Fixes #42641.

#7 @flixos90
7 years ago

  • Keywords fixed-major added
  • Resolution fixed deleted
  • Status changed from closed to reopened

This needs to be back-ported to 4.9.1.

#8 @dd32
7 years ago

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

In 42212:

Multisite: Fix broken update blog_versions query after [41661].

Props Mista-Flo, lenasterg, flixos90.
Merges [42210] to the 4.9 branch.
Fixes #42641.

Note: See TracTickets for help on using tickets.