<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[BuddyPress][7854] trunk: Migrate activity meta functions to the WP metadata API.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://buddypress.trac.wordpress.org/changeset/7854">7854</a></dd>
<dt>Author</dt> <dd>boonebgorges</dd>
<dt>Date</dt> <dd>2014-02-11 20:22:05 +0000 (Tue, 11 Feb 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Migrate activity meta functions to the WP metadata API.
See <a href="http://buddypress.trac.wordpress.org/ticket/4551">#4551</a>
Props boonebgorges, johnjamesjacoby</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpactivitybpactivitycachephp">trunk/bp-activity/bp-activity-cache.php</a></li>
<li><a href="#trunkbpactivitybpactivityclassesphp">trunk/bp-activity/bp-activity-classes.php</a></li>
<li><a href="#trunkbpactivitybpactivityfunctionsphp">trunk/bp-activity/bp-activity-functions.php</a></li>
<li><a href="#trunkbpactivitybpactivityloaderphp">trunk/bp-activity/bp-activity-loader.php</a></li>
<li><a href="#trunkbploaderphp">trunk/bp-loader.php</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkbpcoredeprecated20php">trunk/bp-core/deprecated/2.0.php</a></li>
<li><a href="#trunkteststestcasesactivitycachephp">trunk/tests/testcases/activity/cache.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpactivitybpactivitycachephp"></a>
<div class="modfile"><h4>Modified: trunk/bp-activity/bp-activity-cache.php (7853 => 7854)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-activity/bp-activity-cache.php 2014-02-11 19:42:58 UTC (rev 7853)
+++ trunk/bp-activity/bp-activity-cache.php 2014-02-11 20:22:05 UTC (rev 7854)
</span><span class="lines">@@ -30,6 +30,7 @@
</span><span class="cx"> 'object_ids' => $activity_ids,
</span><span class="cx"> 'object_type' => $bp->activity->id,
</span><span class="cx"> 'object_column' => 'activity_id',
</span><ins>+ 'cache_group' => 'activity_meta',
</ins><span class="cx"> 'meta_table' => $bp->activity->table_name_meta,
</span><span class="cx"> 'cache_key_prefix' => 'bp_activity_meta'
</span><span class="cx"> );
</span><span class="lines">@@ -38,23 +39,6 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Clear the cache for all metadata of a given activity.
- *
- * @param int $activity_id
- */
-function bp_activity_clear_meta_cache_for_activity( $activity_id ) {
- global $wp_object_cache;
-
- if ( is_object( $wp_object_cache ) && ! empty( $wp_object_cache->cache['bp'] ) ) {
- foreach ( $wp_object_cache->cache['bp'] as $ckey => $cvalue ) {
- if ( 0 === strpos( $ckey, 'bp_activity_meta_' . $activity_id ) ) {
- wp_cache_delete( $ckey, 'bp' );
- }
- }
- }
-}
-
-/**
</del><span class="cx"> * Clear a cached activity item when that item is updated.
</span><span class="cx"> *
</span><span class="cx"> * @since 2.0
</span></span></pre></div>
<a id="trunkbpactivitybpactivityclassesphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-activity/bp-activity-classes.php (7853 => 7854)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-activity/bp-activity-classes.php 2014-02-11 19:42:58 UTC (rev 7853)
+++ trunk/bp-activity/bp-activity-classes.php 2014-02-11 20:22:05 UTC (rev 7854)
</span><span class="lines">@@ -824,15 +824,13 @@
</span><span class="cx"> * @return bool True on success.
</span><span class="cx"> */
</span><span class="cx"> public static function delete_activity_meta_entries( $activity_ids = array() ) {
</span><del>- global $bp, $wpdb;
</del><ins>+ $activity_ids = wp_parse_id_list( $activity_ids );
</ins><span class="cx">
</span><del>- $activity_ids = implode( ',', wp_parse_id_list( $activity_ids ) );
-
- foreach ( (array) $activity_ids as $activity_id ) {
- bp_activity_clear_meta_cache_for_activity( $activity_id );
</del><ins>+ foreach ( $activity_ids as $activity_id ) {
+ bp_activity_delete_meta( $activity_id );
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- return $wpdb->query( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id IN ({$activity_ids})" );
</del><ins>+ return true;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span></span></pre></div>
<a id="trunkbpactivitybpactivityfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-activity/bp-activity-functions.php (7853 => 7854)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-activity/bp-activity-functions.php 2014-02-11 19:42:58 UTC (rev 7853)
+++ trunk/bp-activity/bp-activity-functions.php 2014-02-11 20:22:05 UTC (rev 7854)
</span><span class="lines">@@ -556,45 +556,32 @@
</span><span class="cx"> function bp_activity_delete_meta( $activity_id, $meta_key = '', $meta_value = '' ) {
</span><span class="cx"> global $wpdb, $bp;
</span><span class="cx">
</span><del>- // Return false if any of the above values are not set
- if ( !is_numeric( $activity_id ) )
</del><ins>+ // Legacy - Return false if any of the above values are not set
+ if ( ! is_numeric( $activity_id ) ) {
</ins><span class="cx"> return false;
</span><ins>+ }
</ins><span class="cx">
</span><del>- // Sanitize key
</del><ins>+ // Legacy - Sanitize key
</ins><span class="cx"> $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
</span><span class="cx">
</span><del>- if ( is_array( $meta_value ) || is_object( $meta_value ) )
- $meta_value = serialize( $meta_value );
-
- // Trim off whitespace
</del><ins>+ // Legacy - Trim off whitespace
</ins><span class="cx"> $meta_value = trim( $meta_value );
</span><span class="cx">
</span><del>- // Delete all for activity_id
- if ( empty( $meta_key ) )
- $retval = $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id = %d", $activity_id ) );
-
- // Delete only when all match
- else if ( $meta_value )
- $retval = $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id = %d AND meta_key = %s AND meta_value = %s", $activity_id, $meta_key, $meta_value ) );
-
- // Delete only when activity_id and meta_key match
- else
- $retval = $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id = %d AND meta_key = %s", $activity_id, $meta_key ) );
-
- // Delete cache entry
- if ( $meta_key ) {
- wp_cache_delete( 'bp_activity_meta_' . $activity_id . '_' . $meta_key, 'bp' );
</del><ins>+ // Legacy - if no meta_key is passed, delete all for the item
+ if ( empty( $meta_key ) ) {
+ $all_meta = bp_activity_get_meta( $activity_id );
+ $keys = ! empty( $all_meta ) ? wp_list_pluck( $all_meta, 'meta_key' ) : array();
</ins><span class="cx"> } else {
</span><del>- bp_activity_clear_meta_cache_for_activity( $activity_id );
</del><ins>+ $keys = array( $meta_key );
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- // Success
- if ( !is_wp_error( $retval ) )
- return true;
</del><ins>+ add_filter( 'query', 'bp_filter_metaid_column_name' );
+ foreach ( $keys as $key ) {
+ $retval = delete_metadata( 'activity', $activity_id, $key, $meta_value );
+ }
+ remove_filter( 'query', 'bp_filter_metaid_column_name' );
</ins><span class="cx">
</span><del>- // Fail
- else
- return false;
</del><ins>+ return $retval;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -602,10 +589,6 @@
</span><span class="cx"> *
</span><span class="cx"> * @since BuddyPress (1.2)
</span><span class="cx"> *
</span><del>- * @global object $wpdb WordPress database access object.
- * @global object $bp BuddyPress global settings.
- * @uses wp_cache_get()
- * @uses wp_cache_set()
</del><span class="cx"> * @uses apply_filters() To call the 'bp_activity_get_meta' hook.
</span><span class="cx"> *
</span><span class="cx"> * @param int $activity_id ID of the activity item whose metadata is being requseted.
</span><span class="lines">@@ -614,53 +597,46 @@
</span><span class="cx"> * metadata for the activity item will be fetched.
</span><span class="cx"> * @return mixed The meta value(s) being requested.
</span><span class="cx"> */
</span><del>-function bp_activity_get_meta( $activity_id = 0, $meta_key = '' ) {
- global $wpdb, $bp;
</del><ins>+function bp_activity_get_meta( $activity_id = 0, $meta_key = '', $single = true ) {
</ins><span class="cx">
</span><span class="cx"> // Make sure activity_id is valid
</span><del>- if ( empty( $activity_id ) || !is_numeric( $activity_id ) )
</del><ins>+ if ( empty( $activity_id ) || ! is_numeric( $activity_id ) ) {
</ins><span class="cx"> return false;
</span><ins>+ }
</ins><span class="cx">
</span><del>- // We have a key to look for
- if ( !empty( $meta_key ) ) {
</del><ins>+ // Legacy - Sanitize keys
+ $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
</ins><span class="cx">
</span><del>- // Sanitize key
- $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
</del><ins>+ add_filter( 'query', 'bp_filter_metaid_column_name' );
+ $retval = get_metadata( 'activity', $activity_id, $meta_key, $single );
+ remove_filter( 'query', 'bp_filter_metaid_column_name' );
</ins><span class="cx">
</span><del>- // Check cache
- if ( !$metas = wp_cache_get( 'bp_activity_meta_' . $activity_id . '_' . $meta_key, 'bp' ) ) {
- // No cache so hit the DB
- $metas = $wpdb->get_col( $wpdb->prepare("SELECT meta_value FROM {$bp->activity->table_name_meta} WHERE activity_id = %d AND meta_key = %s", $activity_id, $meta_key ) );
-
- // Set cache
- wp_cache_set( 'bp_activity_meta_' . $activity_id . '_' . $meta_key, $metas, 'bp' );
</del><ins>+ // Legacy - If fetching all meta for a group, just return the first
+ // of each found value
+ if ( empty( $meta_key ) ) {
+ $values = array();
+ foreach ( (array) $retval as $rkey => $rvalue ) {
+ $found = new stdClass;
+ $found->meta_key = $rkey;
+ $found->meta_value = array_pop( array_reverse( $rvalue ) );
+ $values[] = $found;
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- // No key so get all for activity_id
- } else {
- $metas = $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value FROM {$bp->activity->table_name_meta} WHERE activity_id = %d", $activity_id ) );
-
- if ( !empty( $metas ) ) {
- $metas = array_map( 'maybe_unserialize', (array) $metas );
-
- foreach( $metas as $mkey => $mvalue ) {
- wp_cache_set( 'bp_activity_meta_' . $activity_id . '_' . $mkey, $mvalue, 'bp' );
- }
</del><ins>+ // If nothing was found, return false
+ if ( empty( $values ) ) {
+ $retval = false;
+ } else {
+ $retval = $values;
</ins><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><del>- // No result so return false
- if ( empty( $metas ) )
- return false;
</del><ins>+ // Legacy - On failure, expect false, not an empty string
+ if ( '' === $retval ) {
+ $retval = false;
+ }
</ins><span class="cx">
</span><del>- // Maybe, just maybe... unserialize
- $metas = array_map( 'maybe_unserialize', (array) $metas );
-
- // Return first item in array if only 1, else return all metas found
- $retval = ( 1 == count( $metas ) ? $metas[0] : $metas );
-
</del><span class="cx"> // Filter result before returning
</span><del>- return apply_filters( 'bp_activity_get_meta', $retval, $activity_id, $meta_key );
</del><ins>+ return apply_filters( 'bp_activity_get_meta', $retval, $activity_id, $meta_key, $single );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -668,59 +644,31 @@
</span><span class="cx"> *
</span><span class="cx"> * @since BuddyPress (1.2)
</span><span class="cx"> *
</span><del>- * @global object $wpdb WordPress database access object.
- * @global object $bp BuddyPress global settings.
- * @uses maybe_serialize()
- * @uses bp_activity_delete_meta()
- * @uses wp_cache_set()
- *
</del><span class="cx"> * @param int $activity_id ID of the activity item whose metadata is being updated.
</span><span class="cx"> * @param string $meta_key Key of the metadata being updated.
</span><span class="cx"> * @param mixed $meta_value Value to be set.
</span><span class="cx"> * @return bool True on success, false on failure.
</span><span class="cx"> */
</span><span class="cx"> function bp_activity_update_meta( $activity_id, $meta_key, $meta_value ) {
</span><del>- global $wpdb, $bp;
</del><span class="cx">
</span><del>- // Make sure activity_id is valid
- if ( !is_numeric( $activity_id ) )
</del><ins>+ // Legacy - Make sure activity_id is valid
+ if ( ! is_numeric( $activity_id ) ) {
</ins><span class="cx"> return false;
</span><ins>+ }
</ins><span class="cx">
</span><del>- // Sanitize key
</del><ins>+ // Legacy - Sanitize key
</ins><span class="cx"> $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
</span><span class="cx">
</span><del>- // Sanitize value
- if ( is_string( $meta_value ) ) {
- $meta_value = stripslashes( $meta_value );
</del><ins>+ add_filter( 'query', 'bp_filter_metaid_column_name' );
+ $retval = update_metadata( 'activity', $activity_id, $meta_key, $meta_value );
+ remove_filter( 'query', 'bp_filter_metaid_column_name' );
+
+ // Legacy - return true if we fall through to add_metadata()
+ if ( is_int( $retval ) ) {
+ $retval = true;
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- // Maybe, just maybe... serialize
- $meta_value = maybe_serialize( $meta_value );
-
- // If value is false, delete the meta key
- if ( false === $meta_value )
- return bp_activity_delete_meta( $activity_id, $meta_key );
-
- // See if meta key exists for activity_id
- $cur = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name_meta} WHERE activity_id = %d AND meta_key = %s", $activity_id, $meta_key ) );
-
- // Meta key does not exist so INSERT
- if ( empty( $cur ) )
- $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->activity->table_name_meta} ( activity_id, meta_key, meta_value ) VALUES ( %d, %s, %s )", $activity_id, $meta_key, $meta_value ) );
-
- // Meta key exists, so UPDATE
- else if ( $cur->meta_value != $meta_value )
- $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name_meta} SET meta_value = %s WHERE activity_id = %d AND meta_key = %s", $meta_value, $activity_id, $meta_key ) );
-
- // Weirdness, so return false
- else
- return false;
-
- // Set cache
- wp_cache_set( 'bp_activity_meta_' . $activity_id . '_' . $meta_key, $meta_value, 'bp' );
-
- // Victory is ours!
- return true;
</del><ins>+ return $retval;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /** Clean up *****************************************************************/
</span></span></pre></div>
<a id="trunkbpactivitybpactivityloaderphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-activity/bp-activity-loader.php (7853 => 7854)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-activity/bp-activity-loader.php 2014-02-11 19:42:58 UTC (rev 7853)
+++ trunk/bp-activity/bp-activity-loader.php 2014-02-11 20:22:05 UTC (rev 7854)
</span><span class="lines">@@ -95,15 +95,21 @@
</span><span class="cx"> 'table_name_meta' => $bp->table_prefix . 'bp_activity_meta',
</span><span class="cx"> );
</span><span class="cx">
</span><ins>+ // Metadata tables for groups component
+ $meta_tables = array(
+ 'activity' => $bp->table_prefix . 'bp_activity_meta',
+ );
+
</ins><span class="cx"> // All globals for activity component.
</span><span class="cx"> // Note that global_tables is included in this array.
</span><span class="cx"> $args = array(
</span><span class="cx"> 'slug' => BP_ACTIVITY_SLUG,
</span><span class="cx"> 'root_slug' => isset( $bp->pages->activity->slug ) ? $bp->pages->activity->slug : BP_ACTIVITY_SLUG,
</span><span class="cx"> 'has_directory' => true,
</span><ins>+ 'notification_callback' => 'bp_activity_format_notifications',
</ins><span class="cx"> 'search_string' => __( 'Search Activity...', 'buddypress' ),
</span><span class="cx"> 'global_tables' => $global_tables,
</span><del>- 'notification_callback' => 'bp_activity_format_notifications',
</del><ins>+ 'meta_tables' => $meta_tables,
</ins><span class="cx"> );
</span><span class="cx">
</span><span class="cx"> parent::setup_globals( $args );
</span></span></pre></div>
<a id="trunkbpcoredeprecated20php"></a>
<div class="addfile"><h4>Added: trunk/bp-core/deprecated/2.0.php (0 => 7854)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-core/deprecated/2.0.php (rev 0)
+++ trunk/bp-core/deprecated/2.0.php 2014-02-11 20:22:05 UTC (rev 7854)
</span><span class="lines">@@ -0,0 +1,8 @@
</span><ins>+<?php
+
+/**
+ * @deprecated BuddyPress (2.0.0)
+ */
+function bp_activity_clear_meta_cache_for_activity() {
+ _deprecated_function( __FUNCTION__, '2.0.0', 'Use WP metadata API instead' );
+}
</ins></span></pre></div>
<a id="trunkbploaderphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-loader.php (7853 => 7854)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-loader.php 2014-02-11 19:42:58 UTC (rev 7853)
+++ trunk/bp-loader.php 2014-02-11 20:22:05 UTC (rev 7854)
</span><span class="lines">@@ -453,6 +453,7 @@
</span><span class="cx"> require( $this->plugin_dir . 'bp-core/deprecated/1.5.php' );
</span><span class="cx"> require( $this->plugin_dir . 'bp-core/deprecated/1.6.php' );
</span><span class="cx"> require( $this->plugin_dir . 'bp-core/deprecated/1.7.php' );
</span><ins>+ require( $this->plugin_dir . 'bp-core/deprecated/2.0.php' );
</ins><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkteststestcasesactivitycachephp"></a>
<div class="addfile"><h4>Added: trunk/tests/testcases/activity/cache.php (0 => 7854)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/tests/testcases/activity/cache.php (rev 0)
+++ trunk/tests/testcases/activity/cache.php 2014-02-11 20:22:05 UTC (rev 7854)
</span><span class="lines">@@ -0,0 +1,93 @@
</span><ins>+<?php
+
+/**
+ * @group activity
+ * @group cache
+ */
+class BP_Tests_Activity_Cache extends BP_UnitTestCase {
+ /**
+ * @group bp_activity_update_meta_cache
+ */
+ public function test_bp_activity_update_meta_cache() {
+ $a1 = $this->factory->activity->create();
+ $a2 = $this->factory->activity->create();
+
+ // Set up some data
+ bp_activity_update_meta( $a1, 'foo', 'bar' );
+ bp_activity_update_meta( $a1, 'Boone', 'Rules' );
+
+ bp_activity_update_meta( $a2, 'foo', 'baz' );
+ bp_activity_update_meta( $a2, 'BuddyPress', 'Is Cool' );
+
+ // Prime the cache for $a1
+ bp_activity_get_meta( $a1, 'foo' );
+
+ // Ensure an empty cache for $a2
+ wp_cache_delete( $a2, 'activity_meta' );
+
+ bp_activity_update_meta_cache( array( $a1, $a2 ) );
+
+ $expected = array(
+ $a1 => array(
+ 'foo' => array(
+ 'bar',
+ ),
+ 'Boone' => array(
+ 'Rules',
+ ),
+ ),
+ $a2 => array(
+ 'foo' => array(
+ 'baz',
+ ),
+ 'BuddyPress' => array(
+ 'Is Cool',
+ ),
+ ),
+ );
+
+ $found = array(
+ $a1 => wp_cache_get( $a1, 'activity_meta' ),
+ $a2 => wp_cache_get( $a2, 'activity_meta' ),
+ );
+
+ $this->assertEquals( $expected, $found );
+ }
+
+ /**
+ * @group groups_update_groupmeta
+ * @group groups_delete_group_cache_on_metadata_change
+ */
+ public function test_bp_groups_delete_group_cache_on_metadata_add() {
+ $g = $this->factory->group->create();
+
+ // Prime cache
+ groups_get_group( array( 'group_id' => $g ) );
+
+ $this->assertNotEmpty( wp_cache_get( 'bp_groups_group_' . $g . '_noload_users', 'bp' ) );
+
+ // Trigger flush
+ groups_update_groupmeta( $g, 'foo', 'bar' );
+
+ $this->assertFalse( wp_cache_get( 'bp_groups_group_' . $g . '_noload_users', 'bp' ) );
+ }
+
+ /**
+ * @group groups_update_groupmeta
+ * @group groups_delete_group_cache_on_metadata_change
+ */
+ public function test_bp_groups_delete_group_cache_on_metadata_change() {
+ $g = $this->factory->group->create();
+
+ // Prime cache
+ groups_update_groupmeta( $g, 'foo', 'bar' );
+ groups_get_group( array( 'group_id' => $g ) );
+
+ $this->assertNotEmpty( wp_cache_get( 'bp_groups_group_' . $g . '_noload_users', 'bp' ) );
+
+ // Trigger flush
+ groups_update_groupmeta( $g, 'foo', 'baz' );
+ $this->assertFalse( wp_cache_get( 'bp_groups_group_' . $g . '_noload_users', 'bp' ) );
+ }
+
+}
</ins></span></pre>
</div>
</div>
</body>
</html>