Skip to:
Content

BuddyPress.org

Changeset 12311


Ignore:
Timestamp:
12/04/2018 03:39:36 PM (8 years ago)
Author:
boonebgorges
Message:

Blogs: Ensure activity data integrity when updating post title.

Previously, a missing primary_id could cause the post_title activity meta
value to be updated for activity items unrelated to the one linked to the
updated blog post.

Props r-a-y.
Fixes #8007.

Location:
trunk
Files:
2 edited

Legend:

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

    r12303 r12311  
    663663                                        'object'       => $activity_post_object->comments_tracking->component_id,
    664664                                        'action'       => $activity_post_object->comments_tracking->action_id,
     665                                        'primary_id'   => get_current_blog_id(),
    665666                                        'secondary_id' => implode( ',', $comment_ids ),
    666667                                );
  • trunk/tests/phpunit/testcases/blogs/activity.php

    r12310 r12311  
    312312
    313313                $this->assertEquals( $this->comment_post_id, $p );
     314        }
     315
     316        /**
     317         * @group post_type_comment_activities
     318         */
     319        public function test_bp_blogs_update_post_title_activity_meta_should_not_be_the_same_for_same_comment_id() {
     320                global $wpdb;
     321
     322                if ( ! is_multisite() ) {
     323                        $this->markTestSkipped();
     324                }
     325
     326                if ( function_exists( 'wp_initialize_site' ) ) {
     327                        $this->setExpectedDeprecated( 'wpmu_new_blog' );
     328                }
     329
     330                $b1 = self::factory()->blog->create();
     331                $b2 = self::factory()->blog->create();
     332                $b3 = self::factory()->blog->create();
     333                $u = self::factory()->user->create();
     334                $u2 = self::factory()->user->create();
     335                $commenter = self::factory()->user->get_object_by_id( $u2 );
     336
     337                $bids = array( $b1, $b2, $b3 );
     338                $pids = array();
     339
     340                foreach ( $bids as $bid ) {
     341                        switch_to_blog( $bid );
     342
     343                        // Ensure blog privacy is public so post activities are recorded.
     344                        update_option( 'blog_public', 1 );
     345
     346                        // Create the post.
     347                        $pids[ $bid ] = self::factory()->post->create( array(
     348                                'post_author' => $u,
     349                        ) );
     350
     351                        /*
     352                         * Create the post comment.
     353                         *
     354                         * Both user_id and comment_author_email are required for unit tests.
     355                         */
     356                        $c = self::factory()->comment->create( array(
     357                                'user_id'         => $u2,
     358                                'comment_author_email' => $commenter->user_email,
     359                                'comment_post_ID' => $pids[ $bid ],
     360                        ) );
     361
     362                        // Approve the comment so the activity item is generated.
     363                        self::factory()->comment->update_object( $c, array( 'comment_approved' => 1 ) );
     364
     365                        restore_current_blog();
     366                }
     367
     368                // Now update the post title on one blog only.
     369                switch_to_blog( $b1 );
     370                wp_update_post( array(
     371                        'ID' => $pids[ $b1 ],
     372                        'post_title' => 'Updated'
     373                ) );
     374                restore_current_blog();
     375
     376                // Check our activity meta to see if the post title is different.
     377                $aids = bp_activity_get( array(
     378                        'fields' => 'ids',
     379                        'filter' => array(
     380                                'action' => 'new_blog_comment'
     381                        )
     382                ) );
     383                $aids= $aids['activities'];
     384                foreach ( $aids as $aid ) {
     385                        // Skip the check for the correct blog.
     386                        $a = new BP_Activity_Activity( $aid );
     387                        if ( $a->item_id == $b1 ) {
     388                                continue;
     389                        }
     390
     391                        // Assert that post title is different.
     392                        $post_title = bp_activity_get_meta( $aid, 'post_title' );
     393                        $this->assertFalse( 'Updated' === $post_title, 'Post title should not be the same across all sites with the same post comment ID' );
     394                }
    314395        }
    315396
Note: See TracChangeset for help on using the changeset viewer.