From 7b7656950e9034ec645e4fdb1cb8a27d05174801 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Sun, 3 Jan 2016 19:49:34 +0000 Subject: [PATCH] XML-RPC: Revert [34681] as it broke date handling. Merges [36163] to the 4.4 branch. props dossy, hnle, redsweater. see #35053, #30429 (original ticket). git-svn-id: https://develop.svn.wordpress.org/branches/4.4@36164 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-xmlrpc-server.php | 16 +++++----- tests/phpunit/tests/xmlrpc/mw/editPost.php | 26 --------------- tests/phpunit/tests/xmlrpc/mw/newPost.php | 23 ------------- tests/phpunit/tests/xmlrpc/wp/editComment.php | 32 ------------------- tests/phpunit/tests/xmlrpc/wp/newPost.php | 18 ----------- 5 files changed, 8 insertions(+), 107 deletions(-) diff --git a/src/wp-includes/class-wp-xmlrpc-server.php b/src/wp-includes/class-wp-xmlrpc-server.php index 08897dc032..5be4dc9b45 100644 --- a/src/wp-includes/class-wp-xmlrpc-server.php +++ b/src/wp-includes/class-wp-xmlrpc-server.php @@ -1349,8 +1349,8 @@ class wp_xmlrpc_server extends IXR_Server { } if ( ! empty( $dateCreated ) ) { - $post_data['post_date'] = iso8601_to_datetime( $dateCreated ); - $post_data['post_date_gmt'] = get_gmt_from_date( $post_data['post_date'] ); + $post_data['post_date'] = get_date_from_gmt( iso8601_to_datetime( $dateCreated ) ); + $post_data['post_date_gmt'] = iso8601_to_datetime( $dateCreated, 'GMT' ); } if ( ! isset( $post_data['ID'] ) ) @@ -3423,8 +3423,8 @@ class wp_xmlrpc_server extends IXR_Server { if ( !empty( $content_struct['date_created_gmt'] ) ) { // We know this is supposed to be GMT, so we're going to slap that Z on there by force $dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z'; - $comment_date = iso8601_to_datetime( $dateCreated ); - $comment_date_gmt = get_gmt_from_date( $comment_date ); + $comment_date = get_date_from_gmt(iso8601_to_datetime($dateCreated)); + $comment_date_gmt = iso8601_to_datetime($dateCreated, 'GMT'); } if ( isset($content_struct['content']) ) @@ -4991,8 +4991,8 @@ class wp_xmlrpc_server extends IXR_Server { $dateCreated = $content_struct['dateCreated']->getIso(); if ( !empty( $dateCreated ) ) { - $post_date = iso8601_to_datetime( $dateCreated ); - $post_date_gmt = get_gmt_from_date( $post_date ); + $post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated)); + $post_date_gmt = iso8601_to_datetime($dateCreated, 'GMT'); } else { $post_date = ''; $post_date_gmt = ''; @@ -5345,8 +5345,8 @@ class wp_xmlrpc_server extends IXR_Server { $dateCreated = $content_struct['dateCreated']->getIso(); if ( !empty( $dateCreated ) ) { - $post_date = iso8601_to_datetime( $dateCreated ); - $post_date_gmt = get_gmt_from_date( $post_date, 'GMT' ); + $post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated)); + $post_date_gmt = iso8601_to_datetime($dateCreated, 'GMT'); } else { $post_date = $postdata['post_date']; $post_date_gmt = $postdata['post_date_gmt']; diff --git a/tests/phpunit/tests/xmlrpc/mw/editPost.php b/tests/phpunit/tests/xmlrpc/mw/editPost.php index fbdf20e061..a62d239baa 100644 --- a/tests/phpunit/tests/xmlrpc/mw/editPost.php +++ b/tests/phpunit/tests/xmlrpc/mw/editPost.php @@ -219,32 +219,6 @@ class Tests_XMLRPC_mw_editPost extends WP_XMLRPC_UnitTestCase { $this->assertEquals( $result->code, 401 ); } - /** - * @ticket 30429 - */ - function test_post_date_timezone_conversion() { - $tz = get_option( 'timezone_string' ); - update_option( 'timezone_string', 'America/New_York' ); - - $editor_id = $this->make_user_by_role( 'editor' ); - - $post_id = self::factory()->post->create( array( - 'post_author' => $editor_id - ) ); - - $date_string = '1984-01-11 05:00:00'; - $result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'editor', 'editor', array( - 'dateCreated' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date_string, false ) ), - ) ) ); - - $fetched_post = get_post( $post_id ); - - update_option( 'timezone_string', $tz ); - - $this->assertTrue( $result ); - $this->assertEquals( $date_string, $fetched_post->post_date ); - } - /** * @ticket 16980 */ diff --git a/tests/phpunit/tests/xmlrpc/mw/newPost.php b/tests/phpunit/tests/xmlrpc/mw/newPost.php index c849f65708..01316e62d5 100644 --- a/tests/phpunit/tests/xmlrpc/mw/newPost.php +++ b/tests/phpunit/tests/xmlrpc/mw/newPost.php @@ -170,27 +170,4 @@ class Tests_XMLRPC_mw_newPost extends WP_XMLRPC_UnitTestCase { $this->assertEquals( 'draft', $out->post_status ); $this->assertEquals( '0000-00-00 00:00:00', $out->post_date_gmt ); } - - /** - * @ticket 30429 - */ - function test_post_date_timezone_conversion() { - $tz = get_option( 'timezone_string' ); - update_option( 'timezone_string', 'America/New_York' ); - - $this->make_user_by_role( 'editor' ); - $date_string = '1984-01-11 05:00:00'; - $post = array( - 'title' => 'test', - 'post_content' => 'test', - 'dateCreated' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date_string, false ) ) - ); - $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'editor', 'editor', $post ) ); - $fetched_post = get_post( $result ); - - update_option( 'timezone_string', $tz ); - - $this->assertStringMatchesFormat( '%d', $result ); - $this->assertEquals( $date_string , $fetched_post->post_date ); - } } diff --git a/tests/phpunit/tests/xmlrpc/wp/editComment.php b/tests/phpunit/tests/xmlrpc/wp/editComment.php index c8859576b4..055b30ec04 100644 --- a/tests/phpunit/tests/xmlrpc/wp/editComment.php +++ b/tests/phpunit/tests/xmlrpc/wp/editComment.php @@ -69,36 +69,4 @@ class Tests_XMLRPC_wp_editComment extends WP_XMLRPC_UnitTestCase { $this->assertEquals( 'trash', get_comment( $comment_id )->comment_approved ); } - - /** - * @ticket 30429 - */ - function test_post_date_timezone_conversion() { - $tz = get_option( 'timezone_string' ); - update_option( 'timezone_string', 'America/New_York' ); - - $this->make_user_by_role( 'administrator' ); - $post_id = self::factory()->post->create(); - - $comment_data = array( - 'comment_post_ID' => $post_id, - 'comment_author' => 'Test commenter', - 'comment_author_url' => 'http://example.com/', - 'comment_author_email' => 'example@example.com', - 'comment_content' => rand_str( 100 ), - 'comment_approved' => '1', - ); - $comment_id = wp_insert_comment( $comment_data ); - - $date_string = '1984-01-11 05:00:00'; - $result = $this->myxmlrpcserver->wp_editComment( array( 1, 'administrator', 'administrator', $comment_id, array( - 'date_created_gmt' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date_string, false ) ) - ) ) ); - $fetched_comment = get_comment( $comment_id ); - - update_option( 'timezone_string', $tz ); - - $this->assertTrue( $result ); - $this->assertEquals( $date_string, $fetched_comment->comment_date ); - } } \ No newline at end of file diff --git a/tests/phpunit/tests/xmlrpc/wp/newPost.php b/tests/phpunit/tests/xmlrpc/wp/newPost.php index 3f9343f495..a8dae54e6e 100644 --- a/tests/phpunit/tests/xmlrpc/wp/newPost.php +++ b/tests/phpunit/tests/xmlrpc/wp/newPost.php @@ -373,22 +373,4 @@ class Tests_XMLRPC_wp_newPost extends WP_XMLRPC_UnitTestCase { $this->assertEquals( $date_string , $fetched_post->post_date_gmt ); } - /** - * @ticket 30429 - */ - function test_post_date_timezone_conversion() { - $tz = get_option( 'timezone_string' ); - update_option( 'timezone_string', 'America/New_York' ); - - $this->make_user_by_role( 'author' ); - $date_string = '1984-01-11 05:00:00'; - $post = array( 'post_title' => 'test', 'post_content' => 'test', 'post_date' => $date_string ); - $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) ); - $fetched_post = get_post( $result ); - - update_option( 'timezone_string', $tz ); - - $this->assertStringMatchesFormat( '%d', $result ); - $this->assertEquals( $date_string , $fetched_post->post_date ); - } }