Skip to:
Content

BuddyPress.org

Changeset 10788


Ignore:
Timestamp:
05/19/2016 05:43:23 PM (9 years ago)
Author:
r-a-y
Message:

Notifications: Make notification meta great again.

This commit fixes this for the betterment of notifications everywhere.

Fixes #7067.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-notifications/bp-notifications-functions.php

    r10725 r10788  
    702702    add_filter( 'query', 'bp_filter_metaid_column_name' );
    703703    foreach ( $keys as $key ) {
    704         $retval = delete_metadata( 'notifications', $notification_id, $key, $meta_value, $delete_all );
     704        $retval = delete_metadata( 'notification', $notification_id, $key, $meta_value, $delete_all );
    705705    }
    706706    remove_filter( 'query', 'bp_filter_metaid_column_name' );
     
    727727function bp_notifications_get_meta( $notification_id = 0, $meta_key = '', $single = true ) {
    728728    add_filter( 'query', 'bp_filter_metaid_column_name' );
    729     $retval = get_metadata( 'notifications', $notification_id, $meta_key, $single );
     729    $retval = get_metadata( 'notification', $notification_id, $meta_key, $single );
    730730    remove_filter( 'query', 'bp_filter_metaid_column_name' );
    731731
     
    762762function bp_notifications_update_meta( $notification_id, $meta_key, $meta_value, $prev_value = '' ) {
    763763    add_filter( 'query', 'bp_filter_metaid_column_name' );
    764     $retval = update_metadata( 'notifications', $notification_id, $meta_key, $meta_value, $prev_value );
     764    $retval = update_metadata( 'notification', $notification_id, $meta_key, $meta_value, $prev_value );
    765765    remove_filter( 'query', 'bp_filter_metaid_column_name' );
    766766
     
    783783function bp_notifications_add_meta( $notification_id, $meta_key, $meta_value, $unique = false ) {
    784784    add_filter( 'query', 'bp_filter_metaid_column_name' );
    785     $retval = add_metadata( 'notifications', $notification_id, $meta_key, $meta_value, $unique );
     785    $retval = add_metadata( 'notification', $notification_id, $meta_key, $meta_value, $unique );
    786786    remove_filter( 'query', 'bp_filter_metaid_column_name' );
    787787
  • trunk/src/bp-notifications/classes/class-bp-notifications-component.php

    r10675 r10788  
    8383        );
    8484
     85        // Metadata tables for notifications component.
     86        $meta_tables = array(
     87            'notification' => $bp->table_prefix . 'bp_notifications_meta',
     88        );
     89
    8590        // All globals for the notifications component.
    8691        // Note that global_tables is included in this array.
     
    9095            'search_string' => __( 'Search Notifications...', 'buddypress' ),
    9196            'global_tables' => $global_tables,
     97            'meta_tables'   => $meta_tables
    9298        );
    9399
  • trunk/tests/phpunit/testcases/notifications/functions.php

    r10437 r10788  
    122122
    123123        $this->assertFalse( wp_cache_get( 'all_for_user_' . $u, 'bp_notifications' ) );
     124    }
     125
     126    /**
     127     * @group bp_notifications_update_meta_cache
     128     */
     129    public function test_bp_notifications_update_meta_cache() {
     130        $u = $this->factory->user->create();
     131
     132        $n1 = $this->factory->notification->create( array(
     133            'component_name' => 'messages',
     134            'user_id'        => $u
     135        ) );
     136
     137        $n2 = $this->factory->notification->create( array(
     138            'component_name' => 'groups',
     139            'user_id'        => $u
     140        ) );
     141
     142        // Add cache for each notification.
     143        bp_notifications_update_meta( $n1, 'meta', 'data' );
     144        bp_notifications_update_meta( $n1, 'data', 'meta' );
     145        bp_notifications_update_meta( $n2, 'meta', 'human' );
     146
     147        // Prime cache.
     148        bp_notifications_get_meta( $n1, 'meta' );
     149
     150        // Ensure an empty cache for second notification.
     151        wp_cache_delete( $n2, 'notification_meta' );
     152
     153        // Update notification meta cache.
     154        bp_notifications_update_meta_cache( array( $n1, $n2 ) );
     155
     156        $expected = array(
     157            $n1 => array(
     158                'meta' => array(
     159                    'data',
     160                ),
     161                'data' => array(
     162                    'meta',
     163                ),
     164            ),
     165            $n2 => array(
     166                'meta' => array(
     167                    'human',
     168                ),
     169            ),
     170        );
     171
     172        $found = array(
     173            $n1 => wp_cache_get( $n1, 'notification_meta' ),
     174            $n2 => wp_cache_get( $n2, 'notification_meta' ),
     175        );
     176
     177        $this->assertEquals( $expected, $found );
    124178    }
    125179
Note: See TracChangeset for help on using the changeset viewer.