Skip to:
Content

BuddyPress.org

Changeset 8124


Ignore:
Timestamp:
03/13/2014 11:45:17 AM (10 years ago)
Author:
boonebgorges
Message:

Introduce tool on Tools menu for repairing last_activity data

Fixes #5461

Location:
trunk
Files:
3 edited

Legend:

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

    r8117 r8124  
    9696 */
    9797function bp_admin_repair_list() {
     98    $repair_list = array();
     99
    98100    // Members:
    99101    // - member count
    100     $repair_list = array(
    101         20 => array(
    102             'bp-total-member-count',
    103             __( 'Count total members', 'buddypress' ),
    104             'bp_admin_repair_count_members',
    105         ),
     102    // - last_activity migration (2.0)
     103    $repair_list[20] = array(
     104        'bp-total-member-count',
     105        __( 'Count total members', 'buddypress' ),
     106        'bp_admin_repair_count_members',
     107    );
     108
     109    $repair_list[25] = array(
     110        'bp-last-activity',
     111        __( 'Repair user "last activity" data', 'buddypress' ),
     112        'bp_admin_repair_last_activity',
    106113    );
    107114
     
    241248    delete_transient( 'bp_active_member_count' );
    242249    bp_core_get_active_member_count();
     250    return array( 0, sprintf( $statement, __( 'Complete!', 'buddypress' ) ) );
     251}
     252
     253/**
     254 * Repair user last_activity data.
     255 *
     256 * Re-runs the migration from usermeta introduced in BP 2.0.
     257 *
     258 * @since BuddyPress (2.0.0)
     259 */
     260function bp_admin_repair_last_activity() {
     261    $statement = __( 'Determining last activity dates for each user… %s', 'buddypress' );
     262    bp_last_activity_migrate();
    243263    return array( 0, sprintf( $statement, __( 'Complete!', 'buddypress' ) ) );
    244264}
  • trunk/bp-core/bp-core-update.php

    r8119 r8124  
    346346    bp_core_install_activity_streams();
    347347
    348     $bp = buddypress();
    349 
    350348    /** Migrate 'last_activity' data *************************************/
    351349
    352     // The "NOT IN" clause prevents duplicates
    353     $sql = "INSERT INTO {$bp->members->table_name_last_activity} (`user_id`, `component`, `type`, `action`, `content`, `primary_link`, `item_id`, `date_recorded` ) (
    354           SELECT user_id, '{$bp->members->id}' as component, 'last_activity' as type, '' as action, '' as content, '' as primary_link, 0 as item_id, meta_value AS date_recorded
    355           FROM {$wpdb->usermeta}
    356           WHERE
    357             meta_key = 'last_activity'
    358             AND
    359             user_id NOT IN (
    360               SELECT user_id
    361               FROM {$bp->members->table_name_last_activity}
    362               WHERE component = '{$bp->members->id}' AND type = 'last_activity'
    363             )
    364     );";
    365 
    366     $wpdb->query( $sql );
     350    bp_last_activity_migrate();
    367351
    368352    /** Migrate signups data *********************************************/
  • trunk/bp-members/bp-members-functions.php

    r8119 r8124  
    989989
    990990    return apply_filters( 'bp_get_user_last_activity', $activity, $user_id );
     991}
     992
     993/**
     994 * Migrate last_activity data from the usermeta table to the activity table.
     995 *
     996 * Generally, this function is only run when BP is upgraded to 2.0. It can also
     997 * be called directly from the BuddyPress Tools panel.
     998 *
     999 * @since BuddyPress (2.0.0)
     1000 */
     1001function bp_last_activity_migrate() {
     1002    global $wpdb;
     1003
     1004    $bp = buddypress();
     1005
     1006    // The "NOT IN" clause prevents duplicates
     1007    $sql = "INSERT INTO {$bp->members->table_name_last_activity} (`user_id`, `component`, `type`, `action`, `content`, `primary_link`, `item_id`, `date_recorded` ) (
     1008          SELECT user_id, '{$bp->members->id}' as component, 'last_activity' as type, '' as action, '' as content, '' as primary_link, 0 as item_id, meta_value AS date_recorded
     1009          FROM {$wpdb->usermeta}
     1010          WHERE
     1011            meta_key = 'last_activity'
     1012            AND
     1013            user_id NOT IN (
     1014              SELECT user_id
     1015              FROM {$bp->members->table_name_last_activity}
     1016              WHERE component = '{$bp->members->id}' AND type = 'last_activity'
     1017            )
     1018    );";
     1019
     1020    return $wpdb->query( $sql );
    9911021}
    9921022
Note: See TracChangeset for help on using the changeset viewer.