Ticket #5609: 5609.03.patch
| File 5609.03.patch, 9.0 KB (added by , 11 years ago) |
|---|
-
src/bp-blogs/bp-blogs-functions.php
523 523 524 524 $activity_content = $post->post_content; 525 525 526 bp_blogs_record_activity( array(526 $activity_id = bp_blogs_record_activity( array( 527 527 'user_id' => (int) $post->post_author, 528 528 'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, $post, $post_permalink ), 529 529 'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ), … … 531 531 'item_id' => $blog_id, 532 532 'secondary_item_id' => $post_id, 533 533 'recorded_time' => $post->post_date_gmt, 534 )); 534 ) ); 535 536 // save post title in activity meta 537 bp_activity_update_meta( $activity_id, 'post_title', $post->post_title ); 538 bp_activity_update_meta( $activity_id, 'post_url', $post_permalink ); 535 539 } 536 540 537 541 // Update the blogs last activity … … 574 578 $activity->content = $post->post_content; 575 579 $activity->save(); 576 580 581 // update post title in activity meta 582 $existing_title = bp_activity_get_meta( $activity_id, 'post_title' ); 583 if ( $post->post_title !== $existing_title ) { 584 bp_activity_update_meta( $activity_id, 'post_title', $post->post_title ); 585 586 // now update activity meta for post comments... sigh 587 $comments = get_comments( array( 'post_id' => $post->ID ) ); 588 589 if ( ! empty( $comments ) ) { 590 $activity_ids = array(); 591 $comment_ids = wp_list_pluck( $comments, 'comment_ID' ); 592 593 // setup activity args 594 $args = array( 595 'update_meta_cache' => false, 596 'show_hidden' => true, 597 'per_page' => 99999, 598 ); 599 600 // query for old-style "new_blog_comment" activity items 601 $args['filter'] = array( 602 'object' => buddypress()->blogs->id, 603 'action' => 'new_blog_comment', 604 'secondary_id' => implode( ',', $comment_ids ), 605 ); 606 607 $activities = bp_activity_get( $args ); 608 if ( ! empty( $activities['activities'] ) ) { 609 $activity_ids = (array) wp_list_pluck( $activities['activities'], 'id' ); 610 } 611 612 // query for activity comments connected to a blog post 613 unset( $args['filter'] ); 614 $args['meta_query'] = array( array( 615 'key' => 'bp_blogs_post_comment_id', 616 'value' => $comment_ids, 617 'compare' => 'IN', 618 ) ); 619 $args['type'] = 'activity_comment'; 620 $args['display_comments'] = 'stream'; 621 622 $activities = bp_activity_get( $args ); 623 if ( ! empty( $activities['activities'] ) ) { 624 $activity_ids = array_merge( $activity_ids, (array) wp_list_pluck( $activities['activities'], 'id' ) ); 625 } 626 627 // update activity meta for all found activity items 628 if ( ! empty( $activity_ids ) ) { 629 foreach ( $activity_ids as $aid ) { 630 bp_activity_update_meta( $aid, 'post_title', $post->post_title ); 631 } 632 } 633 634 unset( $activities, $activity_ids, $comment_ids, $comments ); 635 } 636 } 637 577 638 // add post comment status to activity meta if closed 578 639 if( 'closed' == $post->comment_status ) { 579 640 bp_activity_update_meta( $activity_id, 'post_comment_status', $post->comment_status ); … … 671 732 $args['secondary_item_id'] = $comment_id; 672 733 673 734 // record the activity entry 674 bp_blogs_record_activity( $args ); 735 $activity_id = bp_blogs_record_activity( $args ); 736 737 // add some post info in activity meta 738 bp_activity_update_meta( $activity_id, 'post_title', $recorded_comment->post->post_title ); 739 bp_activity_update_meta( $activity_id, 'post_url', add_query_arg( 'p', $recorded_comment->post->ID, home_url( '/' ) ) ); 675 740 676 741 // record comment as BP activity comment under the parent 'new_blog_post' 677 742 // activity item … … 735 800 if ( empty( $args['id'] ) ) { 736 801 // add meta to activity comment 737 802 bp_activity_update_meta( $comment_activity_id, 'bp_blogs_post_comment_id', $comment_id ); 803 bp_activity_update_meta( $comment_activity_id, 'post_title', $recorded_comment->post->post_title ); 804 bp_activity_update_meta( $comment_activity_id, 'post_url', add_query_arg( 'p', $recorded_comment->post->ID, home_url( '/' ) ) ); 738 805 739 806 // add meta to comment 740 807 add_comment_meta( $comment_id, 'bp_activity_comment_id', $comment_activity_id ); -
tests/phpunit/testcases/blogs/functions.php
394 394 $this->assertFalse( $this->activity_exists_for_post( $post_id ), 'Unpublished post should not have activity' ); 395 395 } 396 396 397 /** 398 * @group bp_blogs_catch_transition_post_status 399 */ 400 public function test_update_blog_post_and_activity_meta() { 401 $post_id = $this->factory->post->create( array( 402 'post_status' => 'publish', 403 'post_type' => 'post', 404 'post_title' => 'First title', 405 ) ); 406 407 wp_update_post( array( 408 'ID' => $post_id, 409 'post_title' => 'Second title', 410 ) ); 411 412 $activity_id = bp_activity_get_activity_id( array( 413 'component' => buddypress()->blogs->id, 414 'type' => 'new_blog_post', 415 'item_id' => get_current_blog_id(), 416 'secondary_item_id' => $post_id, 417 ) ); 418 419 $this->assertEquals( 'Second title', bp_activity_get_meta( $activity_id, 'post_title' ) ); 420 } 421 422 /** 423 * @group bp_blogs_catch_transition_post_status 424 */ 425 public function test_update_blog_post_and_new_blog_comment_activity_meta() { 426 // save the current user and override logged-in user 427 $old_user = get_current_user_id(); 428 $u = $this->create_user(); 429 $this->set_current_user( $u ); 430 $userdata = get_userdata( $u ); 431 432 // create the blog post 433 $post_id = $this->factory->post->create( array( 434 'post_status' => 'publish', 435 'post_type' => 'post', 436 'post_title' => 'First title', 437 ) ); 438 439 // create the blog comment 440 $comment_id = wp_new_comment( array( 441 'comment_post_ID' => $post_id, 442 'comment_author' => $userdata->user_nicename, 443 'comment_author_url' => 'http://buddypress.org', 444 'comment_author_email' => $userdata->user_email, 445 'comment_content' => 'this is a blog comment', 446 'comment_type' => '', 447 'comment_parent' => 0, 448 'user_id' => $u, 449 ) ); 450 451 // update the initial blog post 452 wp_update_post( array( 453 'ID' => $post_id, 454 'post_title' => 'Second title', 455 ) ); 456 457 // grab the activity ID for the blog comment 458 $activity_id = bp_activity_get_activity_id( array( 459 'component' => buddypress()->blogs->id, 460 'type' => 'new_blog_comment', 461 'secondary_item_id' => $comment_id, 462 ) ); 463 464 // see if blog comment activity meta matches the post items 465 $this->assertEquals( 'Second title', bp_activity_get_meta( $activity_id, 'post_title' ) ); 466 $this->assertEquals( add_query_arg( 'p', $post_id, home_url( '/' ) ), bp_activity_get_meta( $activity_id, 'post_url' ) ); 467 468 // reset 469 $this->set_current_user( $old_user ); 470 } 471 472 /** 473 * @group bp_blogs_catch_transition_post_status 474 */ 475 public function test_update_blog_post_and_activity_comment_meta() { 476 // save the current user and override logged-in user 477 $old_user = get_current_user_id(); 478 $u = $this->create_user(); 479 $this->set_current_user( $u ); 480 $userdata = get_userdata( $u ); 481 482 // create the blog post 483 $post_id = $this->factory->post->create( array( 484 'post_status' => 'publish', 485 'post_type' => 'post', 486 'post_title' => 'First title', 487 ) ); 488 489 // let's use activity comments instead of single "new_blog_comment" activity items 490 add_filter( 'bp_disable_blogforum_comments', '__return_false' ); 491 492 // create the blog comment 493 $comment_id = wp_new_comment( array( 494 'comment_post_ID' => $post_id, 495 'comment_author' => $userdata->user_nicename, 496 'comment_author_url' => 'http://buddypress.org', 497 'comment_author_email' => $userdata->user_email, 498 'comment_content' => 'this is a blog comment', 499 'comment_type' => '', 500 'comment_parent' => 0, 501 'user_id' => $u, 502 ) ); 503 504 // update the initial blog post 505 wp_update_post( array( 506 'ID' => $post_id, 507 'post_title' => 'Second title', 508 ) ); 509 510 // grab the activity ID for the blog comment 511 $activity_id = bp_activity_get_activity_id( array( 512 'type' => 'activity_comment', 513 'display_comments' => 'stream', 514 'meta_query' => array( array( 515 'key' => 'bp_blogs_post_comment_id', 516 'value' => $comment_id, 517 ) ) 518 ) ); 519 520 // see if blog comment activity meta matches the post items 521 $this->assertEquals( 'Second title', bp_activity_get_meta( $activity_id, 'post_title' ) ); 522 $this->assertEquals( add_query_arg( 'p', $post_id, home_url( '/' ) ), bp_activity_get_meta( $activity_id, 'post_url' ) ); 523 524 // reset 525 $this->set_current_user( $old_user ); 526 remove_filter( 'bp_disable_blogforum_comments', '__return_false' ); 527 } 528 397 529 protected function activity_exists_for_post( $post_id ) { 398 530 $a = bp_activity_get( array( 399 531 'component' => buddypress()->blogs->id,