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/tests/testcases/members/functions.php

    r8027 r8315  
    280280                $this->assertSame( $expected, bp_core_get_user_displaynames( array( $u1, $u2, ) ) );
    281281        }
     282
     283        /**
     284         * @group bp_members_migrate_signups
     285         */
     286        public function test_bp_members_migrate_signups_standard() {
     287                $u = $this->create_user();
     288                $u_obj = new WP_User( $u );
     289
     290                // Fake an old-style registration
     291                $key = wp_hash( $u_obj->ID );
     292                update_user_meta( $u, 'activation_key', $key );
     293
     294                global $wpdb;
     295                $wpdb->update(
     296                        $wpdb->users,
     297                        array( 'user_status' => '2', ),
     298                        array( 'ID' => $u, ),
     299                        array( '%d', ),
     300                        array( '%d', )
     301                );
     302                clean_user_cache( $u );
     303
     304                bp_members_migrate_signups();
     305
     306                $found = BP_Signup::get();
     307
     308                // Use email address as a sanity check
     309                $found_email = isset( $found['signups'][0]->user_email ) ? $found['signups'][0]->user_email : '';
     310                $this->assertSame( $u_obj->user_email, $found_email );
     311
     312                // Check that activation keys match
     313                $found_key = isset( $found['signups'][0]->activation_key ) ? $found['signups'][0]->activation_key : '';
     314                $this->assertSame( $key, $found_key );
     315        }
     316
     317        /**
     318         * @group bp_members_migrate_signups
     319         */
     320        public function test_bp_members_migrate_signups_activation_key_but_user_status_0() {
     321                $u = $this->create_user();
     322                $u_obj = new WP_User( $u );
     323
     324                // Fake an old-style registration
     325                $key = wp_hash( $u_obj->ID );
     326                update_user_meta( $u, 'activation_key', $key );
     327
     328                // ...but ensure that user_status is 0. This mimics the
     329                // behavior of certain plugins that disrupt the BP registration
     330                // flow
     331                global $wpdb;
     332                $wpdb->update(
     333                        $wpdb->users,
     334                        array( 'user_status' => '0', ),
     335                        array( 'ID' => $u, ),
     336                        array( '%d', ),
     337                        array( '%d', )
     338                );
     339                clean_user_cache( $u );
     340
     341                bp_members_migrate_signups();
     342
     343                // No migrations should have taken place
     344                $found = BP_Signup::get();
     345                $this->assertEmpty( $found['total'] );
     346        }
     347
     348        /**
     349         * @group bp_members_migrate_signups
     350         */
     351        public function test_bp_members_migrate_signups_no_activation_key_but_user_status_2() {
     352                $u = $this->create_user();
     353                $u_obj = new WP_User( $u );
     354
     355                // Fake an old-style registration but without an activation key
     356                global $wpdb;
     357                $wpdb->update(
     358                        $wpdb->users,
     359                        array( 'user_status' => '2', ),
     360                        array( 'ID' => $u, ),
     361                        array( '%d', ),
     362                        array( '%d', )
     363                );
     364                clean_user_cache( $u );
     365
     366                bp_members_migrate_signups();
     367
     368                // Use email address as a sanity check
     369                $found = BP_Signup::get();
     370                $found_email = isset( $found['signups'][0]->user_email ) ? $found['signups'][0]->user_email : '';
     371                $this->assertSame( $u_obj->user_email, $found_email );
     372        }
    282373}
Note: See TracChangeset for help on using the changeset viewer.