Skip to:
Content

BuddyPress.org


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

Introduce tool on Tools menu for repairing last_activity data

Fixes #5461

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.