bp_last_activity_migrate

Migrate last_activity data from the usermeta table to the activity table.

Description

bp_last_activity_migrate(); 

Generally, this function is only run when BP is upgraded to 2.0. It can also be called directly from the BuddyPress Tools panel.


Usage

  1. if ( !function_exists( 'bp_last_activity_migrate' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-members/bp-members-functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bp_last_activity_migrate(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/bp-members/bp-members-functions.php  
  1. function bp_last_activity_migrate() { 
  2. global $wpdb; 
  3.  
  4. $bp =buddypress); 
  5.  
  6. // Wipe out existing last_activity data in the activity table - 
  7. // this helps to prevent duplicates when pulling from the usermeta 
  8. // table. 
  9. $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->members->table_name_last_activity} WHERE component = %s AND type = 'last_activity'", $bp->members->id ) ); 
  10.  
  11. $sql = "INSERT INTO {$bp->members->table_name_last_activity} (`user_id`, `component`, `type`, `action`, `content`, `primary_link`, `item_id`, `date_recorded` ) ( 
  12. 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 
  13. FROM {$wpdb->usermeta} 
  14. WHERE 
  15. meta_key = 'last_activity' 
  16. );"; 
  17.  
  18. return $wpdb->query( $sql );