Skip to:
Content

BuddyPress.org

Changeset 8313


Ignore:
Timestamp:
04/23/2014 04:37:18 AM (10 years ago)
Author:
johnjamesjacoby
Message:

Remove helper functions for assessing the state of the wp_signups table, as they are no longer used in multiple places. Instead, suppress errors and always query for the existence of the table and signup_id column before attempting to upgrade or install. See #5563. Props r-a-y. (trunk)

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-update.php

    r8310 r8313  
    238238
    239239        // 2.0.1
    240         if ( $raw_db_version < 8300 ) {
     240        if ( $raw_db_version < 8311 ) {
    241241            bp_update_to_2_0_1();
    242242        }
     
    449449
    450450/**
    451  * Check if the signups table already exists
    452  *
    453  * @since BuddyPress (2.0.1)
    454  *
    455  * @global WPDB $wpdb
    456  *
    457  * @return bool If signups table exists
    458  */
    459 function bp_core_signups_table_exists() {
    460     global $wpdb;
    461 
    462     // Some installations may already have a signups table (multisite, plugins, etc...)
    463     if ( ! empty( $wpdb->signups ) ) {
    464         return true;
    465     }
    466 
    467     // Suppress errors because users shouldn't see this
    468     $old_suppress = $wpdb->suppress_errors();
    469 
    470     // 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.
    472     $table_exists = $wpdb->get_results( "DESCRIBE {$wpdb->base_prefix}signups;" );
    473 
    474     // Restore previous error suppression setting
    475     $wpdb->suppress_errors( $old_suppress );
    476 
    477     // Return whether or not the table exists
    478     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  */
    492 function 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;
    511 }
    512 
    513 /**
    514  * Check if the signups table needs to be created.
     451 * Check if the signups table needs to be created or upgraded.
    515452 *
    516453 * @since BuddyPress (2.0.0)
     
    527464    }
    528465
     466    global $wpdb;
     467
     468    // The table to run queries against
     469    $signups_table = $wpdb->base_prefix . 'signups';
     470
     471    // Suppress errors because users shouldn't see what happens next
     472    $old_suppress  = $wpdb->suppress_errors();
     473
     474    // Never use bp_core_get_table_prefix() for any global users tables
     475    $table_exists  = (bool) $wpdb->get_results( "DESCRIBE {$signups_table};" );
     476
    529477    // Table already exists, so maybe upgrade instead?
    530     if ( bp_core_signups_table_exists() ) {
     478    if ( true === $table_exists ) {
     479
     480        // Look for the 'signup_id' column
     481        $column_exists = $wpdb->query( "SHOW COLUMNS FROM {$signups_table} LIKE 'signup_id'" );
    531482
    532483        // 'signup_id' column doesn't exist, so run the upgrade
    533         if ( ! bp_core_signups_id_column_exists() ) {
     484        if ( empty( $column_exists ) ) {
    534485            bp_core_upgrade_signups();
    535486        }
    536487
    537     // Table does not exist, and not multisite, so install the signups table
     488    // Table does not exist, and we are a single site, so install the multisite
     489    // signups table using WordPress core's database schema.
    538490    } elseif ( ! is_multisite() ) {
    539491        bp_core_install_signups();
    540492    }
     493
     494    // Restore previous error suppression setting
     495    $wpdb->suppress_errors( $old_suppress );
    541496}
    542497
  • trunk/bp-loader.php

    r8302 r8313  
    305305
    306306        $this->version    = '2.1-alpha';
    307         $this->db_version = 8300;
     307        $this->db_version = 8311;
    308308
    309309        /** Loading ***************************************************/
Note: See TracChangeset for help on using the changeset viewer.