Ticket #28434: 28434.diff
File 28434.diff, 2.7 KB (added by , 11 years ago) |
---|
-
src/wp-includes/comment.php
245 245 246 246 $defaults = array( 247 247 'author_email' => '', 248 'fields' => '', 248 249 'ID' => '', 249 250 'karma' => '', 250 251 'number' => '', … … 368 369 if ( $this->query_vars['count'] ) { 369 370 $fields = 'COUNT(*)'; 370 371 } else { 371 $fields = '*'; 372 switch ( strtolower( $this->query_vars['fields'] ) ) { 373 case 'ids': 374 $fields = "$wpdb->comments.comment_ID"; 375 break; 376 case 'id=>parent': 377 $fields = "$wpdb->comments.comment_ID, $wpdb->comments.comment_post_ID"; 378 break; 379 default: 380 $fields = "*"; 381 break; 382 } 372 383 } 384 373 385 $join = ''; 374 386 $where = $approved; 375 387 … … 460 472 if ( $this->query_vars['count'] ) { 461 473 return $wpdb->get_var( $query ); 462 474 } 475 476 if ( 'ids' == $this->query_vars['fields'] ) { 477 $this->comments = $wpdb->get_col( $query ); 478 return array_map( 'intval', $this->comments ); 479 } 480 481 if ( 'id=>parent' == $this->query_vars['fields'] ) { 482 $this->comments = $wpdb->get_results( $query ); 483 484 $r = array(); 485 foreach ( $this->comments as $comments ) { 486 $r[ (int) $comments->comment_ID ] = (int) $comments->comment_post_ID; 487 } 488 return $r; 489 } 490 491 463 492 $results = $wpdb->get_results( $query ); 464 493 /** 465 494 * Filter the comment query results. -
tests/phpunit/tests/comment/query.php
180 180 $this->assertEquals( $users[1], $comments[2]->user_id ); 181 181 182 182 } 183 184 /** 185 * @ticket 28434 186 */ 187 function test_fields_query() { 188 189 $comment_id1 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'user_id' => 7, 'comment_approved' => '1' ) ); 190 $comment_id2 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'user_id' => 1, 'comment_approved' => '1' ) ); 191 $comment_id3 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'user_id' => 1, 'comment_approved' => '1' ) ); 192 193 $comments1 = get_comments( array( 'fields' => 'ids' ) ); 194 $this->assertEquals( 3, count( $comments1 ) ); 195 $this->assertEquals( array( 196 $comment_id1, 197 $comment_id2, 198 $comment_id3 199 ), $comments1 ); 200 201 $comments2 = get_comments( array( 'fields' => 'id=>parent' ) ); 202 $this->assertEquals( 3, count( $comments2 ) ); 203 $this->assertEquals( array( 204 $comment_id1 => $this->post_id, 205 $comment_id2 => $this->post_id, 206 $comment_id3 => $this->post_id 207 ), $comments2 ); 208 } 183 209 }