Changeset 8333
- Timestamp:
- 04/30/2014 07:22:59 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-members/bp-members-functions.php
r8324 r8333 1037 1037 $bp = buddypress(); 1038 1038 1039 // The "NOT IN" clause prevents duplicates 1039 // Wipe out existing last_activity data in the activity table - 1040 // this helps to prevent duplicates when pulling from the usermeta 1041 // table 1042 $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->members->table_name_last_activity} WHERE component = %s AND type = 'last_activity'", $bp->members->id ) ); 1043 1040 1044 $sql = "INSERT INTO {$bp->members->table_name_last_activity} (`user_id`, `component`, `type`, `action`, `content`, `primary_link`, `item_id`, `date_recorded` ) ( 1041 1045 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 … … 1043 1047 WHERE 1044 1048 meta_key = 'last_activity' 1045 AND1046 user_id NOT IN (1047 SELECT user_id1048 FROM {$bp->members->table_name_last_activity}1049 WHERE component = '{$bp->members->id}' AND type = 'last_activity'1050 )1051 1049 );"; 1052 1050 -
trunk/tests/testcases/members/functions.php
r8330 r8333 354 354 $this->assertSame( $u_obj->user_email, $found_email ); 355 355 } 356 357 /** 358 * @group bp_last_activity_migrate 359 * @expectedIncorrectUsage update_user_meta( $user_id, 'last_activity' ) 360 * @expectedIncorrectUsage get_user_meta( $user_id, 'last_activity' ) 361 */ 362 public function test_bp_last_activity_migrate() { 363 // We explicitly do not want last_activity created, so use the 364 // WP factory methods 365 $u1 = $this->factory->user->create(); 366 $u2 = $this->factory->user->create(); 367 $u3 = $this->factory->user->create(); 368 369 $time = time(); 370 $t1 = date( 'Y-m-d H:i:s', $time - 50 ); 371 $t2 = date( 'Y-m-d H:i:s', $time - 500 ); 372 $t3 = date( 'Y-m-d H:i:s', $time - 5000 ); 373 374 update_user_meta( $u1, 'last_activity', $t1 ); 375 update_user_meta( $u2, 'last_activity', $t2 ); 376 update_user_meta( $u3, 'last_activity', $t3 ); 377 378 // Create an existing entry in last_activity to test no dupes 379 global $wpdb, $bp; 380 $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->members->table_name_last_activity} (`user_id`, `component`, `type`, `action`, `content`, `primary_link`, `item_id`, `date_recorded` ) VALUES ( %d, %s, %s, %s, %s, %s, %d, %s )", $u2, $bp->members->id, 'last_activity', '', '', 0, $t1 ) ); 381 382 bp_last_activity_migrate(); 383 384 $expected = array( 385 $u1 => $t1, 386 $u2 => $t2, 387 $u3 => $t3, 388 ); 389 390 $found = array( 391 $u1 => '', 392 $u2 => '', 393 $u3 => '', 394 ); 395 396 foreach ( $found as $uid => $v ) { 397 $found[ $uid ] = bp_get_user_last_activity( $uid ); 398 } 399 400 $this->assertSame( $expected, $found ); 401 } 356 402 }
Note: See TracChangeset
for help on using the changeset viewer.