Skip to:
Content

BuddyPress.org

Ticket #6257: 6257.01.patch

File 6257.01.patch, 9.7 KB (added by johnjamesjacoby, 10 years ago)

First pass - no unit tests

  • src/bp-core/admin/bp-core-admin-schema.php

     
    114114                                KEY useritem (user_id,is_new)
    115115                        ) {$charset_collate};";
    116116
     117        $sql[] = "CREATE TABLE {$bp_prefix}bp_notifications_meta (
     118                                id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
     119                                notification_id bigint(20) NOT NULL,
     120                                meta_key varchar(255) DEFAULT NULL,
     121                                meta_value longtext DEFAULT NULL,
     122                                KEY notification_id (notification_id),
     123                                KEY meta_key (meta_key)
     124                        ) {$charset_collate};";
     125
    117126        dbDelta( $sql );
    118127}
    119128
  • src/bp-core/bp-core-update.php

     
    211211                // Run the schema install to update tables
    212212                bp_core_install();
    213213
    214                 // 1.5
     214                // 1.5.0
    215215                if ( $raw_db_version < 1801 ) {
    216216                        bp_update_to_1_5();
    217217                        bp_core_add_page_mappings( $default_components, 'delete' );
    218218                }
    219219
    220                 // 1.6
     220                // 1.6.0
    221221                if ( $raw_db_version < 6067 ) {
    222222                        bp_update_to_1_6();
    223223                }
    224224
    225                 // 1.9
     225                // 1.9.0
    226226                if ( $raw_db_version < 7553 ) {
    227227                        bp_update_to_1_9();
    228228                }
     
    232232                        bp_update_to_1_9_2();
    233233                }
    234234
    235                 // 2.0
     235                // 2.0.0
    236236                if ( $raw_db_version < 7892 ) {
    237237                        bp_update_to_2_0();
    238238                }
     
    242242                        bp_update_to_2_0_1();
    243243                }
    244244
    245                 // 2.2
     245                // 2.2.0
    246246                if ( $raw_db_version < 9181 ) {
    247247                        bp_update_to_2_2();
    248248                }
     249
     250                // 2.3.0
     251                if ( $raw_db_version < 9572 ) {
     252                        bp_update_to_2_3();
     253                }
    249254        }
    250255
    251256        /** All done! *************************************************************/
     
    418423}
    419424
    420425/**
     426 * 2.3.0 update routine.
     427 *
     428 * - Add notifications meta table
     429 *
     430 * @since BuddyPress (2.3.0)
     431 */
     432function bp_update_to_2_3() {
     433        if ( bp_is_active( 'notifications' ) ) {
     434                bp_core_install_notifications();
     435        }
     436}
     437
     438/**
    421439 * Updates the component field for new_members type.
    422440 *
    423441 * @since BuddyPress (2.2.0)
  • src/bp-loader.php

     
    303303                /** Versions **********************************************************/
    304304
    305305                $this->version    = '2.3-alpha';
    306                 $this->db_version = 9181;
     306                $this->db_version = 9572;
    307307
    308308                /** Loading ***********************************************************/
    309309
  • src/bp-notifications/bp-notifications-cache.php

     
    77 */
    88
    99/**
     10 * Slurp up metadata for a set of notifications.
     11 *
     12 * It grabs all notification meta associated with all of the notifications
     13 * passed in $notification_ids and adds it to WP cache. This improves efficiency
     14 * when using notification meta within a loop context.
     15 *
     16 * @since BuddyPress (2.3.0)
     17 *
     18 * @param int|str|array $notification_ids Accepts a single notification_id, or a
     19 *                                        comma-separated list or array of
     20 *                                        notification ids.
     21 */
     22function bp_notifications_update_meta_cache( $notification_ids = false ) {
     23        bp_update_meta_cache( array(
     24                'object_ids'       => $notification_ids,
     25                'object_type'      => buddypress()->notifications->id,
     26                'cache_group'      => 'notification_meta',
     27                'object_column'    => 'notification_id',
     28                'meta_table'       => buddypress()->notifications->table_name_meta,
     29                'cache_key_prefix' => 'bp_notifications_meta'
     30        ) );
     31}
     32
     33/**
    1034 * Invalidate 'all_for_user_' cache when saving.
    1135 *
    1236 * @since BuddyPress (2.0.0)
  • src/bp-notifications/bp-notifications-functions.php

     
    611611         */
    612612        return apply_filters( 'bp_notifications_get_registered_components', $component_names, $active_components );
    613613}
     614
     615/** Meta **********************************************************************/
     616
     617/**
     618 * Delete a meta entry from the DB for a notification item.
     619 *
     620 * @since BuddyPress (2.3.0)
     621 *
     622 * @global object $wpdb WordPress database access object.
     623 *
     624 * @param int    $notification_id ID of the notification item whose metadata is being deleted.
     625 * @param string $meta_key        Optional. The key of the metadata being deleted. If
     626 *                                omitted, all metadata associated with the notification
     627 *                                item will be deleted.
     628 * @param string $meta_value      Optional. If present, the metadata will only be
     629 *                                deleted if the meta_value matches this parameter.
     630 * @param bool   $delete_all      Optional. If true, delete matching metadata entries
     631 *                                    for all objects, ignoring the specified object_id. Otherwise,
     632 *                                    only delete matching metadata entries for the specified
     633 *                                    notification item. Default: false.
     634 *
     635 * @return bool                   True on success, false on failure.
     636 */
     637function bp_notifications_delete_meta( $notification_id, $meta_key = '', $meta_value = '', $delete_all = false ) {
     638
     639        // Legacy - if no meta_key is passed, delete all for the item
     640        if ( empty( $meta_key ) ) {
     641                $all_meta = bp_notifications_get_meta( $notification_id );
     642                $keys     = ! empty( $all_meta )
     643                        ? array_keys( $all_meta )
     644                        : array();
     645
     646                // With no meta_key, ignore $delete_all
     647                $delete_all = false;
     648        } else {
     649                $keys = array( $meta_key );
     650        }
     651
     652        $retval = true;
     653
     654        add_filter( 'query', 'bp_filter_metaid_column_name' );
     655        foreach ( $keys as $key ) {
     656                $retval = delete_metadata( 'notifications', $notification_id, $key, $meta_value, $delete_all );
     657        }
     658        remove_filter( 'query', 'bp_filter_metaid_column_name' );
     659
     660        return $retval;
     661}
     662
     663/**
     664 * Get metadata for a given notification item.
     665 *
     666 * @since BuddyPress (2.3.0)
     667 *
     668 * @uses apply_filters() To call the 'bp_notifications_get_meta' hook.
     669 *
     670 * @param int    $notification_id ID of the notification item whose metadata is being requested.
     671 * @param string $meta_key        Optional. If present, only the metadata matching
     672 *                                that meta key will be returned. Otherwise, all metadata for the
     673 *                                notification item will be fetched.
     674 * @param bool   $single          Optional. If true, return only the first value of the
     675 *                                    specified meta_key. This parameter has no effect if meta_key is not
     676 *                                    specified. Default: true.
     677 *
     678 * @return mixed                  The meta value(s) being requested.
     679 */
     680function bp_notifications_get_meta( $notification_id = 0, $meta_key = '', $single = true ) {
     681        add_filter( 'query', 'bp_filter_metaid_column_name' );
     682        $retval = get_metadata( 'notifications', $notification_id, $meta_key, $single );
     683        remove_filter( 'query', 'bp_filter_metaid_column_name' );
     684
     685        /**
     686         * Filters the metadata for a specified notification item.
     687         *
     688         * @since BuddyPress (2.3.0)
     689         *
     690         * @param mixed  $retval          The meta values for the notification item.
     691         * @param int    $notification_id ID of the notification item.
     692         * @param string $meta_key        Meta key for the value being requested.
     693         * @param bool   $single          Whether to return one matched meta key row or all.
     694         */
     695        return apply_filters( 'bp_notifications_get_meta', $retval, $notification_id, $meta_key, $single );
     696}
     697
     698/**
     699 * Update a piece of notification meta.
     700 *
     701 * @since BuddyPress (1.2.0)
     702 *
     703 * @param  int    $notification_id ID of the notification item whose metadata is being
     704 *                                 updated.
     705 * @param  string $meta_key        Key of the metadata being updated.
     706 * @param  mixed  $meta_value      Value to be set.
     707 * @param  mixed  $prev_value      Optional. If specified, only update existing
     708 *                                 metadata entries with the specified value.
     709 *                                 Otherwise, update all entries.
     710 *
     711 * @return bool|int                Returns false on failure. On successful
     712 *                                 update of existing metadata, returns true. On
     713 *                                 successful creation of new metadata,  returns
     714 *                                 the integer ID of the new metadata row.
     715 */
     716function bp_notifications_update_meta( $notification_id, $meta_key, $meta_value, $prev_value = '' ) {
     717        add_filter( 'query', 'bp_filter_metaid_column_name' );
     718        $retval = update_metadata( 'notifications', $notification_id, $meta_key, $meta_value, $prev_value );
     719        remove_filter( 'query', 'bp_filter_metaid_column_name' );
     720
     721        return $retval;
     722}
     723
     724/**
     725 * Add a piece of notification metadata.
     726 *
     727 * @since BuddyPress (2.3.0)
     728 *
     729 * @param int    $notification_id ID of the notification item.
     730 * @param string $meta_key        Metadata key.
     731 * @param mixed  $meta_value      Metadata value.
     732 * @param bool   $unique          Optional. Whether to enforce a single metadata value
     733 *                                for the given key. If true, and the object already has a value for
     734 *                                the key, no change will be made. Default: false.
     735 *
     736 * @return int|bool               The meta ID on successful update, false on failure.
     737 */
     738function bp_notifications_add_meta( $notification_id, $meta_key, $meta_value, $unique = false ) {
     739        add_filter( 'query', 'bp_filter_metaid_column_name' );
     740        $retval = add_metadata( 'notifications', $notification_id, $meta_key, $meta_value, $unique );
     741        remove_filter( 'query', 'bp_filter_metaid_column_name' );
     742
     743        return $retval;
     744}
  • src/bp-notifications/bp-notifications-loader.php

     
    247247
    248248                // Global groups
    249249                wp_cache_add_global_groups( array(
    250                         'bp_notifications'
     250                        'bp_notifications',
     251                        'notification_meta'
    251252                ) );
    252253
    253254                parent::setup_cache_groups();