Changeset 11095
- Timestamp:
- 09/13/2016 06:21:10 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/admin/bp-core-admin-schema.php
r11093 r11095 203 203 description longtext NOT NULL, 204 204 status varchar(10) NOT NULL DEFAULT 'public', 205 parent_id bigint(20) NOT NULL DEFAULT 0, 205 206 enable_forum tinyint(1) NOT NULL DEFAULT '1', 206 207 date_created datetime NOT NULL, 207 208 KEY creator_id (creator_id), 208 KEY status (status) 209 KEY status (status), 210 KEY parent_id (parent_id) 209 211 ) {$charset_collate};"; 210 212 -
trunk/src/bp-core/bp-core-update.php
r11085 r11095 519 519 // Update post_titles 520 520 bp_migrate_directory_page_titles(); 521 522 /* 523 * Add `parent_id` column to groups table. 524 * Also handled by `bp_core_install()`. 525 */ 526 if ( bp_is_active( 'groups' ) ) { 527 bp_core_install_groups(); 528 529 // Invalidate all cached group objects. 530 global $wpdb; 531 $bp = buddypress(); 532 533 $group_ids = $wpdb->get_col( "SELECT id FROM {$bp->groups->table_name}" ); 534 535 foreach ( $group_ids as $group_id ) { 536 wp_cache_delete( $group_id, 'bp_groups' ); 537 } 538 } 521 539 } 522 540 -
trunk/src/bp-groups/bp-groups-actions.php
r11091 r11095 567 567 } 568 568 add_action( 'bp_actions', 'groups_action_group_feed' ); 569 570 /** 571 * Update orphaned child groups when the parent is deleted. 572 * 573 * @since 2.7.0 574 * 575 * @param BP_Groups_Group $group Instance of the group item being deleted. 576 */ 577 function bp_groups_update_orphaned_groups_on_group_delete( $group ) { 578 // Get child groups and set the parent to the deleted parent's parent. 579 $grandparent_group_id = $group->parent_id; 580 $child_args = array( 581 'parent_id' => $group->id, 582 'show_hidden' => true, 583 'per_page' => false, 584 'update_meta_cache' => false, 585 ); 586 $children = groups_get_groups( $child_args ); 587 $children = $children['groups']; 588 589 foreach ( $children as $cgroup ) { 590 $cgroup->parent_id = $grandparent_group_id; 591 $cgroup->save(); 592 } 593 } 594 add_action( 'bp_groups_delete_group', 'bp_groups_update_orphaned_groups_on_group_delete', 10, 2 ); -
trunk/src/bp-groups/bp-groups-functions.php
r11091 r11095 78 78 * @type string $status The group's status. Accepts 'public', 'private' or 79 79 * 'hidden'. Defaults to 'public'. 80 * @type int $parent_id The ID of the parent group. Default: 0. 80 81 * @type int $enable_forum Optional. Whether the group has a forum enabled. 81 82 * If the legacy forums are enabled for this group … … 96 97 'slug' => '', 97 98 'status' => 'public', 99 'parent_id' => 0, 98 100 'enable_forum' => 0, 99 101 'date_created' => bp_core_current_time() … … 142 144 $group->slug = $slug; 143 145 $group->status = $status; 146 $group->parent_id = $parent_id; 144 147 $group->enable_forum = (int) $enable_forum; 145 148 $group->date_created = $date_created; … … 261 264 * @return bool True on success, false on failure. 262 265 */ 263 function groups_edit_group_settings( $group_id, $enable_forum, $status, $invite_status = false ) {266 function groups_edit_group_settings( $group_id, $enable_forum, $status, $invite_status = false, $parent_id = false ) { 264 267 265 268 $group = groups_get_group( $group_id ); … … 275 278 // Now update the status. 276 279 $group->status = $status; 280 281 // Update the parent ID if necessary. 282 if ( false !== $parent_id ) { 283 $group->parent_id = $parent_id; 284 } 277 285 278 286 if ( !$group->save() ) … … 675 683 * @since 1.2.0 676 684 * @since 2.6.0 Added `$group_type`, `$group_type__in`, and `$group_type__not_in` parameters. 677 * @since 2.7.0 Added `$update_admin_cache` parameter.685 * @since 2.7.0 Added `$update_admin_cache` and `$parent_id` parameters. 678 686 * 679 687 * @param array|string $args { … … 695 703 'include' => false, // Only include these specific groups (group_ids). 696 704 'exclude' => false, // Do not include these specific groups (group_ids). 705 'parent_id' => null, // Get groups that are children of the specified group(s). 697 706 'search_terms' => false, // Limit to groups that match these search terms. 698 707 'group_type' => '', … … 715 724 'include' => $r['include'], 716 725 'exclude' => $r['exclude'], 726 'parent_id' => $r['parent_id'], 717 727 'search_terms' => $r['search_terms'], 718 728 'group_type' => $r['group_type'], -
trunk/src/bp-groups/bp-groups-template.php
r11091 r11095 139 139 * @type array|string $exclude Array or comma-separated list of group IDs. Results will exclude 140 140 * the listed groups. Default: false. 141 * @type array|string $parent_id Array or comma-separated list of group IDs. Results will include only 142 * child groups of the listed groups. Default: null. 141 143 * @type bool $update_meta_cache Whether to fetch groupmeta for queried groups. Default: true. 142 144 * @type bool $update_admin_cache Whether to pre-fetch group admins for queried groups. … … 203 205 'include' => false, 204 206 'exclude' => false, 207 'parent_id' => null, 205 208 'populate_extras' => true, 206 209 'update_meta_cache' => true, … … 227 230 'include' => $r['include'], 228 231 'exclude' => $r['exclude'], 232 'parent_id' => $r['parent_id'], 229 233 'populate_extras' => (bool) $r['populate_extras'], 230 234 'update_meta_cache' => (bool) $r['update_meta_cache'], -
trunk/src/bp-groups/classes/class-bp-groups-group.php
r11089 r11095 69 69 70 70 /** 71 * Parent ID. 72 * 73 * ID of parent group, if applicable. 74 * 75 * @since 2.7.0 76 * @var int 77 */ 78 public $parent_id; 79 80 /** 71 81 * Should (legacy) bbPress forums be enabled for this group? 72 82 * … … 209 219 $this->description = stripslashes( $group->description ); 210 220 $this->status = $group->status; 221 $this->parent_id = (int) $group->parent_id; 211 222 $this->enable_forum = (int) $group->enable_forum; 212 223 $this->date_created = $group->date_created; … … 230 241 $this->description = apply_filters( 'groups_group_description_before_save', $this->description, $this->id ); 231 242 $this->status = apply_filters( 'groups_group_status_before_save', $this->status, $this->id ); 243 $this->parent_id = apply_filters( 'groups_group_parent_id_before_save', $this->parent_id, $this->id ); 232 244 $this->enable_forum = apply_filters( 'groups_group_enable_forum_before_save', $this->enable_forum, $this->id ); 233 245 $this->date_created = apply_filters( 'groups_group_date_created_before_save', $this->date_created, $this->id ); … … 272 284 description = %s, 273 285 status = %s, 286 parent_id = %d, 274 287 enable_forum = %d, 275 288 date_created = %s … … 282 295 $this->description, 283 296 $this->status, 297 $this->parent_id, 284 298 $this->enable_forum, 285 299 $this->date_created, … … 294 308 description, 295 309 status, 310 parent_id, 296 311 enable_forum, 297 312 date_created 298 313 ) VALUES ( 299 %d, %s, %s, %s, %s, %d, % s314 %d, %s, %s, %s, %s, %d, %d, %s 300 315 )", 301 316 $this->creator_id, … … 304 319 $this->description, 305 320 $this->status, 321 $this->parent_id, 306 322 $this->enable_forum, 307 323 $this->date_created … … 837 853 * @since 1.6.0 838 854 * @since 2.6.0 Added `$group_type`, `$group_type__in`, and `$group_type__not_in` parameters. 839 * @since 2.7.0 Added `$update_admin_cache` parameter.855 * @since 2.7.0 Added `$update_admin_cache` and `$parent_id` parameters. 840 856 * 841 857 * @param array $args { … … 864 880 * @type array|string $value Optional. Array or comma-separated list of group IDs. Results 865 881 * will be limited to groups within the list. Default: false. 882 * @type array|string $parent_id Optional. Array or comma-separated list of group IDs. Results 883 * will be limited to children of the specified groups. Default: null. 866 884 * @type bool $populate_extras Whether to fetch additional information 867 885 * (such as member count) about groups. Default: true. … … 917 935 'meta_query' => false, 918 936 'include' => false, 937 'parent_id' => null, 919 938 'populate_extras' => true, 920 939 'update_meta_cache' => true, … … 986 1005 $include = implode( ',', wp_parse_id_list( $r['include'] ) ); 987 1006 $where_conditions['include'] = "g.id IN ({$include})"; 1007 } 1008 1009 if ( ! is_null( $r['parent_id'] ) ) { 1010 // Note that `wp_parse_id_list()` converts `false` to 0. 1011 $parent_id = implode( ',', wp_parse_id_list( $r['parent_id'] ) ); 1012 $where_conditions['parent_id'] = "g.parent_id IN ({$parent_id})"; 988 1013 } 989 1014 -
trunk/src/bp-groups/classes/class-bp-groups-template.php
r11091 r11095 166 166 'include' => false, 167 167 'exclude' => false, 168 'parent_id' => null, 168 169 'search_terms' => '', 169 170 'group_type' => '', … … 225 226 'include' => $include, 226 227 'exclude' => $exclude, 228 'parent_id' => $parent_id, 227 229 'populate_extras' => $populate_extras, 228 230 'update_meta_cache' => $update_meta_cache, -
trunk/tests/phpunit/testcases/groups/class-bp-groups-group.php
r11091 r11095 1706 1706 $this->assertEmpty( $groups['groups'] ); 1707 1707 } 1708 1709 /** 1710 * @group hierarchical_groups 1711 */ 1712 public function test_get_by_parent_id() { 1713 $g1 = $this->factory->group->create(); 1714 $g2 = $this->factory->group->create( array( 1715 'parent_id' => $g1, 1716 ) ); 1717 $g3 = $this->factory->group->create( array( 1718 'parent_id' => $g2, 1719 ) ); 1720 $g4 = $this->factory->group->create(); 1721 1722 $groups = BP_Groups_Group::get( array( 1723 'parent_id' => $g1, 1724 ) ); 1725 1726 $found = wp_list_pluck( $groups['groups'], 'id' ); 1727 $this->assertEquals( array( $g2 ), $found ); 1728 } 1729 1730 /** 1731 * @group hierarchical_groups 1732 */ 1733 public function test_get_by_parent_id_ignore_grandparent() { 1734 $g1 = $this->factory->group->create(); 1735 $g2 = $this->factory->group->create( array( 1736 'parent_id' => $g1, 1737 ) ); 1738 $g3 = $this->factory->group->create( array( 1739 'parent_id' => $g2, 1740 ) ); 1741 $g4 = $this->factory->group->create(); 1742 1743 $groups = BP_Groups_Group::get( array( 1744 'parent_id' => $g2, 1745 ) ); 1746 1747 $found = wp_list_pluck( $groups['groups'], 'id' ); 1748 $this->assertEquals( array( $g3 ), $found ); 1749 } 1750 1751 /** 1752 * @group hierarchical_groups 1753 */ 1754 public function test_get_by_parent_id_array() { 1755 $g1 = $this->factory->group->create(); 1756 $g2 = $this->factory->group->create( array( 1757 'parent_id' => $g1, 1758 ) ); 1759 $g3 = $this->factory->group->create( array( 1760 'parent_id' => $g2, 1761 ) ); 1762 $g4 = $this->factory->group->create(); 1763 1764 $groups = BP_Groups_Group::get( array( 1765 'parent_id' => array( $g1, $g2 ), 1766 ) ); 1767 1768 $found = wp_list_pluck( $groups['groups'], 'id' ); 1769 $this->assertEqualSets( array( $g2, $g3 ), $found ); 1770 } 1771 1772 /** 1773 * @group hierarchical_groups 1774 */ 1775 public function test_get_by_parent_id_comma_separated_string() { 1776 $g1 = $this->factory->group->create(); 1777 $g2 = $this->factory->group->create( array( 1778 'parent_id' => $g1, 1779 ) ); 1780 $g3 = $this->factory->group->create( array( 1781 'parent_id' => $g2, 1782 ) ); 1783 $g4 = $this->factory->group->create(); 1784 1785 $groups = BP_Groups_Group::get( array( 1786 'parent_id' => "$g1, $g2", 1787 ) ); 1788 1789 $found = wp_list_pluck( $groups['groups'], 'id' ); 1790 $this->assertEqualSets( array( $g2, $g3 ), $found ); 1791 } 1792 1793 /** 1794 * @group hierarchical_groups 1795 */ 1796 public function test_get_by_parent_id_top_level_groups() { 1797 $g1 = $this->factory->group->create(); 1798 $g2 = $this->factory->group->create( array( 1799 'parent_id' => $g1, 1800 ) ); 1801 $g3 = $this->factory->group->create( array( 1802 'parent_id' => $g2, 1803 ) ); 1804 $g4 = $this->factory->group->create(); 1805 1806 $groups = BP_Groups_Group::get( array( 1807 'parent_id' => 0, 1808 ) ); 1809 1810 $found = wp_list_pluck( $groups['groups'], 'id' ); 1811 $this->assertEqualSets( array( $g1, $g4 ), $found ); 1812 } 1813 1814 /** 1815 * @group hierarchical_groups 1816 */ 1817 public function test_get_by_parent_id_top_level_groups_using_false() { 1818 $g1 = $this->factory->group->create(); 1819 $g2 = $this->factory->group->create( array( 1820 'parent_id' => $g1, 1821 ) ); 1822 $g3 = $this->factory->group->create( array( 1823 'parent_id' => $g2, 1824 ) ); 1825 $g4 = $this->factory->group->create(); 1826 1827 $groups = BP_Groups_Group::get( array( 1828 'parent_id' => false, 1829 ) ); 1830 1831 $found = wp_list_pluck( $groups['groups'], 'id' ); 1832 $this->assertEqualSets( array( $g1, $g4 ), $found ); 1833 } 1708 1834 } 1709 1835 -
trunk/tests/phpunit/testcases/groups/functions.php
r11091 r11095 635 635 $this->assertEquals( 0, groups_get_invite_count_for_user( $u2 ) ); 636 636 } 637 638 /** 639 * @group hierarchical_groups 640 */ 641 public function test_update_orphaned_groups_on_group_delete_top_level() { 642 $g1 = $this->factory->group->create(); 643 $g2 = $this->factory->group->create( array( 644 'parent_id' => $g1, 645 ) ); 646 647 groups_delete_group( $g1 ); 648 649 $child = groups_get_group( array( 'group_id' => $g2 ) ); 650 $this->assertEquals( 0, $child->parent_id ); 651 } 652 653 /** 654 * @group hierarchical_groups 655 */ 656 public function test_update_orphaned_groups_on_group_delete_two_levels() { 657 $g1 = $this->factory->group->create(); 658 $g2 = $this->factory->group->create( array( 659 'parent_id' => $g1, 660 ) ); 661 $g3 = $this->factory->group->create( array( 662 'parent_id' => $g2, 663 ) ); 664 665 groups_delete_group( $g2 ); 666 667 $child = groups_get_group( array( 'group_id' => $g3 ) ); 668 $this->assertEquals( $g1, $child->parent_id ); 669 } 637 670 } -
trunk/tests/phpunit/testcases/groups/template.php
r9819 r11095 118 118 119 119 $this->assertEquals( 1, $groups_template->group_count ); 120 } 121 122 /** 123 * @group hierarchical_groups 124 */ 125 public function test_bp_has_groups_parent_id() { 126 $g1 = $this->factory->group->create(); 127 $g2 = $this->factory->group->create( array( 128 'parent_id' => $g1, 129 ) ); 130 $g3 = $this->factory->group->create( array( 131 'parent_id' => $g2, 132 ) ); 133 $g4 = $this->factory->group->create(); 134 135 global $groups_template; 136 bp_has_groups( array( 137 'parent_id' => $g1, 138 ) ); 139 140 $ids = wp_parse_id_list( wp_list_pluck( $groups_template->groups, 'id' ) ); 141 $this->assertEquals( array( $g2 ), $ids ); 142 } 143 144 /** 145 * @group hierarchical_groups 146 */ 147 public function test_bp_has_groups_parent_id_array() { 148 $g1 = $this->factory->group->create(); 149 $g2 = $this->factory->group->create( array( 150 'parent_id' => $g1, 151 ) ); 152 $g3 = $this->factory->group->create( array( 153 'parent_id' => $g2, 154 ) ); 155 $g4 = $this->factory->group->create(); 156 157 global $groups_template; 158 bp_has_groups( array( 159 'parent_id' => array( $g1, $g2 ), 160 ) ); 161 162 $ids = wp_parse_id_list( wp_list_pluck( $groups_template->groups, 'id' ) ); 163 $this->assertEqualSets( array( $g2, $g3 ), $ids ); 164 } 165 166 /** 167 * @group hierarchical_groups 168 */ 169 public function test_bp_has_groups_parent_id_comma_separated() { 170 $g1 = $this->factory->group->create(); 171 $g2 = $this->factory->group->create( array( 172 'parent_id' => $g1, 173 ) ); 174 $g3 = $this->factory->group->create( array( 175 'parent_id' => $g2, 176 ) ); 177 $g4 = $this->factory->group->create(); 178 179 global $groups_template; 180 bp_has_groups( array( 181 'parent_id' => "{$g1},{$g2}", 182 ) ); 183 184 $ids = wp_parse_id_list( wp_list_pluck( $groups_template->groups, 'id' ) ); 185 $this->assertEqualSets( array( $g2, $g3 ), $ids ); 186 } 187 188 /** 189 * @group hierarchical_groups 190 */ 191 public function test_bp_has_groups_parent_id_null() { 192 $g1 = $this->factory->group->create(); 193 $g2 = $this->factory->group->create( array( 194 'parent_id' => $g1, 195 ) ); 196 $g3 = $this->factory->group->create( array( 197 'parent_id' => $g2, 198 ) ); 199 $g4 = $this->factory->group->create(); 200 201 global $groups_template; 202 bp_has_groups( array( 203 'parent_id' => null, 204 ) ); 205 206 $ids = wp_parse_id_list( wp_list_pluck( $groups_template->groups, 'id' ) ); 207 $this->assertEqualSets( array( $g1, $g2, $g3, $g4 ), $ids ); 208 } 209 210 /** 211 * @group hierarchical_groups 212 */ 213 public function test_bp_has_groups_parent_id_top_level_groups() { 214 $g1 = $this->factory->group->create(); 215 $g2 = $this->factory->group->create( array( 216 'parent_id' => $g1, 217 ) ); 218 $g3 = $this->factory->group->create( array( 219 'parent_id' => $g2, 220 ) ); 221 $g4 = $this->factory->group->create(); 222 223 global $groups_template; 224 bp_has_groups( array( 225 'parent_id' => 0, 226 ) ); 227 228 $ids = wp_parse_id_list( wp_list_pluck( $groups_template->groups, 'id' ) ); 229 $this->assertEqualSets( array( $g1, $g4 ), $ids ); 230 } 231 232 /** 233 * @group hierarchical_groups 234 */ 235 public function test_bp_has_groups_parent_id_top_level_groups_using_false() { 236 $g1 = $this->factory->group->create(); 237 $g2 = $this->factory->group->create( array( 238 'parent_id' => $g1, 239 ) ); 240 $g3 = $this->factory->group->create( array( 241 'parent_id' => $g2, 242 ) ); 243 $g4 = $this->factory->group->create(); 244 245 global $groups_template; 246 bp_has_groups( array( 247 'parent_id' => false, 248 ) ); 249 250 $ids = wp_parse_id_list( wp_list_pluck( $groups_template->groups, 'id' ) ); 251 $this->assertEqualSets( array( $g1, $g4 ), $ids ); 120 252 } 121 253
Note: See TracChangeset
for help on using the changeset viewer.