Ticket #41819: 41819.2.patch
File 41819.2.patch, 11.2 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 335 if ( ! $paged ) { 336 $paged = 1; 337 } 338 330 339 if ( ! empty( $number ) ) { 331 340 if ( $offset ) { 332 341 $limits = 'LIMIT ' . $offset . ',' . $number; 333 342 } else { 334 $limits = 'LIMIT' . $number;335 } 343 $limits = 'LIMIT ' . ( $number * absint( $paged - 1 ) ) . ',' . $number; 344 } 336 345 } 337 346 338 347 if ( $this->query_vars['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 if ( ! $paged ) { 381 $paged = 1; 382 } 373 383 374 384 if ( ! empty( $number ) ) { 375 385 if ( $offset ) { 376 386 $limits = 'LIMIT ' . $offset . ',' . $number; 377 378 $limits = 'LIMIT' . $number;379 } 387 } else { 388 $limits = 'LIMIT ' . ( $number * absint( $paged - 1 ) ) . ',' . $number; 389 } 380 390 } 381 391 382 392 if ( $this->query_vars['count'] ) { -
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 $n1 = get_network_by_path( 'wordpress.org', '/' ); 515 $n2 = get_network_by_path( 'make.wordpress.org', '/' ); 516 $n3 = get_network_by_path( 'www.wordpress.net', '/' ); 517 $n4 = get_network_by_path( 'www.w.org', '/foo/' ); 518 519 $q0 = new WP_Network_Query(); 520 521 $actual0 = $q0->query( array( 522 'fields' => 'ids', 523 'network__in' => array( $n1->id, $n2->id, $n3->id, $n4->id ), 524 'number' => 2, 525 'paged' => 0, 526 'orderby' => 'network__in', 527 'order' => 'ASC' 528 ) ); 529 530 $q1 = new WP_Network_Query(); 531 532 $actual1 = $q1->query( array( 533 'fields' => 'ids', 534 'network__in' => array( $n1->id, $n2->id, $n3->id, $n4->id ), 535 'number' => 2, 536 'paged' => 1, 537 'orderby' => 'network__in', 538 'order' => 'ASC' 539 ) ); 540 541 $this->assertSame( $q0->request, $q1->request ); 542 } 543 455 544 } 456 545 457 546 endif; 547 -
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 /** 796 * @ticket 41819 797 */ 798 public function test_wp_site_query_paged_zero_same_as_paged_one() { 799 800 $s1 = get_site_by_path( 'www.w.org', '/' ); 801 $s2 = get_site_by_path( 'www.w.org', '/foo/' ); 802 $s3 = get_site_by_path( 'www.w.org', '/foo/bar/' ); 803 $s4 = get_site_by_path( 'www.w.org', '/make/' ); 804 805 $q0 = new WP_Site_Query(); 806 807 $actual0 = $q0->query( array( 808 'fields' => 'ids', 809 'site__in' => array( $s1->blog_id, $s2->blog_id, $s3->blog_id, $s4->blog_id ), 810 'number' => 2, 811 'paged' => 0, 812 'orderby' => 'site__in', 813 'order' => 'ASC' 814 ) ); 815 816 $q1 = new WP_Site_Query(); 817 818 $actual1 = $q1->query( array( 819 'fields' => 'ids', 820 'site__in' => array( $s1->blog_id, $s2->blog_id, $s3->blog_id, $s4->blog_id ), 821 'number' => 2, 822 'paged' => 1, 823 'orderby' => 'site__in', 824 'order' => 'ASC' 825 ) ); 826 827 $this->assertSame( $q0->request, $q1->request ); 828 829 } 830 831 740 832 } 741 833 742 834 endif;