Skip to:
Content

BuddyPress.org

Ticket #8637: 8637.diff

File 8637.diff, 4.3 KB (added by oztaser, 22 months ago)
  • src/bp-notifications/bp-notifications-cache.php

    diff --git src/bp-notifications/bp-notifications-cache.php src/bp-notifications/bp-notifications-cache.php
    index f948daef3..4ab0ca5d7 100644
    function bp_notifications_clear_all_for_user_cache_before_update( $update_args, 
    104104        }
    105105}
    106106add_action( 'bp_notification_before_update', 'bp_notifications_clear_all_for_user_cache_before_update', 10, 2 );
     107
     108/**
     109 * Invalidate the 'all_for_user_' cache when deleting notifications by id list.
     110 *
     111 * @since 10.1.0
     112 *
     113 * @param string $field The name of the db field of the items to delete.
     114 *                      Possible values are `id` or `item_id`.
     115 * @param int[]  $items The list of items to delete.
     116 * @param array  $args  The WHERE arguments to use to specify the item IDs to delete.
     117 */
     118function bp_notifications_clear_all_for_user_cache_before_delete_by_id_list( $field, $items, $args ) {
     119        $args[ $field ] = $items;
     120
     121        $notifications = BP_Notifications_Notification::get( $args );
     122        $user_ids      = wp_parse_id_list( wp_list_pluck( $notifications, 'user_id' ) );
     123
     124        foreach ( $user_ids as $user_id ) {
     125                bp_notifications_clear_all_for_user_cache( $user_id );
     126        }
     127}
     128add_action( 'bp_notification_before_delete_by_id_list', 'bp_notifications_clear_all_for_user_cache_before_delete_by_id_list', 10, 3 );
     129
     130/**
     131 * Invalidate the 'all_for_user_' cache when updating notifications by id list.
     132 *
     133 * @since 10.1.0
     134 *
     135 * @param string $field The name of the db field of the items to update.
     136 *                      Possible values are `id` or `item_id`.
     137 * @param int[]  $items The list of items to update.
     138 * @param array  $data  Array of notification data to update.
     139 * @param array  $where The WHERE params to use to specify the item IDs to update.
     140 */
     141function bp_notifications_clear_all_for_user_cache_before_update_id_list( $field, $items, $data, $where ) {
     142        $where[ $field ] = $items;
     143
     144        $notifications = BP_Notifications_Notification::get( $where );
     145        $user_ids      = wp_parse_id_list( wp_list_pluck( $notifications, 'user_id' ) );
     146
     147        foreach ( $user_ids as $user_id ) {
     148                bp_notifications_clear_all_for_user_cache( $user_id );
     149        }
     150}
     151add_action( 'bp_notification_before_update_id_list', 'bp_notifications_clear_all_for_user_cache_before_update_id_list', 10, 4 );
  • src/bp-notifications/classes/class-bp-notifications-notification.php

    diff --git src/bp-notifications/classes/class-bp-notifications-notification.php src/bp-notifications/classes/class-bp-notifications-notification.php
    index 9d5c1ebae..1bfc40555 100644
    class BP_Notifications_Notification { 
    941941                        $values[] = $value;
    942942                }
    943943
    944                 foreach ( $where_args['data'] as $field => $value ) {
    945                         $index  = array_search( $field, array_keys( $where_args['data'] ) );
     944                foreach ( $where_args['data'] as $where_field => $value ) {
     945                        $index  = array_search( $where_field, array_keys( $where_args['data'] ) );
    946946                        $format = $where_args['format'][ $index ];
    947947
    948                         $conditions[] = "{$field} = {$format}";
     948                        $conditions[] = "{$where_field} = {$format}";
    949949                        $values[]     = $value;
    950950                }
    951951
    class BP_Notifications_Notification { 
    955955                /** This action is documented in bp-notifications/classes/class-bp-notifications-notification.php */
    956956                do_action( 'bp_notification_before_update', $update_args, $where_args );
    957957
     958                /** This action is documented in bp-notifications/classes/class-bp-notifications-notification.php */
     959                do_action( 'bp_notification_before_update_id_list', $field, $items, $data, $where, $update_args, $where_args );
     960
    958961                return $wpdb->query( $wpdb->prepare( "UPDATE {$bp->notifications->table_name} SET {$fields} WHERE {$conditions}", $values ) );
    959962        }
    960963
    class BP_Notifications_Notification { 
    10341037                /** This action is documented in bp-notifications/classes/class-bp-notifications-notification.php */
    10351038                do_action( 'bp_notification_before_delete', $args );
    10361039
     1040                /** This action is documented in bp-notifications/classes/class-bp-notifications-notification.php */
     1041                do_action( 'bp_notification_before_delete_by_id_list', $field, $items, $args );
     1042
    10371043                if ( ! $values ) {
    10381044                        return $wpdb->query( "DELETE FROM {$bp->notifications->table_name} WHERE {$conditions}" );
    10391045                }