Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/21/2014 04:14:52 PM (11 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/bp-core-update.php

    r8196 r8302  
    236236            bp_update_to_2_0();
    237237        }
     238
     239        // 2.0.1
     240        if ( $raw_db_version < 8300 ) {
     241            bp_update_to_2_0_1();
     242        }
    238243    }
    239244
     
    243248    bp_version_bump();
    244249}
     250
     251/** Upgrade Routines **********************************************************/
    245252
    246253/**
     
    339346 * - Migrate last_activity data from usermeta to activity table
    340347 * - Add values for all BuddyPress options to the options table
     348 *
     349 * @since BuddyPress (2.0.0)
    341350 */
    342351function bp_update_to_2_0() {
    343     global $wpdb;
    344352
    345353    /** Install activity tables for 'last_activity' ***************************/
     
    355363    if ( ! is_multisite() ) {
    356364
    357         if ( empty( $wpdb->signups ) ) {
    358             bp_core_install_signups();
    359         }
     365        // Maybe install the signups table
     366        bp_core_maybe_install_signups();
    360367
    361368        $signups = get_users( array(
     
    401408
    402409/**
     410 * 2.0.1 database upgrade routine
     411 *
     412 * @since BuddyPress (2.0.1)
     413 *
     414 * @return void
     415 */
     416function bp_update_to_2_0_1() {
     417    bp_core_maybe_upgrade_signups();
     418}
     419
     420/**
    403421 * Redirect user to BP's What's New page on first page load after activation.
    404422 *
     
    423441    // Add the transient to redirect
    424442    set_transient( '_bp_activation_redirect', true, 30 );
     443}
     444
     445/** Signups *******************************************************************/
     446
     447/**
     448 * Check if the signups table already exists
     449 *
     450 * @since BuddyPress (2.0.1)
     451 *
     452 * @global WPDB $wpdb
     453 *
     454 * @return bool If signups table exists
     455 */
     456function bp_core_signups_table_exists() {
     457    global $wpdb;
     458
     459    // Some installations may already have a signups table (multisite, plugins, etc...)
     460    if ( ! empty( $wpdb->signups ) ) {
     461        return true;
     462    }
     463
     464    // Check for the table (we suppress errors because users shouldn't see this)
     465    $old_suppress = $wpdb->suppress_errors();
     466
     467    // Never use bp_core_get_table_prefix() for any global users tables
     468    $table_exists = $wpdb->get_results( "DESCRIBE {$wpdb->base_prefix}signups;" );
     469
     470    // Restore previous error suppression setting
     471    $wpdb->suppress_errors( $old_suppress );
     472
     473    // Return whether or not the table exists
     474    return (bool) $table_exists;
     475}
     476
     477/**
     478 * Check if the signups table needs to be created.
     479 *
     480 * @since BuddyPress (2.0.0)
     481 *
     482 * @global WPDB $wpdb
     483 *
     484 * @return bool If signups table exists
     485 */
     486function bp_core_maybe_install_signups() {
     487
     488    // Bail if we are explicitly not upgrading global tables
     489    if ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) {
     490        return false;
     491    }
     492
     493    // Try to install the sign-ups table
     494    if ( ! is_multisite() && ! bp_core_signups_table_exists() ) {
     495        bp_core_install_signups();
     496    }
     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 */
     519function 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();
    425533}
    426534
Note: See TracChangeset for help on using the changeset viewer.