Skip to:
Content

BuddyPress.org

Changeset 9716


Ignore:
Timestamp:
04/07/2015 01:28:21 PM (9 years ago)
Author:
boonebgorges
Message:

Introduce bp_pre_schema_upgrade() and use it to drop old meta_key indexes.

After [9695], BP tries to update existing indexes using dbDelta(), but
dbDelta() cannot DROP INDEX properly. So we must run a separate routine
before the regular schema updates. See WP's pre_schema_upgrade().

See #6346.

Location:
trunk/src
Files:
3 edited

Legend:

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

    r9695 r9716  
    3838 */
    3939function bp_core_install( $active_components = false ) {
     40
     41    bp_pre_schema_upgrade();
    4042
    4143    // If no components passed, get all the active components from the main site
  • trunk/src/bp-core/bp-core-update.php

    r9615 r9716  
    258258    // Bump the version
    259259    bp_version_bump();
     260}
     261
     262/**
     263 * Perform database operations that must take place before the general schema upgrades.
     264 *
     265 * `dbDelta()` cannot handle certain operations - like changing indexes - so we do it here instead.
     266 *
     267 * @since BuddyPress (2.3.0)
     268 */
     269function bp_pre_schema_upgrade() {
     270    global $wpdb;
     271
     272    $raw_db_version = (int) bp_get_db_version_raw();
     273    $bp_prefix      = bp_core_get_table_prefix();
     274
     275    // 2.3.0: Change index lengths to account for utf8mb4.
     276    if ( $raw_db_version < 9695 ) {
     277        // table_name => columns.
     278        $tables = array(
     279            $bp_prefix . 'bp_activity_meta'       => array( 'meta_key' ),
     280            $bp_prefix . 'bp_groups_groupmeta'    => array( 'meta_key' ),
     281            $bp_prefix . 'bp_messages_meta'       => array( 'meta_key' ),
     282            $bp_prefix . 'bp_notifications_meta'  => array( 'meta_key' ),
     283            $bp_prefix . 'bp_user_blogs_blogmeta' => array( 'meta_key' ),
     284            $bp_prefix . 'bp_xprofile_meta'       => array( 'meta_key' ),
     285        );
     286
     287        foreach ( $tables as $table_name => $indexes ) {
     288            foreach ( $indexes as $index ) {
     289                $wpdb->query( "ALTER TABLE $table_name DROP INDEX $index" );
     290            }
     291        }
     292    }
    260293}
    261294
  • trunk/src/bp-loader.php

    r9683 r9716  
    306306
    307307        $this->version    = '2.3-alpha';
    308         $this->db_version = 9615;
     308        $this->db_version = 9695;
    309309
    310310        /** Loading ***********************************************************/
Note: See TracChangeset for help on using the changeset viewer.