Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/23/2021 11:31:33 PM (3 years ago)
Author:
dcavins
Message:

BP_Invitation: Increment date_modified on key actions.

When an invitation is sent or accepted, the date_modified
should be updated. However, if a date_modified has been
specified in the invitation or request creation function
(as we do in our unit test functions), the date_modified
should be set to that, even if notices are sent (now) as
part of the creation process.

Ensure that BP_Invitation::get_query_clauses() handles specified date_modified data updates.

Fixes #8444.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/classes/class-bp-invitation-manager.php

    r12793 r12873  
    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, $r );
    143143            if ( ! $sent ) {
    144144                return false;
     
    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          See BP_Invitation::mark_sent().
    158159     *
    159160     * @return int|bool The number of rows updated, or false on error.
    160161     */
    161     public function send_invitation_by_id( $invitation_id = 0 ) {
     162    public function send_invitation_by_id( $invitation_id = 0, $args = array() ) {
    162163        $updated = false;
    163164
     
    197198        $this->run_send_action( $invitation );
    198199
    199         $updated = BP_Invitation::mark_sent( $invitation->id );
     200        $updated = BP_Invitation::mark_sent( $invitation->id, $args );
    200201
    201202        return $updated;
     
    306307     * @access public
    307308     *
    308      * @param int $request_id ID of request to send.
     309     * @param int   $request_id ID of request to send.
     310     * @param array $args       See BP_Invitation::mark_sent().
    309311     *
    310312     * @return int|bool The number of rows updated, or false on error.
    311313     */
    312     public function send_request_notification_by_id( $request_id = 0 ) {
     314    public function send_request_notification_by_id( $request_id = 0, $args = array() ) {
    313315        $updated = false;
    314316
     
    326328         * A sent invitation + a request = acceptance.
    327329         */
    328         $args = array(
     330        $invite_args = array(
    329331            'user_id'           => $request->user_id,
    330332            'invitee_email'     => $request->invitee_email,
     
    333335            'invite_sent'       => 'sent'
    334336        );
    335         $invites = $this->invitation_exists( $args );
     337        $invites = $this->invitation_exists( $invite_args );
    336338
    337339        if ( ! empty( $invites ) ) {
    338340            // Accept the request.
    339             return $this->accept_invitation( $args );
     341            return $this->accept_invitation( $invite_args );
    340342        }
    341343
     
    343345        $this->run_send_action( $request );
    344346
    345         $updated = BP_Invitation::mark_sent( $request->id );
     347        $updated = BP_Invitation::mark_sent( $request->id, $args );
    346348
    347349        return $updated;
     
    453455     *      accepted update/where arguments.
    454456     *
    455      * @param array $update_args Associative array of fields to update,
    456      *              and the values to update them to. Of the format
    457      *              array( 'user_id' => 4 )
     457     * @param array $args {
     458     *     Invitation characteristics. Some basic info is required to accept an invitation,
     459     *     because we'll need to accept all similar invitations and requests.
     460     *
     461     *     @type int    $user_id           User ID of the invitee.
     462     *                                     Either 'user_id' or 'invitee_email' is required.
     463     *     @type string $invitee_email     Email address of the invitee.
     464     *                                     Either 'user_id' or 'invitee_email' is required.
     465     *     @type int    $item_id           Item ID of the invitation to accept.
     466     *     @type int    $secondary_item_id Optional. Secondary item ID if needed.
     467     *     @type string $invite_sent       Optional. Defaults to only allowing the
     468     *                                     acceptance of sent invitations.
     469     *     @type string $date_modified     Modified time in 'Y-m-d h:i:s' format, GMT.
     470     *                                     Defaults to current time if not specified.
     471     * }
    458472     *
    459473     * @return int|bool Number of rows updated on success, false on failure.
     
    461475     public function accept_invitation( $args = array() ) {
    462476
    463         /*
    464          * Some basic info is required to accept an invitation,
    465          * because we'll need to mark all similar invitations and requests.
    466          * The following, except the optional 'secondary_item_id', are required.
    467          */
    468477        $r = bp_parse_args( $args, array(
    469478            'user_id'           => 0,
     
    472481            'secondary_item_id' => null,
    473482            'invite_sent'       => 'sent',
     483            'date_modified'     => bp_core_current_time(),
    474484        ), 'accept_invitation' );
    475485        $r['class'] = $this->class_name;
     
    502512     *      accepted update/where arguments.
    503513     *
    504      * @param array $update_args Associative array of fields to update,
    505      *              and the values to update them to. Of the format
    506      *              array( 'user_id' => 4 )
     514     * @param array $args {
     515     *     Invitation characteristics. Some basic info is required to accept an invitation,
     516     *     because we'll need to accept all similar invitations and requests.
     517     *
     518     *     @type int    $user_id           User ID of the invitee.
     519     *     @type int    $item_id           Item ID of the invitation to accept.
     520     *     @type int    $secondary_item_id Optional. Secondary item ID if needed.
     521     *     @type string $date_modified     Modified time in 'Y-m-d h:i:s' format, GMT.
     522     *                                     Defaults to current time if not specified.
     523     * }
    507524     *
    508525     * @return bool Number of rows updated on success, false on failure.
    509526     */
    510527     public function accept_request( $args = array() ) {
    511         /*
    512          * Some basic info is required to accept an invitation,
    513          * because we'll need to accept all similar invitations and requests.
    514          * The following, except the optional 'secondary_item_id', are required.
    515          */
     528
    516529        $r = bp_parse_args( $args, array(
    517530            'user_id'           => 0,
    518531            'item_id'           => null,
    519532            'secondary_item_id' => null,
     533            'date_modified'     => bp_core_current_time(),
    520534        ), 'accept_request' );
    521535        $r['class'] = $this->class_name;
     
    619633     * @since 5.0.0
    620634     *
    621      * @param int $id The ID of the invitation to mark as sent.
     635     * @see BP_Invitation::mark_accepted()
     636     *      for a description of arguments.
    622637     * @return bool True on success, false on failure.
    623638     */
    624     public function mark_accepted_by_id( $id ) {
    625         return BP_Invitation::mark_accepted( $id );
     639    public function mark_accepted_by_id( $id, $args ) {
     640        return BP_Invitation::mark_accepted( $id, $args );
    626641    }
    627642
Note: See TracChangeset for help on using the changeset viewer.