/**
 * 2.0 update routine.
 *
 * - Ensure that the activity tables are installed, for last_activity storage.
 * - Migrate last_activity data from usermeta to activity table.
 * - Add values for all BuddyPress options to the options table.
 *
 * @since 2.0.0
 */
function bp_update_to_2_0()
{
    /** Install activity tables for 'last_activity' ***************************/
    bp_core_install_activity_streams();
    /** Migrate 'last_activity' data ******************************************/
    bp_last_activity_migrate();
    /** Migrate signups data **************************************************/
    if (!is_multisite()) {
        // Maybe install the signups table
        bp_core_maybe_install_signups();
        // Run the migration script
        bp_members_migrate_signups();
    }
    /** Add BP options to the options table ***********************************/
    bp_add_options();
}
/**
 * Repair user last_activity data.
 *
 * Re-runs the migration from usermeta introduced in BP 2.0.
 *
 * @since BuddyPress (2.0.0)
 */
function bp_admin_repair_last_activity()
{
    $statement = __('Determining last activity dates for each user… %s', 'buddypress');
    bp_last_activity_migrate();
    return array(0, sprintf($statement, __('Complete!', 'buddypress')));
}
 /**
  * @group bp_last_activity_migrate
  * @expectedIncorrectUsage update_user_meta( $user_id, 'last_activity' )
  * @expectedIncorrectUsage get_user_meta( $user_id, 'last_activity' )
  */
 public function test_bp_last_activity_migrate()
 {
     // We explicitly do not want last_activity created, so use the
     // WP factory methods
     $u1 = $this->factory->user->create();
     $u2 = $this->factory->user->create();
     $u3 = $this->factory->user->create();
     $time = time();
     $t1 = date('Y-m-d H:i:s', $time - 50);
     $t2 = date('Y-m-d H:i:s', $time - 500);
     $t3 = date('Y-m-d H:i:s', $time - 5000);
     update_user_meta($u1, 'last_activity', $t1);
     update_user_meta($u2, 'last_activity', $t2);
     update_user_meta($u3, 'last_activity', $t3);
     // Create an existing entry in last_activity to test no dupes
     global $wpdb;
     $bp = buddypress();
     $wpdb->query($wpdb->prepare("INSERT INTO {$bp->members->table_name_last_activity}\n\t\t\t\t(`user_id`, `component`, `type`, `action`, `content`, `primary_link`, `item_id`, `date_recorded` ) VALUES\n\t\t\t\t( %d, %s, %s, %s, %s, %s, %d, %s )", $u2, $bp->members->id, 'last_activity', '', '', '', 0, $t1));
     bp_last_activity_migrate();
     $expected = array($u1 => $t1, $u2 => $t2, $u3 => $t3);
     $found = array($u1 => '', $u2 => '', $u3 => '');
     foreach ($found as $uid => $v) {
         $found[$uid] = bp_get_user_last_activity($uid);
     }
     $this->assertSame($expected, $found);
 }