Make WordPress Core

Ticket #35874: xmlrpc-based-fix-and-test.patch

File xmlrpc-based-fix-and-test.patch, 3.1 KB (added by redsweater, 8 years ago)

A new patch and test addressing the problem from the XMLRPC component.

  • src/wp-includes/class-wp-xmlrpc-server.php

    diff --git src/wp-includes/class-wp-xmlrpc-server.php src/wp-includes/class-wp-xmlrpc-server.php
    index c331591..c21afb6 100644
    class wp_xmlrpc_server extends IXR_Server { 
    53625362                elseif ( !empty( $content_struct['dateCreated']) )
    53635363                        $dateCreated = $content_struct['dateCreated']->getIso();
    53645364
     5365                // We need to pass along a value to wp_update_post for "edit_date", indicating whether
     5366                // an intentional edit is being made to the date. This drives logic that determines
     5367                // whether the value of post_date or post_date_gmt will be disregarded or not for
     5368                // draft posts.
     5369                $edit_date = false;
    53655370                if ( !empty( $dateCreated ) ) {
    53665371                        $post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated));
    53675372                        $post_date_gmt = iso8601_to_datetime($dateCreated, 'GMT');
     5373
     5374                        // If $dateCreated is not empty, it means that a specific date was supplied.
     5375                        $edit_date = true;
    53685376                } else {
    53695377                        $post_date     = $postdata['post_date'];
    53705378                        $post_date_gmt = $postdata['post_date_gmt'];
    53715379                }
    53725380
    53735381                // We've got all the data -- post it.
    5374                 $newpost = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'post_date', 'post_date_gmt', 'to_ping', 'post_name', 'post_password', 'post_parent', 'menu_order', 'post_author', 'tags_input', 'page_template');
     5382                $newpost = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'edit_date', 'post_date', 'post_date_gmt', 'to_ping', 'post_name', 'post_password', 'post_parent', 'menu_order', 'post_author', 'tags_input', 'page_template');
    53755383
    53765384                $result = wp_update_post($newpost, true);
    53775385                if ( is_wp_error( $result ) )
  • tests/phpunit/tests/xmlrpc/mw/editPost.php

    diff --git tests/phpunit/tests/xmlrpc/mw/editPost.php tests/phpunit/tests/xmlrpc/mw/editPost.php
    index a62d239..8c26522 100644
    class Tests_XMLRPC_mw_editPost extends WP_XMLRPC_UnitTestCase { 
    241241                $tags2 = get_the_tags( $post_id );
    242242                $this->assertEmpty( $tags2 );
    243243        }
     244
     245        /**
     246         * @ticket 35874
     247         */
     248        function test_draft_not_prematurely_published() {
     249                $editor_id = $this->make_user_by_role( 'editor' );
     250
     251                $post = array (
     252                        'title' => 'Title'
     253                );
     254
     255                // We have to use mw_newPost method, rather than the factory
     256                // post->create method to create the database conditions that exhibit the bug.
     257                $post_id = $this->myxmlrpcserver->mw_newPost( array( 1, 'editor', 'editor', $post ) );
     258
     259                // Change the post's status to publish and date to future
     260                $future_time = strtotime( '+1 day' );
     261                $future_date = new IXR_Date( $future_time );
     262                $this->myxmlrpcserver->mw_editPost( array( $post_id, 'editor', 'editor', array(
     263                        'dateCreated' => $future_date,
     264                        'post_status' => 'publish'
     265                ) ) );
     266
     267                $after = get_post( $post_id );
     268                $this->assertEquals( 'future', $after->post_status );
     269
     270                $future_date_string = strftime( "%Y-%m-%d %H:%M:%S", $future_time );
     271                $this->assertEquals( $future_date_string, $after->post_date );
     272        }
    244273}