Ticket #3083: 3083.01.patch
| File 3083.01.patch, 14.5 KB (added by , 11 years ago) |
|---|
-
src/bp-core/admin/bp-core-schema.php
304 304 KEY is_active (is_active) 305 305 ) {$charset_collate};"; 306 306 307 $sql[] = "CREATE TABLE {$bp_prefix}bp_messages_meta ( 308 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY, 309 message_id bigint(20) NOT NULL, 310 meta_key varchar(255) DEFAULT NULL, 311 meta_value longtext DEFAULT NULL, 312 KEY message_id (message_id), 313 KEY meta_key (meta_key) 314 ) {$charset_collate};"; 315 307 316 dbDelta( $sql ); 308 317 } 309 318 -
src/bp-core/bp-core-update.php
241 241 if ( $raw_db_version < 8311 ) { 242 242 bp_update_to_2_0_1(); 243 243 } 244 245 // 2.0.1 246 if ( $raw_db_version < 9155 ) { 247 bp_update_to_2_2(); 248 } 244 249 } 245 250 246 251 /** All done! *************************************************************/ … … 390 395 } 391 396 392 397 /** 398 * 2.2.0 update routine. 399 * 400 * - Add messages meta table 401 * 402 * @since BuddyPress (2.0.0) 403 */ 404 function bp_update_to_2_2() { 405 if ( bp_is_active( 'messages' ) ) { 406 bp_core_install_private_messaging(); 407 } 408 } 409 410 /** 393 411 * Redirect user to BP's What's New page on first page load after activation. 394 412 * 395 413 * @since BuddyPress (1.7.0) -
src/bp-loader.php
301 301 /** Versions **********************************************************/ 302 302 303 303 $this->version = '2.2-alpha'; 304 $this->db_version = 8311;304 $this->db_version = 9155; 305 305 306 306 /** Loading ***********************************************************/ 307 307 -
src/bp-messages/bp-messages-cache.php
12 12 // Exit if accessed directly 13 13 if ( !defined( 'ABSPATH' ) ) exit; 14 14 15 /** 16 * Slurp up metadata for a set of messages. 17 * 18 * It grabs all message meta associated with all of the messages passed in 19 * $message_ids and adds it to WP cache. This improves efficiency when using 20 * message meta within a loop context. 21 * 22 * @since BuddyPress (2.2.0) 23 * 24 * @param int|str|array $message_ids Accepts a single message_id, or a 25 * comma-separated list or array of group ids. 26 */ 27 function bp_messages_update_meta_cache( $message_ids = false ) { 28 bp_update_meta_cache( array( 29 'object_ids' => $message_ids, 30 'object_type' => buddypress()->messages->id, 31 'cache_group' => 'message_meta', 32 'object_column' => 'message_id', 33 'meta_table' => buddypress()->messages->table_name_meta, 34 'cache_key_prefix' => 'bp_messages_groupmeta' 35 ) ); 36 } 37 15 38 // List actions to clear super cached pages on, if super cache is installed 16 39 add_action( 'messages_delete_thread', 'bp_core_clear_cache' ); 17 40 add_action( 'messages_send_notice', 'bp_core_clear_cache' ); -
src/bp-messages/bp-messages-classes.php
109 109 * 110 110 * @since BuddyPress (1.0.0) 111 111 * 112 * @param int $thread_id The message thread ID. 113 * @param string $order The order to sort the messages. Either 'ASC' or 'DESC'. 112 * @see BP_Messages_Thread::populate() for full description of parameters 114 113 */ 115 public function __construct( $thread_id = false, $order = 'ASC' ) {114 public function __construct( $thread_id = false, $order = 'ASC', $args = array() ) { 116 115 if ( $thread_id ) { 117 $this->populate( $thread_id, $order );116 $this->populate( $thread_id, $order, $args ); 118 117 } 119 118 } 120 119 … … 127 126 * 128 127 * @param int $thread_id The message thread ID. 129 128 * @param string $order The order to sort the messages. Either 'ASC' or 'DESC'. 129 * @param array $args { 130 * Array of arguments. 131 * @type bool $update_meta_cache Whether to pre-fetch metadata for 132 * queried message items. Default: true. 133 * } 130 134 */ 131 public function populate( $thread_id, $order ) {135 public function populate( $thread_id, $order = 'ASC', $args = array() ) { 132 136 global $wpdb, $bp; 133 137 134 138 if( 'ASC' != $order && 'DESC' != $order ) { 135 $order = 'ASC';139 $order = 'ASC'; 136 140 } 137 141 142 // merge $args with our defaults 143 $r = wp_parse_args( $args, array( 144 'update_meta_cache' => true 145 ) ); 146 138 147 $this->messages_order = $order; 139 148 $this->thread_id = $thread_id; 140 149 … … 153 162 if ( isset( $this->recipients[bp_loggedin_user_id()] ) ) { 154 163 $this->unread_count = $this->recipients[bp_loggedin_user_id()]->unread_count; 155 164 } 165 166 // Grab all message meta 167 if ( true === (bool) $r['update_meta_cache'] ) { 168 bp_messages_update_meta_cache( wp_list_pluck( $this->messages, 'id' ) ); 169 } 156 170 } 157 171 158 172 /** … … 212 226 // Mark messages as deleted 213 227 $wpdb->query( $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET is_deleted = 1 WHERE thread_id = %d AND user_id = %d", $thread_id, bp_loggedin_user_id() ) ); 214 228 215 // Get the message id in order to pass to the action216 $message_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_messages} WHERE thread_id = %d", $thread_id ) );229 // Get the message ids in order to pass to the action 230 $message_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_messages} WHERE thread_id = %d", $thread_id ) ); 217 231 218 232 // Check to see if any more recipients remain for this message 219 233 // if not, then delete the message from the database. … … 223 237 // Delete all the messages 224 238 $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->messages->table_name_messages} WHERE thread_id = %d", $thread_id ) ); 225 239 240 // Delete message meta 241 foreach ( $message_ids as $message_id ) { 242 bp_messages_delete_meta( $message_id ); 243 } 244 226 245 // Delete all the recipients 227 246 $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d", $thread_id ) ); 228 247 } 229 248 230 do_action( 'messages_thread_deleted_thread', $message_id );249 do_action( 'messages_thread_deleted_thread', $message_ids, $thread_id ); 231 250 232 251 return true; 233 252 } … … 290 309 291 310 $threads = false; 292 311 foreach ( (array) $sorted_threads as $thread_id => $date_sent ) { 293 $threads[] = new BP_Messages_Thread( $thread_id ); 312 $threads[] = new BP_Messages_Thread( $thread_id, 'ASC', array( 313 // need some feedback here... 314 // what are the chances a plugin will need the message meta during the inbox? 315 'update_meta_cache' => false 316 ) ); 294 317 } 295 318 296 319 return array( 'threads' => &$threads, 'total' => (int) $total_threads ); -
src/bp-messages/bp-messages-functions.php
335 335 function messages_is_valid_thread( $thread_id ) { 336 336 return BP_Messages_Thread::is_valid( $thread_id ); 337 337 } 338 339 /** Messages Meta *******************************************************/ 340 341 /** 342 * Delete metadata for a message. 343 * 344 * If $meta_key is false, this will delete all meta for the message ID. 345 * 346 * @since BuddyPress (2.2.0) 347 * 348 * @see delete_metadata() for full documentation excluding $meta_type variable. 349 */ 350 function bp_messages_delete_meta( $message_id, $meta_key = false, $meta_value = false, $delete_all = false ) { 351 global $wpdb; 352 353 // Legacy - if no meta_key is passed, delete all for the item 354 if ( empty( $meta_key ) ) { 355 $keys = $wpdb->get_col( $wpdb->prepare( "SELECT meta_key FROM {$wpdb->messagemeta} WHERE message_id = %d", $message_id ) ); 356 357 // With no meta_key, ignore $delete_all 358 $delete_all = false; 359 } else { 360 $keys = array( $meta_key ); 361 } 362 363 add_filter( 'query', 'bp_filter_metaid_column_name' ); 364 365 foreach ( $keys as $key ) { 366 $retval = delete_metadata( 'message', $message_id, $key, $meta_value, $delete_all ); 367 } 368 369 remove_filter( 'query', 'bp_filter_metaid_column_name' ); 370 371 return $retval; 372 } 373 374 /** 375 * Get a piece of group metadata. 376 * 377 * @since BuddyPress (2.2.0) 378 * 379 * @see get_metadata() for full documentation excluding $meta_type variable. 380 */ 381 function bp_messages_get_meta( $message_id, $meta_key = '', $single = true ) { 382 add_filter( 'query', 'bp_filter_metaid_column_name' ); 383 $retval = get_metadata( 'message', $message_id, $meta_key, $single ); 384 remove_filter( 'query', 'bp_filter_metaid_column_name' ); 385 386 return $retval; 387 } 388 389 /** 390 * Update a piece of message metadata. 391 * 392 * @since BuddyPress (2.2.0) 393 * 394 * @see update_metadata() for full documentation excluding $meta_type variable. 395 */ 396 function bp_messages_update_meta( $message_id, $meta_key, $meta_value, $prev_value = '' ) { 397 add_filter( 'query', 'bp_filter_metaid_column_name' ); 398 $retval = update_metadata( 'message', $message_id, $meta_key, $meta_value, $prev_value ); 399 remove_filter( 'query', 'bp_filter_metaid_column_name' ); 400 401 return $retval; 402 } 403 404 /** 405 * Add a piece of message metadata. 406 * 407 * @since BuddyPress (2.2.0) 408 * 409 * @see add_metadata() for full documentation excluding $meta_type variable. 410 */ 411 function bp_message_add_meta( $message_id, $meta_key, $meta_value, $unique = false ) { 412 add_filter( 'query', 'bp_filter_metaid_column_name' ); 413 $retval = add_metadata( 'message', $message_id, $meta_key, $meta_value, $unique ); 414 remove_filter( 'query', 'bp_filter_metaid_column_name' ); 415 416 return $retval; 417 } -
src/bp-messages/bp-messages-loader.php
90 90 $global_tables = array( 91 91 'table_name_notices' => $bp->table_prefix . 'bp_messages_notices', 92 92 'table_name_messages' => $bp->table_prefix . 'bp_messages_messages', 93 'table_name_recipients' => $bp->table_prefix . 'bp_messages_recipients' 93 'table_name_recipients' => $bp->table_prefix . 'bp_messages_recipients', 94 'table_name_meta' => $bp->table_prefix . 'bp_messages_meta', 94 95 ); 95 96 97 // Metadata tables for messaging component 98 $meta_tables = array( 99 'message' => $bp->table_prefix . 'bp_messages_meta', 100 ); 101 102 $this->autocomplete_all = defined( 'BP_MESSAGES_AUTOCOMPLETE_ALL' ); 103 96 104 // All globals for messaging component. 97 105 // Note that global_tables is included in this array. 98 $globals =array(106 parent::setup_globals( array( 99 107 'slug' => BP_MESSAGES_SLUG, 100 108 'has_directory' => false, 101 109 'notification_callback' => 'messages_format_notifications', 102 110 'search_string' => __( 'Search Messages...', 'buddypress' ), 103 'global_tables' => $global_tables 104 ); 105 106 $this->autocomplete_all = defined( 'BP_MESSAGES_AUTOCOMPLETE_ALL' ); 107 108 parent::setup_globals( $globals ); 111 'global_tables' => $global_tables, 112 'meta_tables' => $meta_tables 113 ) ); 109 114 } 110 115 111 116 /** -
src/bp-messages/bp-messages-template.php
1405 1405 * Default: if viewing a thread, the thread ID will be parsed from 1406 1406 * the URL (bp_action_variable( 0 )). 1407 1407 * @type string $order 'ASC' or 'DESC'. Default: 'ASC'. 1408 * @type bool $update_meta_cache Whether to pre-fetch metadata for 1409 * queried message items. Default: true. 1408 1410 * } 1409 1411 * @return bool True if there are messages to display, otherwise false. 1410 1412 */ … … 1412 1414 global $thread_template; 1413 1415 1414 1416 $r = bp_parse_args( $args, array( 1415 'thread_id' => false, 1416 'order' => 'ASC' 1417 'thread_id' => false, 1418 'order' => 'ASC', 1419 'update_meta_cache' => true, 1417 1420 ), 'thread_has_messages' ); 1418 1421 1419 1422 if ( empty( $r['thread_id'] ) && bp_is_messages_component() && bp_is_current_action( 'view' ) ) { 1420 1423 $r['thread_id'] = (int) bp_action_variable( 0 ); 1421 1424 } 1422 1425 1423 $thread_template = new BP_Messages_Thread_Template( $r['thread_id'], $r['order'] ); 1426 // Set up extra args 1427 $extra_args = $r; 1428 unset( $extra_args['thread_id'], $extra_args['order'] ); 1429 1430 $thread_template = new BP_Messages_Thread_Template( $r['thread_id'], $r['order'], $extra_args ); 1424 1431 1425 1432 return $thread_template->has_messages(); 1426 1433 } … … 1834 1841 * @todo Add Messages meta? 1835 1842 */ 1836 1843 function bp_messages_embed() { 1837 add_filter( 'embed_post_id', 'bp_get_message_thread_id' ); 1844 add_filter( 'embed_post_id', 'bp_get_the_thread_message_id' ); 1845 add_filter( 'bp_embed_get_cache', 'bp_embed_message_cache', 10, 3 ); 1846 add_action( 'bp_embed_update_cache', 'bp_embed_message_save_cache', 10, 3 ); 1847 } 1848 add_action( 'thread_loop_start', 'bp_messages_embed' ); 1849 1850 /** 1851 * Fetch a private message item's cached embeds. 1852 * 1853 * Used during {@link BP_Embed::parse_oembed()} via {@link bp_messages_embed()}. 1854 * 1855 * @since BuddyPress (2.2.0) 1856 * 1857 * @param string $cache An empty string passed by BP_Embed::parse_oembed() for 1858 * functions like this one to filter. 1859 * @param int $id The ID of the activity item. 1860 * @param string $cachekey The cache key generated in BP_Embed::parse_oembed(). 1861 * @return mixed The cached embeds for this activity item. 1862 */ 1863 function bp_embed_message_cache( $cache, $id, $cachekey ) { 1864 return bp_messages_get_meta( $id, $cachekey ); 1865 } 1866 1867 /** 1868 * Set a private message item's embed cache. 1869 * 1870 * Used during {@link BP_Embed::parse_oembed()} via {@link bp_messages_embed()}. 1871 * 1872 * @since BuddyPress (2.2.0) 1873 * 1874 * @param string $cache An empty string passed by BP_Embed::parse_oembed() for 1875 * functions like this one to filter. 1876 * @param string $cachekey The cache key generated in BP_Embed::parse_oembed(). 1877 * @param int $id The ID of the activity item. 1878 * @return bool True on success, false on failure. 1879 */ 1880 function bp_embed_message_save_cache( $cache, $cachekey, $id ) { 1881 bp_messages_update_meta( $id, $cachekey, $cache ); 1838 1882 } 1839 add_action( 'messages_box_loop_start', 'bp_messages_embed' ); 1883 No newline at end of file -
src/bp-templates/bp-legacy/buddypress-functions.php
1298 1298 1299 1299 bp_thread_has_messages( array( 'thread_id' => (int) $_REQUEST['thread_id'] ) ); 1300 1300 1301 bp_thread_the_message(); 1302 1301 1303 if ( $thread_template->message_count % 2 == 1 ) { 1302 1304 $class = 'odd'; 1303 1305 } else {