Skip to:
Content

BuddyPress.org

Changeset 10277


Ignore:
Timestamp:
10/14/2015 04:37:30 PM (4 years ago)
Author:
r-a-y
Message:

Blogs: Record activity item for blog post if it doesn't exist when a post comment is posted.

Fixes an issue where if "Allow activity stream commenting on blog and forum
posts" is enabled, the activity item for the post comment would not be
created because the activity item for the blog post does not exist.

This might occur if the "Site Tracking" component is enabled after posts
have already been published.

Commit also includes a unit test.

Fixes #6530.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-blogs/bp-blogs-functions.php

    r10248 r10277  
    674674            ) );
    675675
     676            // Try to create a new activity item for the parent blog post
     677            if ( empty( $parent_activity_id ) ) {
     678                $parent_activity_id = bp_activity_post_type_publish( $recorded_comment->comment_post_ID, $recorded_comment->post );
     679            }
     680
    676681            // we found the parent activity entry
    677682            // so let's go ahead and reconfigure some activity args
  • trunk/tests/phpunit/testcases/blogs/functions.php

    r10252 r10277  
    776776    }
    777777
     778    /**
     779     * @group bp_blogs_record_comment
     780     */
     781    public function test_bp_blogs_record_comment_should_record_parent_blog_post_activity_if_not_found() {
     782        // Save the current user and override logged-in user
     783        $old_user = get_current_user_id();
     784        $u = $this->factory->user->create();
     785        $this->set_current_user( $u );
     786
     787        // Get user details
     788        $user = get_userdata( $u );
     789
     790        // Let's use activity comments instead of single "new_blog_comment" activity items
     791        add_filter( 'bp_disable_blogforum_comments', '__return_false' );
     792
     793        // Create the blog post
     794        $post_id = $this->factory->post->create( array(
     795            'post_status' => 'publish',
     796            'post_type'   => 'post',
     797        ) );
     798
     799        // Now, delete the activity item for the blog post
     800        bp_activity_delete( array(
     801            'component'         => buddypress()->blogs->id,
     802            'type'              => 'new_blog_post',
     803            'item_id'           => get_current_blog_id(),
     804            'secondary_item_id' => $post_id,
     805        ) );
     806
     807        // Add a comment to blog post
     808        wp_new_comment( array(
     809            'comment_post_ID' => $post_id,
     810            'user_id' => $u,
     811            'comment_content' => 'Dummy comment',
     812            'comment_author' => 'Dumbo',
     813            'comment_author_url' => 'http://buddypress.org',
     814
     815            // Important to pass check in bp_blogs_record_comment()
     816            'comment_author_email' => $user->user_email
     817        ) );
     818
     819        // Fetch the activity ID for the blog post to see if it exists
     820        $a1 = bp_activity_get_activity_id( array(
     821            'type'      => 'new_blog_post',
     822            'component' => buddypress()->blogs->id,
     823            'filter'    => array(
     824                'item_id' => get_current_blog_id(),
     825                'secondary_item_id' => $post_id
     826            ),
     827        ) );
     828
     829        // Assert that activity item for blog post was created after adding a comment
     830        $this->assertNotNull( $a1, 'Activity item was not created for existing blog post when recording post comment.' );
     831
     832        $this->set_current_user( $old_user );
     833    }
     834
    778835    public function count_activity_comment_saved() {
    779836        $this->activity_saved_comment_count += 1;
Note: See TracChangeset for help on using the changeset viewer.