Make WordPress Core

Ticket #35053: 35053.patch

File 35053.patch, 4.7 KB (added by hnle, 9 years ago)
  • src/wp-includes/class-wp-xmlrpc-server.php

     
    49844984                }
    49854985
    49864986                // Do some timestamp voodoo
    4987                 if ( !empty( $content_struct['date_created_gmt'] ) )
     4987                if ( !empty( $content_struct['date_created_gmt'] ) ) {
    49884988                        // We know this is supposed to be GMT, so we're going to slap that Z on there by force
    4989                         $dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z';
    4990                 elseif ( !empty( $content_struct['dateCreated']) )
    4991                         $dateCreated = $content_struct['dateCreated']->getIso();
     4989                        $dateCreated = iso8601_to_datetime( rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z' );
     4990                        $dateCreated = get_date_from_gmt( $dateCreated );
     4991                } elseif ( !empty( $content_struct['dateCreated']) ) {
     4992                        $dateCreated = iso8601_to_datetime( $content_struct['dateCreated']->getIso() );
     4993                }
    49924994
    49934995                if ( !empty( $dateCreated ) ) {
    4994                         $post_date = iso8601_to_datetime( $dateCreated );
     4996                        $post_date = $dateCreated;
    49954997                        $post_date_gmt = get_gmt_from_date( $post_date );
    49964998                } else {
    49974999                        $post_date = '';
     
    53375339                                $to_ping = implode(' ', $to_ping);
    53385340                }
    53395341
    5340                 // Do some timestamp voodoo.
    5341                 if ( !empty( $content_struct['date_created_gmt'] ) )
    5342                         // We know this is supposed to be GMT, so we're going to slap that Z on there by force.
    5343                         $dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z';
    5344                 elseif ( !empty( $content_struct['dateCreated']) )
    5345                         $dateCreated = $content_struct['dateCreated']->getIso();
     5342                // Do some timestamp voodoo
     5343                if ( !empty( $content_struct['date_created_gmt'] ) ) {
     5344                        // We know this is supposed to be GMT, so we're going to slap that Z on there by force
     5345                        $dateCreated = iso8601_to_datetime( rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z' );
     5346                        $dateCreated = get_date_from_gmt( $dateCreated );
     5347                } elseif ( !empty( $content_struct['dateCreated']) ) {
     5348                        $dateCreated = iso8601_to_datetime( $content_struct['dateCreated']->getIso() );
     5349                }
    53465350
    53475351                if ( !empty( $dateCreated ) ) {
    5348                         $post_date = iso8601_to_datetime( $dateCreated );
     5352                        $post_date = $dateCreated;
    53495353                        $post_date_gmt = get_gmt_from_date( $post_date, 'GMT' );
    53505354                } else {
    53515355                        $post_date     = $postdata['post_date'];
  • tests/phpunit/tests/xmlrpc/mw/editPost.php

     
    246246        }
    247247
    248248        /**
     249         * @ticket
     250         */
     251        function test_post_date_gmt_timezone_conversion() {
     252                $tz = get_option( 'timezone_string' );
     253                update_option( 'timezone_string', 'America/New_York' );
     254
     255                $editor_id = $this->make_user_by_role( 'editor' );
     256
     257                $post_id = self::factory()->post->create( array(
     258                        'post_author' => $editor_id
     259                ) );
     260
     261                $date_string = '1984-01-11 05:00:00';
     262                // America/New_York's time zone is -5:00 so add 5 hours
     263                $date_string_gmt = '1984-01-11 10:00:00';
     264
     265                $result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'editor', 'editor', array(
     266                        'date_created_gmt' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date_string_gmt, false ) ),
     267                ) ) );
     268
     269                $fetched_post = get_post( $post_id );
     270
     271                update_option( 'timezone_string', $tz );
     272
     273                $this->assertTrue( $result );
     274                $this->assertEquals( $date_string, $fetched_post->post_date );
     275        }
     276
     277        /**
    249278         * @ticket 16980
    250279         */
    251280        function test_empty_not_null() {
  • tests/phpunit/tests/xmlrpc/mw/newPost.php

     
    193193                $this->assertStringMatchesFormat( '%d', $result );
    194194                $this->assertEquals( $date_string , $fetched_post->post_date );
    195195        }
     196       
     197        /**
     198         * @ticket
     199         */
     200        function test_post_date_gmt_timezone_conversion() {
     201                $tz = get_option( 'timezone_string' );
     202                update_option( 'timezone_string', 'America/New_York' );
     203
     204                $this->make_user_by_role( 'editor' );
     205                $date_string = '1984-01-11 05:00:00';
     206                // America/New_York's time zone is -5:00 so add 5 hours
     207                $date_string_gmt = '1984-01-11 10:00:00';
     208                $post = array(
     209                        'title' => 'test',
     210                        'post_content' => 'test',
     211                        'date_created_gmt' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date_string_gmt, false ) )
     212                );
     213                $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'editor', 'editor', $post ) );
     214                $fetched_post = get_post( $result );
     215
     216                update_option( 'timezone_string', $tz );
     217
     218                $this->assertStringMatchesFormat( '%d', $result );
     219                $this->assertEquals( $date_string , $fetched_post->post_date );
     220        }
     221
    196222}