Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/24/2014 12:22:29 AM (12 years ago)
Author:
boonebgorges
Message:

Improve the migration tool that converts old non-multisite signups to post-2.0 system

This refactoring involves a number of improvements:

  • Old signups are identified as those users with user_status=2, instead of those users with an 'activation_key' usermeta value. Use of the latter technique caused problems with upgrades when plugins had interfered in the normal BuddyPress registration flow in such a way as to retain the activation key on activated accounts. user_status=2 is a more reliable technique.
  • Querying by user_status=2 means that the get_users() query does not have to include all usermeta, which makes for a more performant query on large sites.
  • The migration routine has been broken out into a separate function bp_members_migrate_signups(), and unit tests have been written for it.
  • Activation keys are now regenerated for migrated users who did not have an existing key in usermeta for some reason.

Fixes #5553

Props imath

File:
1 edited

Legend:

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

    r8313 r8315  
    366366                bp_core_maybe_install_signups();
    367367
    368                 $signups = get_users( array(
    369                         'fields'       => 'all_with_meta',
    370                         'meta_key'     => 'activation_key',
    371                         'meta_compare' => 'EXISTS',
    372                 ) );
    373 
    374                 if ( empty( $signups ) ) {
    375                         return;
    376                 }
    377 
    378                 foreach ( $signups as $signup ) {
    379                         $meta = array();
    380 
    381                         if ( bp_is_active( 'xprofile' ) ) {
    382                                 $meta['field_1'] = $signup->display_name;
    383                         }
    384 
    385                         $meta['password'] = $signup->user_pass;
    386 
    387                         $user_login = preg_replace( '/\s+/', '', sanitize_user( $signup->user_login, true ) );
    388                         $user_email = sanitize_email( $signup->user_email );
    389 
    390                         BP_Signup::add( array(
    391                                 'user_login'     => $user_login,
    392                                 'user_email'     => $user_email,
    393                                 'registered'     => $signup->user_registered,
    394                                 'activation_key' => $signup->activation_key,
    395                                 'meta'           => $meta
    396                         ) );
    397 
    398                         // Deleting these options will remove signups from users count
    399                         delete_user_option( $signup->ID, 'capabilities' );
    400                         delete_user_option( $signup->ID, 'user_level'   );
    401                 }
     368                // Run the migration script
     369                bp_members_migrate_signups();
    402370        }
    403371
Note: See TracChangeset for help on using the changeset viewer.