Skip to:
Content

BuddyPress.org

Ticket #8444: 8444.1.diff

File 8444.1.diff, 11.0 KB (added by dcavins, 4 years ago)

Add invitation date_modified changes and tests.

  • 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 { 
    139139
    140140                // "Send" the invite if necessary.
    141141                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 );
    143143                        if ( ! $sent ) {
    144144                                return false;
    145145                        }
    abstract class BP_Invitation_Manager { 
    154154         * @since 5.0.0
    155155         * @access public
    156156         *
    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.
    158160         *
    159161         * @return int|bool The number of rows updated, or false on error.
    160162         */
    161         public function send_invitation_by_id( $invitation_id = 0 ) {
     163        public function send_invitation_by_id( $invitation_id = 0, $args = array() ) {
    162164                $updated = false;
    163165
    164166                $invitation = new BP_Invitation( $invitation_id );
    abstract class BP_Invitation_Manager { 
    196198                // Perform the send action.
    197199                $this->run_send_action( $invitation );
    198200
    199                 $updated = BP_Invitation::mark_sent( $invitation->id );
     201                $updated = BP_Invitation::mark_sent( $invitation->id, $args );
    200202
    201203                return $updated;
    202204        }
    abstract class BP_Invitation_Manager { 
    305307         * @since 5.0.0
    306308         * @access public
    307309         *
    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.
    309313         *
    310314         * @return int|bool The number of rows updated, or false on error.
    311315         */
    312         public function send_request_notification_by_id( $request_id = 0 ) {
     316        public function send_request_notification_by_id( $request_id = 0, $args = array() ) {
    313317                $updated = false;
    314318
    315319                $request = new BP_Invitation( $request_id );
    abstract class BP_Invitation_Manager { 
    342346                // Perform the send action.
    343347                $this->run_send_action( $request );
    344348
    345                 $updated = BP_Invitation::mark_sent( $request->id );
     349                $updated = BP_Invitation::mark_sent( $request->id, $args );
    346350
    347351                return $updated;
    348352        }
    abstract class BP_Invitation_Manager { 
    485489                $success = $this->run_acceptance_action( 'invite', $r );
    486490                if ( $success ) {
    487491                        // Mark invitations & requests to this item for this user.
    488                         $this->mark_accepted( $r );
     492                        $this->mark_accepted( $r, $args );
    489493
    490494                        // Allow plugins an opportunity to act on the change.
    491495                        do_action( 'bp_invitations_accepted_invite', $r );
    abstract class BP_Invitation_Manager { 
    531535                $success = $this->run_acceptance_action( 'request', $r );
    532536                if ( $success ) {
    533537                        // Update/Delete all related invitations & requests to this item for this user.
    534                         $this->mark_accepted( $r );
     538                        $this->mark_accepted( $r, $args );
    535539
    536540                        // Allow plugins an opportunity to act on the change.
    537541                        do_action( 'bp_invitations_accepted_request', $r );
    abstract class BP_Invitation_Manager { 
    618622         *
    619623         * @since 5.0.0
    620624         *
    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.
    622627         * @return bool True on success, false on failure.
    623628         */
    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 );
    626631        }
    627632
    628633        /**
    abstract class BP_Invitation_Manager { 
    635640         * @see BP_Invitation::mark_accepted_by_data()
    636641         *      for a description of arguments.
    637642         */
    638         public function mark_accepted( $args ) {
     643        public function mark_accepted( $args, $passed_args ) {
    639644                $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 );
    641646        }
    642647
    643648        /** 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 { 
    640640                        }
    641641                }
    642642
     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
    643649                return $where_clauses;
    644650        }
    645651
    class BP_Invitation { 
    968974         *
    969975         * @since 5.0.0
    970976         *
    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.
    972980         */
    973         public static function mark_sent( $id = 0 ) {
     981        public static function mark_sent( $id = 0, $args = array() ) {
    974982
    975983                if ( ! $id ) {
    976984                        return false;
    class BP_Invitation { 
    978986
    979987                // Values to be updated.
    980988                $update_args = array(
    981                         'invite_sent' => 'sent',
     989                        'invite_sent'   => 'sent',
     990                        'date_modified' => bp_core_current_time(),
    982991                );
     992                // Respect a specified `date-modified`
     993                if ( ! empty( $args['date_modified'] ) ) {
     994                        $update_args['date_modified'] = $args['date_modified'];
     995                }
    983996
    984997                // WHERE clauses.
    985998                $where_args = array(
    class BP_Invitation { 
    9951008         *
    9961009         * @since 5.0.0
    9971010         *
    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.
    9991014         */
    1000         public static function mark_sent_by_data( $args ) {
     1015        public static function mark_sent_by_data( $args, $passed_args = array() ) {
    10011016
    10021017                // Values to be updated.
    10031018                $update_args = array(
    1004                         'invite_sent' => 'sent',
     1019                        'invite_sent'   => 'sent',
     1020                        'date_modified' => bp_core_current_time(),
    10051021                );
     1022                // Respect a specified `date-modified`
     1023                if ( ! empty( $passed_args['date_modified'] ) ) {
     1024                        $update_args['date_modified'] = $passed_args['date_modified'];
     1025                }
    10061026
    10071027                return self::update( $update_args, $args );
    10081028        }
    class BP_Invitation { 
    10141034         *
    10151035         * @since 5.0.0
    10161036         *
    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.
    10181040         */
    1019         public static function mark_accepted( $id = 0 ) {
     1041        public static function mark_accepted( $id = 0, $args = array() ) {
    10201042
    10211043                if ( ! $id ) {
    10221044                        return false;
    class BP_Invitation { 
    10241046
    10251047                // Values to be updated.
    10261048                $update_args = array(
    1027                         'accepted' => 'accepted',
     1049                        'accepted'      => 'accepted',
     1050                        'date_modified' => bp_core_current_time(),
    10281051                );
     1052                // Respect a specified `date-modified`
     1053                if ( ! empty( $args['date_modified'] ) ) {
     1054                        $update_args['date_modified'] = $args['date_modified'];
     1055                }
    10291056
    10301057                // WHERE clauses.
    10311058                $where_args = array(
    class BP_Invitation { 
    10411068         *
    10421069         * @since 5.0.0
    10431070         *
    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.
    10451074         */
    1046         public static function mark_accepted_by_data( $args ) {
     1075        public static function mark_accepted_by_data( $args, $passed_args = array() ) {
    10471076
    10481077                // Values to be updated.
    10491078                $update_args = array(
    1050                         'accepted' => 'accepted',
     1079                        'accepted'      => 'accepted',
     1080                        'date_modified' => bp_core_current_time(),
    10511081                );
     1082                // Respect a specified `date-modified`
     1083                if ( ! empty( $args['date_modified'] ) ) {
     1084                        $update_args['date_modified'] = $args['date_modified'];
     1085                }
    10521086
    10531087                return self::update( $update_args, $args );
    10541088        }
  • 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 ) { 
    20442044
    20452045        // If a new request was created, send the emails.
    20462046        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 );
    20482048                $admins = groups_get_group_admins( $r['group_id'] );
    20492049
    20502050                /**
  • 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 { 
    140140         *
    141141         * @param array $args.
    142142         */
    143         public function mark_accepted( $args ) {
     143        public function mark_accepted( $args, $passed_args ) {
    144144                // Delete all existing invitations/requests to this group for this user.
    145145                $this->delete( array(
    146146                        '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'; 
    332332                $this->set_current_user( $old_current_user );
    333333        }
    334334
     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
    335383}