Ticket #41819: 41819.3.patch
File 41819.3.patch, 10.5 KB (added by , 7 years ago) |
---|
-
src/wp-includes/class-wp-network-query.php
98 98 * @type int $number Maximum number of networks to retrieve. Default empty (no limit). 99 99 * @type int $offset Number of networks to offset the query. Used to build LIMIT clause. 100 100 * Default 0. 101 * @type int $paged When used with $number, defines the page of results to return. 102 * When used with $offset, $offset takes precedence. 103 * If 0 same as default. Default 1. 101 104 * @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true. 102 105 * @type string|array $orderby Network status or array of statuses. Accepts 'id', 'domain', 'path', 103 106 * 'domain_length', 'path_length' and 'network__in'. Also accepts false, … … 121 124 'fields' => '', 122 125 'number' => '', 123 126 'offset' => '', 127 'paged' => 1, 124 128 'no_found_rows' => true, 125 129 'orderby' => 'id', 126 130 'order' => 'ASC', … … 326 330 327 331 $number = absint( $this->query_vars['number'] ); 328 332 $offset = absint( $this->query_vars['offset'] ); 333 $paged = absint( $this->query_vars['paged'] ); 329 334 330 if ( ! empty( $number ) ) { 331 if ( $offset ) { 332 $limits = 'LIMIT ' . $offset . ',' . $number; 333 } else { 334 $limits = 'LIMIT ' . $number; 335 } 336 } 335 // Limit 336 if ( $number > 0 ) { 337 if ( $offset > 0 ) { 338 $calc_offset = $offset; 339 } elseif( $paged > 0 ) { 340 $calc_offset = $number * ( $paged - 1 ); 341 } else { 342 $calc_offset = 0; 343 } 344 $limits = $wpdb->prepare( "LIMIT %d, %d", $calc_offset, $number ); 345 } 337 346 338 347 if ( $this->query_vars['count'] ) { 339 348 $fields = 'COUNT(*)'; -
src/wp-includes/class-wp-site-query.php
92 92 * 93 93 * @since 4.6.0 94 94 * @since 4.8.0 Introduced the 'lang_id', 'lang__in', and 'lang__not_in' parameters. 95 * @since 4.9.0 Introduced the 'paged' argument. 95 96 * 96 97 * @param string|array $query { 97 98 * Optional. Array or query string of site query parameters. Default empty. … … 108 109 * @type int $number Maximum number of sites to retrieve. Default 100. 109 110 * @type int $offset Number of sites to offset the query. Used to build LIMIT clause. 110 111 * Default 0. 112 * @type int $paged When used with $number, defines the page of results to return. 113 * When used with $offset, $offset takes precedence. 114 * If 0 same as default. Default 1. 111 115 * @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true. 112 116 * @type string|array $orderby Site status or array of statuses. Accepts 'id', 'domain', 'path', 113 117 * 'network_id', 'last_updated', 'registered', 'domain_length', … … 147 151 'site__not_in' => '', 148 152 'number' => 100, 149 153 'offset' => '', 154 'paged' => 1, 150 155 'no_found_rows' => true, 151 156 'orderby' => 'id', 152 157 'order' => 'ASC', … … 370 375 371 376 $number = absint( $this->query_vars['number'] ); 372 377 $offset = absint( $this->query_vars['offset'] ); 378 $paged = absint( $this->query_vars['paged'] ); 379 380 // Limit 381 if ( $number > 0 ) { 382 if ( $offset > 0 ) { 383 $calc_offset = $offset; 384 } elseif( $paged > 0 ) { 385 $calc_offset = $number * ( $paged - 1 ); 386 } else { 387 $calc_offset = 0; 388 } 389 $limits = $wpdb->prepare( "LIMIT %d, %d", $calc_offset, $number ); 390 } 373 391 374 if ( ! empty( $number ) ) {375 if ( $offset ) {376 $limits = 'LIMIT ' . $offset . ',' . $number;377 } else {378 $limits = 'LIMIT ' . $number;379 }380 }381 382 392 if ( $this->query_vars['count'] ) { 383 393 $fields = 'COUNT(*)'; 384 394 } else { -
tests/phpunit/tests/multisite/networkQuery.php
452 452 ) ); 453 453 $this->assertEquals( $number_of_queries + 1, $wpdb->num_queries ); 454 454 } 455 456 /** 457 * @ticket 41819 458 */ 459 public function test_wp_network_query_by_paged() { 460 461 $n1 = get_network_by_path( 'wordpress.org', '/' ); 462 $n2 = get_network_by_path( 'make.wordpress.org', '/' ); 463 $n3 = get_network_by_path( 'www.wordpress.net', '/' ); 464 $n4 = get_network_by_path( 'www.w.org', '/foo/' ); 465 466 $q = new WP_Network_Query(); 467 468 $actual = $q->query( array( 469 'fields' => 'ids', 470 'network__in' => array( $n1->id, $n2->id, $n3->id, $n4->id ), 471 'number' => 2, 472 'paged' => 2, 473 'orderby' => 'network__in', 474 'order' => 'ASC' 475 ) ); 476 477 $expected = array( $n3->id, $n4->id ); 478 479 $this->assertEquals( $actual, $expected ); 480 } 481 482 /** 483 * @ticket 41819 484 */ 485 public function test_wp_network_query_offset_should_take_precedence_over_paged() { 486 487 $n1 = get_network_by_path( 'wordpress.org', '/' ); 488 $n2 = get_network_by_path( 'make.wordpress.org', '/' ); 489 $n3 = get_network_by_path( 'www.wordpress.net', '/' ); 490 $n4 = get_network_by_path( 'www.w.org', '/foo/' ); 491 492 $q = new WP_Network_Query(); 493 494 $actual = $q->query( array( 495 'fields' => 'ids', 496 'network__in' => array( $n1->id, $n2->id, $n3->id, $n4->id ), 497 'number' => 2, 498 'offset' => 1, 499 'paged' => 2, 500 'orderby' => 'network__in', 501 'order' => 'ASC' 502 ) ); 503 504 $expected = array( $n2->id, $n3->id ); 505 506 $this->assertEquals( $actual, $expected ); 507 } 508 509 /** 510 * @ticket 41819 511 */ 512 public function test_wp_network_query_paged_zero_same_as_paged_one() { 513 514 $q0 = new WP_Network_Query(); 515 516 $actual0 = $q0->query( array( 517 'number' => 2, 518 'paged' => 0, 519 ) ); 520 521 $q1 = new WP_Network_Query(); 522 523 $actual1 = $q1->query( array( 524 'number' => 2, 525 'paged' => 1, 526 ) ); 527 528 $this->assertSame( $q0->request, $q1->request ); 529 } 530 455 531 } 456 532 457 533 endif; 534 -
tests/phpunit/tests/multisite/siteQuery.php
737 737 ) ); 738 738 $this->assertEquals( $number_of_queries + 1, $wpdb->num_queries ); 739 739 } 740 741 /** 742 * @ticket 41819 743 */ 744 public function test_wp_site_query_by_paged() { 745 746 $s1 = get_site_by_path( 'www.w.org', '/' ); 747 $s2 = get_site_by_path( 'www.w.org', '/foo/' ); 748 $s3 = get_site_by_path( 'www.w.org', '/foo/bar/' ); 749 $s4 = get_site_by_path( 'www.w.org', '/make/' ); 750 751 $q = new WP_Site_Query(); 752 753 $actual = $q->query( array( 754 'fields' => 'ids', 755 'site__in' => array( $s1->blog_id, $s2->blog_id, $s3->blog_id, $s4->blog_id ), 756 'number' => 2, 757 'paged' => 2, 758 'orderby' => 'site__in', 759 'order' => 'ASC' 760 ) ); 761 762 $expected = array( $s3->blog_id, $s4->blog_id ); 763 764 $this->assertEquals( $actual, $expected ); 765 } 766 767 /** 768 * @ticket 41819 769 */ 770 public function test_wp_site_query_offset_should_take_precedence_over_paged() { 771 772 $s1 = get_site_by_path( 'www.w.org', '/' ); 773 $s2 = get_site_by_path( 'www.w.org', '/foo/' ); 774 $s3 = get_site_by_path( 'www.w.org', '/foo/bar/' ); 775 $s4 = get_site_by_path( 'www.w.org', '/make/' ); 776 777 $q = new WP_Site_Query(); 778 779 $actual = $q->query( array( 780 'fields' => 'ids', 781 'site__in' => array( $s1->blog_id, $s2->blog_id, $s3->blog_id, $s4->blog_id ), 782 'number' => 2, 783 'offset' => 1, 784 'paged' => 2, 785 'orderby' => 'site__in', 786 'order' => 'ASC' 787 ) ); 788 789 $expected = array( $s2->blog_id, $s3->blog_id ); 790 791 $this->assertEquals( $actual, $expected ); 792 } 793 794 /** 795 * @ticket 41819 796 */ 797 public function test_wp_site_query_paged_zero_same_as_paged_one() { 798 799 $q0 = new WP_Site_Query(); 800 801 $actual0 = $q0->query( array( 802 'number' => 2, 803 'paged' => 0, 804 ) ); 805 806 $q1 = new WP_Site_Query(); 807 808 $actual1 = $q1->query( array( 809 'number' => 2, 810 'paged' => 1, 811 ) ); 812 813 $this->assertSame( $q0->request, $q1->request ); 814 } 815 740 816 } 741 817 742 818 endif;