Changeset 7883
- Timestamp:
- 02/14/2014 07:02:16 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-activity/bp-activity-functions.php
r7879 r7883 539 539 * Delete a meta entry from the DB for an activity stream item. 540 540 * 541 * @since BuddyPress (1.2 )541 * @since BuddyPress (1.2.0) 542 542 * 543 543 * @global object $wpdb WordPress database access object. 544 544 * @global object $bp BuddyPress global settings. 545 * @uses wp_cache_delete()546 * @uses is_wp_error()547 545 * 548 546 * @param int $activity_id ID of the activity item whose metadata is being deleted. 549 547 * @param string $meta_key Optional. The key of the metadata being deleted. If 550 * 551 * 548 * omitted, all metadata associated with the activity 549 * item will be deleted. 552 550 * @param string $meta_value Optional. If present, the metadata will only be 553 * deleted if the meta_value matches this parameter. 551 * deleted if the meta_value matches this parameter. 552 * @param bool $delete_all Optional. If true, delete matching metadata entries 553 * for all objects, ignoring the specified object_id. Otherwise, 554 * only delete matching metadata entries for the specified 555 * activity item. Default: false. 554 556 * @return bool True on success, false on failure. 555 557 */ 556 function bp_activity_delete_meta( $activity_id, $meta_key = '', $meta_value = '' ) {558 function bp_activity_delete_meta( $activity_id, $meta_key = '', $meta_value = '', $delete_all = false ) { 557 559 global $wpdb, $bp; 558 560 … … 572 574 $all_meta = bp_activity_get_meta( $activity_id ); 573 575 $keys = ! empty( $all_meta ) ? wp_list_pluck( $all_meta, 'meta_key' ) : array(); 576 577 // With no meta_key, ignore $delete_all 578 $delete_all = false; 574 579 } else { 575 580 $keys = array( $meta_key ); … … 578 583 add_filter( 'query', 'bp_filter_metaid_column_name' ); 579 584 foreach ( $keys as $key ) { 580 $retval = delete_metadata( 'activity', $activity_id, $key, $meta_value );585 $retval = delete_metadata( 'activity', $activity_id, $key, $meta_value, $delete_all ); 581 586 } 582 587 remove_filter( 'query', 'bp_filter_metaid_column_name' ); -
trunk/bp-blogs/bp-blogs-functions.php
r7879 r7883 835 835 * @param string $meta_value Optional. If present, the metadata will only be 836 836 * deleted if the meta_value matches this parameter. 837 * @param bool $delete_all Optional. If true, delete matching metadata entries 838 * for all objects, ignoring the specified blog_id. Otherwise, only 839 * delete matching metadata entries for the specified blog. 840 * Default: false. 837 841 * @return bool True on success, false on failure. 838 842 */ 839 function bp_blogs_delete_blogmeta( $blog_id, $meta_key = false, $meta_value = false ) {843 function bp_blogs_delete_blogmeta( $blog_id, $meta_key = false, $meta_value = false, $delete_all = false ) { 840 844 global $wpdb, $bp; 841 845 … … 851 855 if ( empty( $meta_key ) ) { 852 856 $keys = $wpdb->get_col( $wpdb->prepare( "SELECT meta_key FROM {$wpdb->blogmeta} WHERE blog_id = %d", $blog_id ) ); 857 $delete_all = false; 853 858 } else { 854 859 $keys = array( $meta_key ); … … 861 866 862 867 foreach ( $keys as $key ) { 863 $retval = delete_metadata( 'blog', $blog_id, $key, $meta_value );868 $retval = delete_metadata( 'blog', $blog_id, $key, $meta_value, $delete_all ); 864 869 } 865 870 -
trunk/bp-groups/bp-groups-functions.php
r7875 r7883 966 966 * @param bool $delete_all Optional. If true, delete matching metadata entries 967 967 * for all groups. Default: false. 968 * @param bool $delete_all Optional. If true, delete matching metadata entries 969 * for all objects, ignoring the specified group_id. Otherwise, only 970 * delete matching metadata entries for the specified group. 971 * Default: false. 968 972 * @return bool True on success, false on failure. 969 973 */ 970 974 function groups_delete_groupmeta( $group_id, $meta_key = false, $meta_value = false, $delete_all = false ) { 975 global $wpdb; 971 976 972 977 // Legacy - return false if non-int group ID … … 978 983 $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key ); 979 984 985 // Legacy - if no meta_key is passed, delete all for the item 986 if ( empty( $meta_key ) ) { 987 $keys = $wpdb->get_col( $wpdb->prepare( "SELECT meta_key FROM {$wpdb->groupmeta} WHERE group_id = %d", $group_id ) ); 988 989 // With no meta_key, ignore $delete_all 990 $delete_all = false; 991 } else { 992 $keys = array( $meta_key ); 993 } 994 980 995 add_filter( 'query', 'bp_filter_metaid_column_name' ); 981 $retval = delete_metadata( 'group', $group_id, $meta_key, $meta_value, $delete_all ); 996 997 foreach ( $keys as $key ) { 998 $retval = delete_metadata( 'group', $group_id, $key, $meta_value, $delete_all ); 999 } 1000 982 1001 remove_filter( 'query', 'bp_filter_metaid_column_name' ); 983 1002 -
trunk/bp-xprofile/bp-xprofile-functions.php
r7879 r7883 539 539 * @param mixed $meta_value Optional. If provided, only metadata that matches 540 540 * the value will be permitted. 541 * @param bool $delete_all Optional. If true, delete matching metadata entries 542 * for all objects, ignoring the specified object_id. Otherwise, only 543 * delete matching metadata entries for the specified object. 544 * Default: false. 541 545 * @return bool True on success, false on failure. 542 546 */ 543 function bp_xprofile_delete_meta( $object_id, $object_type, $meta_key = false, $meta_value = false ) {547 function bp_xprofile_delete_meta( $object_id, $object_type, $meta_key = false, $meta_value = false, $delete_all = false ) { 544 548 global $wpdb; 545 549 … … 559 563 $table_name = $wpdb->{$table_key}; 560 564 $keys = $wpdb->get_col( $wpdb->prepare( "SELECT meta_key FROM {$table_name} WHERE object_type = %s AND object_id = %d", $object_type, $object_id ) ); 565 566 // Force delete_all to false if deleting all for object 567 $delete_all = false; 561 568 } else { 562 569 $keys = array( $meta_key ); … … 570 577 571 578 foreach ( $keys as $key ) { 572 $retval = delete_metadata( 'xprofile_' . $object_type, $object_id, $key, $meta_value );579 $retval = delete_metadata( 'xprofile_' . $object_type, $object_id, $key, $meta_value, $delete_all ); 573 580 } 574 581 -
trunk/tests/testcases/activity/functions.php
r7879 r7883 337 337 /** 338 338 * @group activitymeta 339 * @group bp_activity_delete_meta 340 */ 341 public function test_bp_activity_delete_meta_with_delete_all_but_no_meta_key() { 342 // With no meta key, don't delete for all items - just delete 343 // all for a single item 344 $a1 = $this->factory->activity->create(); 345 $a2 = $this->factory->activity->create(); 346 bp_activity_update_meta( $a1, 'foo', 'bar' ); 347 bp_activity_update_meta( $a1, 'foo1', 'bar1' ); 348 bp_activity_update_meta( $a2, 'foo', 'bar' ); 349 bp_activity_update_meta( $a2, 'foo1', 'bar1' ); 350 351 $this->assertTrue( bp_activity_delete_meta( $a1, '', '', true ) ); 352 $this->assertEmpty( bp_activity_get_meta( $a1 ) ); 353 $this->assertSame( 'bar', bp_activity_get_meta( $a2, 'foo' ) ); 354 $this->assertSame( 'bar1', bp_activity_get_meta( $a2, 'foo1' ) ); 355 } 356 357 /** 358 * @group activitymeta 359 * @group bp_activity_delete_meta 360 */ 361 public function test_bp_activity_delete_meta_with_delete_all() { 362 // With no meta key, don't delete for all items - just delete 363 // all for a single item 364 $a1 = $this->factory->activity->create(); 365 $a2 = $this->factory->activity->create(); 366 bp_activity_update_meta( $a1, 'foo', 'bar' ); 367 bp_activity_update_meta( $a1, 'foo1', 'bar1' ); 368 bp_activity_update_meta( $a2, 'foo', 'bar' ); 369 bp_activity_update_meta( $a2, 'foo1', 'bar1' ); 370 371 $this->assertTrue( bp_activity_delete_meta( $a1, 'foo', '', true ) ); 372 $this->assertEmpty( '', bp_activity_get_meta( $a1, 'foo' ) ); 373 $this->assertEmpty( '', bp_activity_get_meta( $a2, 'foo' ) ); 374 $this->assertSame( 'bar1', bp_activity_get_meta( $a1, 'foo1' ) ); 375 $this->assertSame( 'bar1', bp_activity_get_meta( $a2, 'foo1' ) ); 376 } 377 /** 378 * @group activitymeta 339 379 * @group bp_activity_add_meta 340 380 */ -
trunk/tests/testcases/blogs/functions.php
r7879 r7883 63 63 /** 64 64 * @group blogmeta 65 * @group bp_blogs_delete_blogmeta 66 */ 67 public function test_bp_blogs_delete_blogmeta_with_delete_all_but_no_meta_key() { 68 // With no meta key, don't delete for all items - just delete 69 // all for a single item 70 bp_blogs_add_blogmeta( 1, 'foo', 'bar' ); 71 bp_blogs_add_blogmeta( 1, 'foo1', 'bar1' ); 72 bp_blogs_add_blogmeta( 2, 'foo', 'bar' ); 73 bp_blogs_add_blogmeta( 2, 'foo1', 'bar1' ); 74 75 $this->assertTrue( bp_blogs_delete_blogmeta( 1, '', '', true ) ); 76 $this->assertEmpty( bp_blogs_get_blogmeta( 1 ) ); 77 $this->assertSame( 'bar', bp_blogs_get_blogmeta( 2, 'foo' ) ); 78 $this->assertSame( 'bar1', bp_blogs_get_blogmeta( 2, 'foo1' ) ); 79 } 80 81 /** 82 * @group blogmeta 83 * @group bp_blogs_delete_blogmeta 84 */ 85 public function test_bp_blogs_delete_blogmeta_with_delete_all() { 86 // With no meta key, don't delete for all items - just delete 87 // all for a single item 88 bp_blogs_add_blogmeta( 1, 'foo', 'bar' ); 89 bp_blogs_add_blogmeta( 1, 'foo1', 'bar1' ); 90 bp_blogs_add_blogmeta( 2, 'foo', 'bar' ); 91 bp_blogs_add_blogmeta( 2, 'foo1', 'bar1' ); 92 93 $this->assertTrue( bp_blogs_delete_blogmeta( 1, 'foo', '', true ) ); 94 $this->assertEmpty( '', bp_blogs_get_blogmeta( 1, 'foo' ) ); 95 $this->assertEmpty( '', bp_blogs_get_blogmeta( 2, 'foo' ) ); 96 $this->assertSame( 'bar1', bp_blogs_get_blogmeta( 1, 'foo1' ) ); 97 $this->assertSame( 'bar1', bp_blogs_get_blogmeta( 2, 'foo1' ) ); 98 } 99 100 /** 101 * @group blogmeta 65 102 * @group bp_blogs_get_blogmeta 66 103 */ -
trunk/tests/testcases/groups/functions.php
r7879 r7883 437 437 /** 438 438 * @group groupmeta 439 * @group groups_delete_groupmeta 440 */ 441 public function test_groups_delete_groupmeta_with_delete_all_but_no_meta_key() { 442 // With no meta key, don't delete for all items - just delete 443 // all for a single item 444 $g1 = $this->factory->group->create(); 445 $g2 = $this->factory->group->create(); 446 groups_add_groupmeta( $g1, 'foo', 'bar' ); 447 groups_add_groupmeta( $g1, 'foo1', 'bar1' ); 448 groups_add_groupmeta( $g2, 'foo', 'bar' ); 449 groups_add_groupmeta( $g2, 'foo1', 'bar1' ); 450 451 $this->assertTrue( groups_delete_groupmeta( $g1, '', '', true ) ); 452 $this->assertEmpty( groups_get_groupmeta( $g1 ) ); 453 $this->assertSame( 'bar', groups_get_groupmeta( $g2, 'foo' ) ); 454 $this->assertSame( 'bar1', groups_get_groupmeta( $g2, 'foo1' ) ); 455 } 456 457 /** 458 * @group groupmeta 459 * @group groups_delete_groupmeta 460 */ 461 public function test_groups_delete_groupmeta_with_delete_all() { 462 // With no meta key, don't delete for all items - just delete 463 // all for a single item 464 $g1 = $this->factory->group->create(); 465 $g2 = $this->factory->group->create(); 466 groups_add_groupmeta( $g1, 'foo', 'bar' ); 467 groups_add_groupmeta( $g1, 'foo1', 'bar1' ); 468 groups_add_groupmeta( $g2, 'foo', 'bar' ); 469 groups_add_groupmeta( $g2, 'foo1', 'bar1' ); 470 471 $this->assertTrue( groups_delete_groupmeta( $g1, 'foo', '', true ) ); 472 $this->assertEmpty( '', groups_get_groupmeta( $g1, 'foo' ) ); 473 $this->assertEmpty( '', groups_get_groupmeta( $g2, 'foo' ) ); 474 $this->assertSame( 'bar1', groups_get_groupmeta( $g1, 'foo1' ) ); 475 $this->assertSame( 'bar1', groups_get_groupmeta( $g2, 'foo1' ) ); 476 } 477 478 /** 479 * @group groupmeta 439 480 * @group groups_add_groupmeta 440 481 */ -
trunk/tests/testcases/xprofile/functions.php
r7879 r7883 234 234 $this->assertTrue( bp_xprofile_delete_meta( $g, 'group' ) ); 235 235 236 // These will fail because of a caching bug237 236 $this->assertEquals( '', bp_xprofile_get_meta( $g, 'group', 'foo' ) ); 238 237 $this->assertEquals( '', bp_xprofile_get_meta( $g, 'group', 'foo2' ) ); 238 } 239 240 /** 241 * @group xprofilemeta 242 * @group bp_xprofile_delete_meta 243 */ 244 public function test_bp_xprofile_delete_meta_with_delete_all_but_no_meta_key() { 245 // With no meta key, don't delete for all items - just delete 246 // all for a single item 247 $g1 = $this->factory->xprofile_group->create(); 248 $g2 = $this->factory->xprofile_group->create(); 249 bp_xprofile_add_meta( $g1, 'group', 'foo', 'bar' ); 250 bp_xprofile_add_meta( $g1, 'group', 'foo1', 'bar1' ); 251 bp_xprofile_add_meta( $g2, 'group', 'foo', 'bar' ); 252 bp_xprofile_add_meta( $g2, 'group', 'foo1', 'bar1' ); 253 254 $this->assertTrue( bp_xprofile_delete_meta( $g1, 'group', '', '', true ) ); 255 $this->assertEmpty( bp_xprofile_get_meta( $g1, 'group' ) ); 256 $this->assertSame( 'bar', bp_xprofile_get_meta( $g2, 'group', 'foo' ) ); 257 $this->assertSame( 'bar1', bp_xprofile_get_meta( $g2, 'group', 'foo1' ) ); 258 } 259 260 /** 261 * @group xprofilemeta 262 * @group bp_xprofile_delete_meta 263 */ 264 public function test_bp_xprofile_delete_meta_with_delete_all() { 265 // With no meta key, don't delete for all items - just delete 266 // all for a single item 267 $g1 = $this->factory->xprofile_group->create(); 268 $g2 = $this->factory->xprofile_group->create(); 269 bp_xprofile_add_meta( $g1, 'group', 'foo', 'bar' ); 270 bp_xprofile_add_meta( $g1, 'group', 'foo1', 'bar1' ); 271 bp_xprofile_add_meta( $g2, 'group', 'foo', 'bar' ); 272 bp_xprofile_add_meta( $g2, 'group', 'foo1', 'bar1' ); 273 274 $this->assertTrue( bp_xprofile_delete_meta( $g1, 'group', 'foo', '', true ) ); 275 $this->assertEmpty( '', bp_xprofile_get_meta( $g1, 'group', 'foo' ) ); 276 $this->assertEmpty( '', bp_xprofile_get_meta( $g2, 'group', 'foo' ) ); 277 $this->assertSame( 'bar1', bp_xprofile_get_meta( $g1, 'group', 'foo1' ) ); 278 $this->assertSame( 'bar1', bp_xprofile_get_meta( $g2, 'group', 'foo1' ) ); 239 279 } 240 280
Note: See TracChangeset
for help on using the changeset viewer.