diff --git a/src/wp-admin/includes/schema.php b/src/wp-admin/includes/schema.php index 8ea0b3680291c..099a35361c639 100644 --- a/src/wp-admin/includes/schema.php +++ b/src/wp-admin/includes/schema.php @@ -52,6 +52,13 @@ function wp_get_db_schema( $scope = 'all', $blog_id = null ) { */ $max_index_length = 191; + /* + * comment_post_ID_parent_content indexes comment_content after two bigint columns. + * Limit the content prefix to floor( ( 767 - 16 - 2 ) / 4 ) = 187 characters, + * keeping the composite key below the 767-byte limit. + */ + $max_comment_content_index_length = 187; + // Blog-specific tables. $blog_tables = "CREATE TABLE $wpdb->termmeta ( meta_id bigint(20) unsigned NOT NULL auto_increment, @@ -116,6 +123,7 @@ function wp_get_db_schema( $scope = 'all', $blog_id = null ) { user_id bigint(20) unsigned NOT NULL default '0', PRIMARY KEY (comment_ID), KEY comment_post_ID (comment_post_ID), + KEY comment_post_ID_parent_content (comment_post_ID,comment_parent,comment_content($max_comment_content_index_length)), KEY comment_approved_date_gmt (comment_approved,comment_date_gmt), KEY comment_date_gmt (comment_date_gmt), KEY comment_parent (comment_parent), diff --git a/src/wp-includes/version.php b/src/wp-includes/version.php index 934e5d0bb5369..364e97f70ce2a 100644 --- a/src/wp-includes/version.php +++ b/src/wp-includes/version.php @@ -23,7 +23,7 @@ * * @global int $wp_db_version */ -$wp_db_version = 61833; +$wp_db_version = 61834; /** * Holds the TinyMCE version. diff --git a/tests/phpunit/tests/comment/wpAllowComment.php b/tests/phpunit/tests/comment/wpAllowComment.php index 8b3de23fc194c..c3aa08c2bd605 100644 --- a/tests/phpunit/tests/comment/wpAllowComment.php +++ b/tests/phpunit/tests/comment/wpAllowComment.php @@ -71,4 +71,41 @@ public function test_die_as_duplicate_if_comment_author_name_and_emails_match() $result = wp_allow_comment( $comment_data ); } + + /** + * @ticket 26858 + */ + public function test_return_error_as_duplicate_if_comment_author_email_is_empty() { + $comment_id = self::factory()->comment->create( + array( + 'comment_post_ID' => self::$post_id, + 'comment_approved' => '1', + 'comment_author' => 'Anonymous Bob', + 'comment_author_email' => '', + 'comment_author_url' => 'http://example.com', + 'comment_content' => 'Still a duplicate.', + ) + ); + + $now = time(); + $comment_data = array( + 'comment_post_ID' => self::$post_id, + 'comment_author' => 'Anonymous Bob', + 'comment_author_email' => '', + 'comment_author_url' => 'http://example.com', + 'comment_content' => 'Still a duplicate.', + 'comment_author_IP' => '192.168.0.1', + 'comment_parent' => 0, + 'comment_date_gmt' => gmdate( 'Y-m-d H:i:s', $now ), + 'comment_agent' => 'Bobbot/2.1', + 'comment_type' => '', + ); + + $result = wp_allow_comment( $comment_data, true ); + + wp_delete_comment( $comment_id, true ); + + $this->assertWPError( $result ); + $this->assertSame( 'comment_duplicate', $result->get_error_code() ); + } }