Skip to:
Content

BuddyPress.org

Changeset 8309


Ignore:
Timestamp:
04/21/2014 09:48:38 PM (5 years ago)
Author:
johnjamesjacoby
Message:

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

Location:
branches/2.0/bp-core
Files:
2 edited

Legend:

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

    r8301 r8309  
    5252        bp_core_install_blog_tracking();
    5353
    54     // Install the signups table
    55     bp_core_install_signups();
    56 
     54    // Maybe install (or upgrade) the signups table
     55    bp_core_maybe_install_signups();
    5756}
    5857
  • branches/2.0/bp-core/bp-core-update.php

    r8301 r8309  
    350350 */
    351351function bp_update_to_2_0() {
    352     global $wpdb;
    353352
    354353    /** Install activity tables for 'last_activity' ***************************/
     
    462461    }
    463462
    464     // Check for the table (we suppress errors because users shouldn't see this)
     463    // Suppress errors because users shouldn't see this
    465464    $old_suppress = $wpdb->suppress_errors();
    466465
    467466    // Never use bp_core_get_table_prefix() for any global users tables
     467    // We also don't use $wpdb->signups because we want decisive evidence.
    468468    $table_exists = $wpdb->get_results( "DESCRIBE {$wpdb->base_prefix}signups;" );
    469469
     
    473473    // Return whether or not the table exists
    474474    return (bool) $table_exists;
     475}
     476
     477/**
     478 * Check if the signups table already exists
     479 *
     480 * @since BuddyPress (2.0.1)
     481 *
     482 * @global WPDB $wpdb
     483 *
     484 * @link https://core.trac.wordpress.org/changeset/25179
     485 *
     486 * @return bool If signup_id column exists
     487 */
     488function bp_core_signups_id_column_exists() {
     489    global $wpdb;
     490
     491    // No signups table to query, so bail and return false
     492    if ( empty( $wpdb->signups ) ) {
     493        return false;
     494    }
     495
     496    // Suppress errors because users shouldn't see this
     497    $old_suppress = $wpdb->suppress_errors();
     498
     499    // Never use bp_core_get_table_prefix() for any global users tables
     500    $column_exists = $wpdb->query( "SHOW COLUMNS FROM {$wpdb->signups} LIKE 'signup_id'" );
     501
     502    // Restore previous error suppression setting
     503    $wpdb->suppress_errors( $old_suppress );
     504
     505    // Column does not exist
     506    return $column_exists;
    475507}
    476508
     
    491523    }
    492524
    493     // Try to install the sign-ups table
    494     if ( ! is_multisite() && ! bp_core_signups_table_exists() ) {
     525    // Table already exists, so maybe upgrade instead?
     526    if ( bp_core_signups_table_exists() ) {
     527
     528        // 'signup_id' column doesn't exist, so run the upgrade
     529        if ( ! bp_core_signups_id_column_exists() ) {
     530            bp_core_upgrade_signups();
     531        }
     532
     533    // Table does not exist, and not multisite, so install the signups table
     534    } elseif ( ! is_multisite() ) {
    495535        bp_core_install_signups();
    496536    }
    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();
    533537}
    534538
Note: See TracChangeset for help on using the changeset viewer.