Ticket #8444: 8444.1.diff
File 8444.1.diff, 11.0 KB (added by , 4 years ago) |
---|
-
src/bp-core/classes/class-bp-invitation-manager.php
diff --git src/bp-core/classes/class-bp-invitation-manager.php src/bp-core/classes/class-bp-invitation-manager.php index a8bb047ce..aca7b6089 100644
abstract class BP_Invitation_Manager { 139 139 140 140 // "Send" the invite if necessary. 141 141 if ( $invite_id && $r['send_invite'] ) { 142 $sent = $this->send_invitation_by_id( $invite_id );142 $sent = $this->send_invitation_by_id( $invite_id, $args ); 143 143 if ( ! $sent ) { 144 144 return false; 145 145 } … … abstract class BP_Invitation_Manager { 154 154 * @since 5.0.0 155 155 * @access public 156 156 * 157 * @param int $invitation_id ID of invitation to send. 157 * @param int $invitation_id ID of invitation to send. 158 * @param array $args Invitation characteristics used 159 * to override certain sending behaviors. 158 160 * 159 161 * @return int|bool The number of rows updated, or false on error. 160 162 */ 161 public function send_invitation_by_id( $invitation_id = 0 ) {163 public function send_invitation_by_id( $invitation_id = 0, $args = array() ) { 162 164 $updated = false; 163 165 164 166 $invitation = new BP_Invitation( $invitation_id ); … … abstract class BP_Invitation_Manager { 196 198 // Perform the send action. 197 199 $this->run_send_action( $invitation ); 198 200 199 $updated = BP_Invitation::mark_sent( $invitation->id );201 $updated = BP_Invitation::mark_sent( $invitation->id, $args ); 200 202 201 203 return $updated; 202 204 } … … abstract class BP_Invitation_Manager { 305 307 * @since 5.0.0 306 308 * @access public 307 309 * 308 * @param int $request_id ID of request to send. 310 * @param int $request_id ID of request to send. 311 * @param array $args Invitation characteristics used 312 * to override certain sending behaviors. 309 313 * 310 314 * @return int|bool The number of rows updated, or false on error. 311 315 */ 312 public function send_request_notification_by_id( $request_id = 0 ) {316 public function send_request_notification_by_id( $request_id = 0, $args = array() ) { 313 317 $updated = false; 314 318 315 319 $request = new BP_Invitation( $request_id ); … … abstract class BP_Invitation_Manager { 342 346 // Perform the send action. 343 347 $this->run_send_action( $request ); 344 348 345 $updated = BP_Invitation::mark_sent( $request->id );349 $updated = BP_Invitation::mark_sent( $request->id, $args ); 346 350 347 351 return $updated; 348 352 } … … abstract class BP_Invitation_Manager { 485 489 $success = $this->run_acceptance_action( 'invite', $r ); 486 490 if ( $success ) { 487 491 // Mark invitations & requests to this item for this user. 488 $this->mark_accepted( $r );492 $this->mark_accepted( $r, $args ); 489 493 490 494 // Allow plugins an opportunity to act on the change. 491 495 do_action( 'bp_invitations_accepted_invite', $r ); … … abstract class BP_Invitation_Manager { 531 535 $success = $this->run_acceptance_action( 'request', $r ); 532 536 if ( $success ) { 533 537 // Update/Delete all related invitations & requests to this item for this user. 534 $this->mark_accepted( $r );538 $this->mark_accepted( $r, $args ); 535 539 536 540 // Allow plugins an opportunity to act on the change. 537 541 do_action( 'bp_invitations_accepted_request', $r ); … … abstract class BP_Invitation_Manager { 618 622 * 619 623 * @since 5.0.0 620 624 * 621 * @param int $id The ID of the invitation to mark as sent. 625 * @see BP_Invitation::mark_accepted() 626 * for a description of arguments. 622 627 * @return bool True on success, false on failure. 623 628 */ 624 public function mark_accepted_by_id( $id ) {625 return BP_Invitation::mark_accepted( $id );629 public function mark_accepted_by_id( $id, $args ) { 630 return BP_Invitation::mark_accepted( $id, $args ); 626 631 } 627 632 628 633 /** … … abstract class BP_Invitation_Manager { 635 640 * @see BP_Invitation::mark_accepted_by_data() 636 641 * for a description of arguments. 637 642 */ 638 public function mark_accepted( $args ) {643 public function mark_accepted( $args, $passed_args ) { 639 644 $args['class'] = $this->class_name; 640 return BP_Invitation::mark_accepted_by_data( $args );645 return BP_Invitation::mark_accepted_by_data( $args, $passed_args ); 641 646 } 642 647 643 648 /** Delete ********************************************************************/ -
src/bp-core/classes/class-bp-invitation.php
diff --git src/bp-core/classes/class-bp-invitation.php src/bp-core/classes/class-bp-invitation.php index 64f0ee30e..420a0b617 100644
class BP_Invitation { 640 640 } 641 641 } 642 642 643 // date_modified 644 if ( ! empty( $args['date_modified'] ) ) { 645 $where_clauses['data']['date_modified'] = $args['date_modified']; 646 $where_clauses['format'][] = '%s'; 647 } 648 643 649 return $where_clauses; 644 650 } 645 651 … … class BP_Invitation { 968 974 * 969 975 * @since 5.0.0 970 976 * 971 * @param int $id The ID of the invitation to mark as sent. 977 * @param int $id The ID of the invitation to mark as sent. 978 * @param array $args Invitation characteristics used 979 * to override certain sending behaviors. 972 980 */ 973 public static function mark_sent( $id = 0 ) {981 public static function mark_sent( $id = 0, $args = array() ) { 974 982 975 983 if ( ! $id ) { 976 984 return false; … … class BP_Invitation { 978 986 979 987 // Values to be updated. 980 988 $update_args = array( 981 'invite_sent' => 'sent', 989 'invite_sent' => 'sent', 990 'date_modified' => bp_core_current_time(), 982 991 ); 992 // Respect a specified `date-modified` 993 if ( ! empty( $args['date_modified'] ) ) { 994 $update_args['date_modified'] = $args['date_modified']; 995 } 983 996 984 997 // WHERE clauses. 985 998 $where_args = array( … … class BP_Invitation { 995 1008 * 996 1009 * @since 5.0.0 997 1010 * 998 * @param array $args See BP_Invitation::update(). 1011 * @param array $args See BP_Invitation::update(). 1012 * @param array $passed_args Invitation characteristics used 1013 * to override certain sending behaviors. 999 1014 */ 1000 public static function mark_sent_by_data( $args ) {1015 public static function mark_sent_by_data( $args, $passed_args = array() ) { 1001 1016 1002 1017 // Values to be updated. 1003 1018 $update_args = array( 1004 'invite_sent' => 'sent', 1019 'invite_sent' => 'sent', 1020 'date_modified' => bp_core_current_time(), 1005 1021 ); 1022 // Respect a specified `date-modified` 1023 if ( ! empty( $passed_args['date_modified'] ) ) { 1024 $update_args['date_modified'] = $passed_args['date_modified']; 1025 } 1006 1026 1007 1027 return self::update( $update_args, $args ); 1008 1028 } … … class BP_Invitation { 1014 1034 * 1015 1035 * @since 5.0.0 1016 1036 * 1017 * @param int $id The ID of the invitation to mark as sent. 1037 * @param int $id The ID of the invitation to mark as sent. 1038 * @param array $args Invitation characteristics used 1039 * to override certain acceptance behaviors. 1018 1040 */ 1019 public static function mark_accepted( $id = 0 ) {1041 public static function mark_accepted( $id = 0, $args = array() ) { 1020 1042 1021 1043 if ( ! $id ) { 1022 1044 return false; … … class BP_Invitation { 1024 1046 1025 1047 // Values to be updated. 1026 1048 $update_args = array( 1027 'accepted' => 'accepted', 1049 'accepted' => 'accepted', 1050 'date_modified' => bp_core_current_time(), 1028 1051 ); 1052 // Respect a specified `date-modified` 1053 if ( ! empty( $args['date_modified'] ) ) { 1054 $update_args['date_modified'] = $args['date_modified']; 1055 } 1029 1056 1030 1057 // WHERE clauses. 1031 1058 $where_args = array( … … class BP_Invitation { 1041 1068 * 1042 1069 * @since 5.0.0 1043 1070 * 1044 * @param array $args See BP_Invitation::update(). 1071 * @param array $args See BP_Invitation::update(). 1072 * @param array $passed_args Invitation characteristics used 1073 * to override certain acceptance behaviors. 1045 1074 */ 1046 public static function mark_accepted_by_data( $args ) {1075 public static function mark_accepted_by_data( $args, $passed_args = array() ) { 1047 1076 1048 1077 // Values to be updated. 1049 1078 $update_args = array( 1050 'accepted' => 'accepted', 1079 'accepted' => 'accepted', 1080 'date_modified' => bp_core_current_time(), 1051 1081 ); 1082 // Respect a specified `date-modified` 1083 if ( ! empty( $args['date_modified'] ) ) { 1084 $update_args['date_modified'] = $args['date_modified']; 1085 } 1052 1086 1053 1087 return self::update( $update_args, $args ); 1054 1088 } -
src/bp-groups/bp-groups-functions.php
diff --git src/bp-groups/bp-groups-functions.php src/bp-groups/bp-groups-functions.php index d1af9ad1f..e8c5639b0 100644
function groups_send_membership_request( ...$args ) { 2044 2044 2045 2045 // If a new request was created, send the emails. 2046 2046 if ( $request_id && is_int( $request_id ) ) { 2047 $invites_class->send_request_notification_by_id( $request_id );2047 $invites_class->send_request_notification_by_id( $request_id, $args ); 2048 2048 $admins = groups_get_group_admins( $r['group_id'] ); 2049 2049 2050 2050 /** -
src/bp-groups/classes/class-bp-groups-invitation-manager.php
diff --git src/bp-groups/classes/class-bp-groups-invitation-manager.php src/bp-groups/classes/class-bp-groups-invitation-manager.php index 76d4e13c7..874aa0d25 100644
class BP_Groups_Invitation_Manager extends BP_Invitation_Manager { 140 140 * 141 141 * @param array $args. 142 142 */ 143 public function mark_accepted( $args ) {143 public function mark_accepted( $args, $passed_args ) { 144 144 // Delete all existing invitations/requests to this group for this user. 145 145 $this->delete( array( 146 146 'user_id' => $args['user_id'], -
tests/phpunit/testcases/core/invitations.php
diff --git tests/phpunit/testcases/core/invitations.php tests/phpunit/testcases/core/invitations.php index 0646557a4..d8f1f4efb 100644
include_once BP_TESTS_DIR . 'assets/invitations-extensions.php'; 332 332 $this->set_current_user( $old_current_user ); 333 333 } 334 334 335 public function test_bp_invitations_add_request_with_date_modified() { 336 $old_current_user = get_current_user_id(); 337 338 $u1 = $this->factory->user->create(); 339 $this->set_current_user( $u1 ); 340 341 $invites_class = new BPTest_Invitation_Manager_Extension(); 342 343 $time = gmdate( 'Y-m-d H:i:s', time() - 100 ); 344 $args = array( 345 'user_id' => $u1, 346 'item_id' => 7, 347 'date_modified' => $time, 348 ); 349 $r1 = $invites_class->add_request( $args ); 350 351 $req = new BP_Invitation( $r1 ); 352 $this->assertEquals( $time, $req->date_modified ); 353 354 $this->set_current_user( $old_current_user ); 355 } 356 357 public function test_bp_invitations_add_invite_with_date_modified() { 358 $old_current_user = get_current_user_id(); 359 360 $u1 = $this->factory->user->create(); 361 $u2 = $this->factory->user->create(); 362 $this->set_current_user( $u1 ); 363 364 $invites_class = new BPTest_Invitation_Manager_Extension(); 365 $time = gmdate( 'Y-m-d H:i:s', time() - 100 ); 366 367 // Create an invitation. 368 $invite_args = array( 369 'user_id' => $u2, 370 'inviter_id' => $u1, 371 'item_id' => 1, 372 'send_invite' => 1, 373 'date_modified' => $time, 374 ); 375 $i1 = $invites_class->add_invitation( $invite_args ); 376 377 $inv = new BP_Invitation( $i1 ); 378 $this->assertEquals( $time, $inv->date_modified ); 379 380 $this->set_current_user( $old_current_user ); 381 } 382 335 383 }