Skip to:
Content

BuddyPress.org

Ticket #5563: 5563.patch

File 5563.patch, 8.3 KB (added by johnjamesjacoby, 6 years ago)
  • bp-core/admin/bp-core-functions.php

     
    276276                        'id'   => 'register',
    277277                        'name' => __( 'Register', 'buddypress' )
    278278                );
    279 
    280                 bp_core_maybe_install_signups();
    281279        }
    282280
    283281        // On the first admin screen after a new installation, this isn't set, so grab it to supress a misleading error message.
     
    794792}
    795793
    796794/**
    797  * Check if the signups table needs to be created.
    798  *
    799  * @since BuddyPress (2.0.0)
    800  *
    801  * @global $wpdb
    802  */
    803 function bp_core_maybe_install_signups() {
    804         global $wpdb;
    805 
    806         // Multisite installations already have the signups table.
    807         if ( ! empty( $wpdb->signups ) ) {
    808                 return;
    809         }
    810 
    811         $bp_signups = bp_core_get_table_prefix() . 'signups';
    812 
    813         // Check for the table
    814         $suppress = $wpdb->suppress_errors();
    815         $table_exists = $wpdb->get_results( "DESCRIBE {$bp_signups};" );
    816         $wpdb->suppress_errors( $suppress );
    817 
    818         // Bail if the table exists
    819         if ( ! empty( $table_exists ) ) {
    820                 return;
    821         }
    822 
    823         // Signups is not there and we need it so let's create it
    824         require_once( buddypress()->plugin_dir . '/bp-core/admin/bp-core-schema.php' );
    825 
    826         bp_core_install_signups();
    827 }
    828 
    829 /**
    830795 * Add "Mark as Spam/Ham" button to user row actions.
    831796 *
    832797 * @since BuddyPress (2.0.0)
  • bp-core/admin/bp-core-schema.php

     
    348348        dbDelta( $sql );
    349349}
    350350
     351/** Signups *******************************************************************/
     352
    351353/**
    352354 * Install the signups table.
    353355 *
     
    359361function bp_core_install_signups() {
    360362        global $wpdb;
    361363
    362         // Multisite installations already have the signups table
    363         if ( ! empty( $wpdb->signups ) ) {
    364                 return;
    365         }
     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'     );
    366367
    367         $wpdb->signups = bp_core_get_table_prefix() . 'signups';
     368        // Never use bp_core_get_table_prefix() for any global users tables
     369        $wpdb->signups = $wpdb->base_prefix . 'signups';
    368370
    369         // Setting the charset to be sure WordPress upgrade.php is loaded
    370         $charset_collate = bp_core_set_charset();
    371 
    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 );
    377375                $create_queries = array_filter( $create_queries );
     
    380378        // Filter out all the queries except wp_signups
    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                        }
    386384                }
    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}
  • bp-core/bp-core-update.php

     
    235235                if ( $raw_db_version < 7892 ) {
    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
    240245        /** All done! *************************************************************/
     
    243248        bp_version_bump();
    244249}
    245250
     251/** Upgrade Routines **********************************************************/
     252
    246253/**
    247254 * Remove unused metadata from database when upgrading from < 1.5.
    248255 *
     
    338345 * - Ensure that the activity tables are installed, for last_activity storage.
    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() {
    343352        global $wpdb;
     
    354363
    355364        if ( ! is_multisite() ) {
    356365
    357                 if ( empty( $wpdb->signups ) ) {
    358                         bp_core_install_signups();
    359                 }
     366                // Maybe install the signups table
     367                bp_core_maybe_install_signups();
    360368
    361369                $signups = get_users( array(
    362370                        'fields'       => 'all_with_meta',
     
    400408}
    401409
    402410/**
     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 *
    405423 * @since BuddyPress (1.7.0)
     
    424442        set_transient( '_bp_activation_redirect', true, 30 );
    425443}
    426444
     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();
     533}
     534
    427535/** Activation Actions ********************************************************/
    428536
    429537/**
  • bp-loader.php

     
    303303
    304304                /** Versions **************************************************/
    305305
    306                 $this->version    = '2.0';
    307                 $this->db_version = 7892;
     306                $this->version    = '2.0.1';
     307                $this->db_version = 8300;
    308308
    309309                /** Loading ***************************************************/
    310310