Skip to:
Content

BuddyPress.org

Changeset 8310


Ignore:
Timestamp:
04/21/2014 09:59:55 PM (11 years ago)
Author:
johnjamesjacoby
Message:

Simplify signups table install & upgrade routines. See #5563. Props r-a-y. (trunk)

Location:
trunk/bp-core
Files:
2 edited

Legend:

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

    r8302 r8310  
    5353
    5454    // Install the signups table
    55     bp_core_install_signups();
     55    bp_core_maybe_install_signups();
    5656
    5757}
  • trunk/bp-core/bp-core-update.php

    r8302 r8310  
    415415 */
    416416function bp_update_to_2_0_1() {
    417     bp_core_maybe_upgrade_signups();
     417
     418    // We purposely call this during both the 2.0 upgrade and the 2.0.1 upgrade.
     419    // Don't worry; it won't break anything, and safely handles all cases.
     420    bp_core_maybe_install_signups();
    418421}
    419422
     
    462465    }
    463466
    464     // Check for the table (we suppress errors because users shouldn't see this)
     467    // Suppress errors because users shouldn't see this
    465468    $old_suppress = $wpdb->suppress_errors();
    466469
    467470    // Never use bp_core_get_table_prefix() for any global users tables
     471    // We also don't use $wpdb->signups because we want decisive evidence.
    468472    $table_exists = $wpdb->get_results( "DESCRIBE {$wpdb->base_prefix}signups;" );
    469473
     
    473477    // Return whether or not the table exists
    474478    return (bool) $table_exists;
     479}
     480
     481/**
     482 * Check if the signups table already exists
     483 *
     484 * @since BuddyPress (2.0.1)
     485 *
     486 * @global WPDB $wpdb
     487 *
     488 * @link https://core.trac.wordpress.org/changeset/25179
     489 *
     490 * @return bool If signup_id column exists
     491 */
     492function bp_core_signups_id_column_exists() {
     493    global $wpdb;
     494
     495    // No signups table to query, so bail and return false
     496    if ( empty( $wpdb->signups ) ) {
     497        return false;
     498    }
     499
     500    // Suppress errors because users shouldn't see this
     501    $old_suppress = $wpdb->suppress_errors();
     502
     503    // Never use bp_core_get_table_prefix() for any global users tables
     504    $column_exists = $wpdb->query( "SHOW COLUMNS FROM {$wpdb->signups} LIKE 'signup_id'" );
     505
     506    // Restore previous error suppression setting
     507    $wpdb->suppress_errors( $old_suppress );
     508
     509    // Column does not exist
     510    return $column_exists;
    475511}
    476512
     
    491527    }
    492528
    493     // Try to install the sign-ups table
    494     if ( ! is_multisite() && ! bp_core_signups_table_exists() ) {
     529    // Table already exists, so maybe upgrade instead?
     530    if ( bp_core_signups_table_exists() ) {
     531
     532        // 'signup_id' column doesn't exist, so run the upgrade
     533        if ( ! bp_core_signups_id_column_exists() ) {
     534            bp_core_upgrade_signups();
     535        }
     536
     537    // Table does not exist, and not multisite, so install the signups table
     538    } elseif ( ! is_multisite() ) {
    495539        bp_core_install_signups();
    496540    }
    497 
    498     // Return whether or not the table exists now
    499     return (bool) bp_core_signups_table_exists();
    500 }
    501 
    502 /**
    503  * Check if the signups table needs to be upgraded.
    504  *
    505  * Update the signups table, adding `signup_id` column and drop `domain` index.
    506  *
    507  * This is necessary because WordPress's `pre_schema_upgrade()` function wraps
    508  * table ALTER's in multisite checks, and other plugins may have installed their
    509  * own sign-ups table; Eg: Gravity Forms User Registration Add On
    510  *
    511  * @since BuddyPress (2.0.1)
    512  *
    513  * @see pre_schema_upgrade()
    514  * @link https://core.trac.wordpress.org/ticket/27855 WordPress Trac Ticket
    515  * @link https://buddypress.trac.wordpress.org/ticket/5563 BuddyPress Trac Ticket
    516  *
    517  * @return bool If signups table exists
    518  */
    519 function bp_core_maybe_upgrade_signups() {
    520 
    521     // Bail if we are explicitly not upgrading global tables
    522     if ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) {
    523         return false;
    524     }
    525 
    526     // Actually upgrade the sign-ups table
    527     if ( bp_core_maybe_install_signups() ) {
    528         bp_core_upgrade_signups();
    529     }
    530 
    531     // Return whether or not the table exists now
    532     return (bool) bp_core_signups_table_exists();
    533541}
    534542
Note: See TracChangeset for help on using the changeset viewer.