Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/21/2014 04:14:52 PM (10 years ago)
Author:
johnjamesjacoby
Message:

Signups: Introduce functions for upgrading the global wp_signups table if an old version exists. This happens primarily on singlesite installations where third party plugins may have previously created the sign-ups table without keeping it updated.

  • Bumps the DB version number to 8300.
  • Moves functions for table creation and upgrade into the admin schema file.
  • Moves sign-ups table creation out of activation process, and into the database upgrade process.
  • No not rely on dbDelta() for these specific database upgrades (inspired by [WP25179])

See #5563, #WP27855. (trunk)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/admin/bp-core-schema.php

    r8196 r8302  
    349349}
    350350
     351/** Signups *******************************************************************/
     352
    351353/**
    352354 * Install the signups table.
     
    360362    global $wpdb;
    361363
    362     // Multisite installations already have the signups table
    363     if ( ! empty( $wpdb->signups ) ) {
    364         return;
    365     }
    366 
    367     $wpdb->signups = bp_core_get_table_prefix() . 'signups';
    368 
    369     // Setting the charset to be sure WordPress upgrade.php is loaded
    370     $charset_collate = bp_core_set_charset();
     364    // Signups is not there and we need it so let's create it
     365    require_once( buddypress()->plugin_dir . '/bp-core/admin/bp-core-schema.php' );
     366    require_once( ABSPATH                  . 'wp-admin/includes/upgrade.php'     );
     367
     368    // Never use bp_core_get_table_prefix() for any global users tables
     369    $wpdb->signups = $wpdb->base_prefix . 'signups';
    371370
    372371    // Use WP's core CREATE TABLE query
    373372    $create_queries = wp_get_db_schema( 'ms_global' );
    374 
    375373    if ( ! is_array( $create_queries ) ) {
    376374        $create_queries = explode( ';', $create_queries );
     
    381379    foreach ( $create_queries as $key => $query ) {
    382380        if ( preg_match( "|CREATE TABLE ([^ ]*)|", $query, $matches ) ) {
    383             if ( $wpdb->signups != trim( $matches[1], '`' ) ) {
     381            if ( trim( $matches[1], '`' ) !== $wpdb->signups ) {
    384382                unset( $create_queries[ $key ] );
    385383            }
     
    387385    }
    388386
     387    // Run WordPress's database upgrader
    389388    if ( ! empty( $create_queries ) ) {
    390389        dbDelta( $create_queries );
    391390    }
    392391}
     392
     393/**
     394 * Update the signups table, adding `signup_id` column and drop `domain` index.
     395 *
     396 * This is necessary because WordPress's `pre_schema_upgrade()` function wraps
     397 * table ALTER's in multisite checks, and other plugins may have installed their
     398 * own sign-ups table; Eg: Gravity Forms User Registration Add On
     399 *
     400 * @since BuddyPress (2.0.1)
     401 *
     402 * @see pre_schema_upgrade()
     403 * @link https://core.trac.wordpress.org/ticket/27855 WordPress Trac Ticket
     404 * @link https://buddypress.trac.wordpress.org/ticket/5563 BuddyPress Trac Ticket
     405 *
     406 * @global WPDB $wpdb
     407 */
     408function bp_core_upgrade_signups() {
     409    global $wpdb;
     410
     411    // Never use bp_core_get_table_prefix() for any global users tables
     412    $wpdb->signups = $wpdb->base_prefix . 'signups';
     413
     414    // Attempt to alter the signups table
     415    $wpdb->query( "ALTER TABLE {$wpdb->signups} ADD signup_id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST" );
     416    $wpdb->query( "ALTER TABLE {$wpdb->signups} DROP INDEX domain" );
     417}
Note: See TracChangeset for help on using the changeset viewer.