Ticket #1925: 1925.diff
File 1925.diff, 8.7 KB (added by , 12 years ago) |
---|
-
includes/common/widgets.php
554 554 'posts_per_page' => $max_shown, 555 555 'post_status' => join( ',', array( bbp_get_public_status_id(), bbp_get_closed_status_id() ) ), 556 556 'show_stickes' => false, 557 'meta_key' => '_bbp_last_active_time', 558 'orderby' => 'meta_value', 557 'orderby' => 'modified', 559 558 'order' => 'DESC', 560 559 'meta_query' => array( bbp_exclude_forum_ids( 'meta_query' ) ) 561 560 ); -
includes/admin/tools.php
744 744 $statement = __( 'Recomputing latest post in every topic and forum… %s', 'bbpress' ); 745 745 $result = __( 'Failed!', 'bbpress' ); 746 746 747 // First, delete everything. 747 /* First, delete everything. 748 We're not using _bbp_last_active_time anymore, but 749 it makes sense to keep it here to help migrate to the 750 new data model. 751 */ 748 752 if ( is_wp_error( $wpdb->query( "DELETE FROM `$wpdb->postmeta` WHERE `meta_key` IN ( '_bbp_last_reply_id', '_bbp_last_topic_id', '_bbp_last_active_id', '_bbp_last_active_time' );" ) ) ) 749 753 return array( 1, sprintf( $statement, $result ) ); 750 754 … … 797 801 return array( 7, sprintf( $statement, $result ) ); 798 802 799 803 // Give topics with replies their last update time. 800 if ( is_wp_error( $wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`) 801 ( SELECT `topic`.`ID`, '_bbp_last_active_time', MAX( `reply`.`post_date` ) 802 FROM `$wpdb->posts` AS `topic` INNER JOIN `$wpdb->posts` AS `reply` ON `topic`.`ID` = `reply`.`post_parent` 803 WHERE `reply`.`post_status` IN ( '" . bbp_get_public_status_id() . "' ) AND `topic`.`post_type` = 'topic' AND `reply`.`post_type` = 'reply' 804 GROUP BY `topic`.`ID` );" ) ) ) 804 $sql = $wpdb->prepare( "UPDATE $wpdb->posts p1 805 LEFT JOIN (SELECT post_parent, 806 Max(post_date) AS max_date 807 FROM $wpdb->posts 808 WHERE post_status = %s 809 GROUP BY post_parent 810 ) p2 811 ON p1.ID = p2.post_parent 812 SET p1.post_modified = p2.max_date 813 WHERE p1.post_type = %s", bbp_get_public_status_id(), bbp_get_topic_post_type() ); 814 815 if ( is_wp_error( $wpdb->query( $sql ) ) ) 805 816 return array( 8, sprintf( $statement, $result ) ); 806 817 807 // Give topics without replies their last update time.808 if ( is_wp_error( $wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`)809 ( SELECT `ID`, '_bbp_last_active_time', `post_date`810 FROM `$wpdb->posts` AS `topic` LEFT JOIN `$wpdb->postmeta` AS `reply`811 ON `topic`.`ID` = `reply`.`post_id` AND `reply`.`meta_key` = '_bbp_last_active_time'812 WHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = 'topic' );" ) ) )813 return array( 9, sprintf( $statement, $result ) );814 815 818 // Forums need to know what their last active item is as well. Now it gets a bit more complex to do in the database. 816 819 $forums = $wpdb->get_col( "SELECT `ID` FROM `$wpdb->posts` WHERE `post_type` = 'forum' and `post_status` != 'auto-draft';" ); 817 820 if ( is_wp_error( $forums ) ) -
includes/topics/template-tags.php
108 108 'post_type' => bbp_get_topic_post_type(), // Narrow query down to bbPress topics 109 109 'post_parent' => $default_post_parent, // Forum ID 110 110 'post_status' => $default_post_status, // Post Status 111 'meta_key' => '_bbp_last_active_time', // Make sure topic has some last activity time 112 'orderby' => 'meta_value', // 'meta_value', 'author', 'date', 'title', 'modified', 'parent', rand', 111 'orderby' => 'modified', // 'meta_value', 'author', 'date', 'title', 'modified', 'parent', rand', 113 112 'order' => 'DESC', // 'ASC', 'DESC' 114 113 'posts_per_page' => bbp_get_topics_per_page(), // Topics per page 115 114 'paged' => bbp_get_paged(), // Page Number … … 196 195 'post_type' => bbp_get_topic_post_type(), 197 196 'post_parent' => 'any', 198 197 'post_status' => $default_post_status, 199 'meta_key' => '_bbp_last_active_time', 200 'orderby' => 'meta_value', 198 'orderby' => 'modified', 201 199 'order' => 'DESC', 202 200 'include' => $stickies 203 201 ); … … 1659 1657 $topic_id = bbp_get_topic_id( $topic_id ); 1660 1658 1661 1659 // Try to get the most accurate freshness time possible 1662 $last_active = get_post_ meta( $topic_id, '_bbp_last_active_time', true);1660 $last_active = get_post_field( 'post_modified', $topic_id ); 1663 1661 if ( empty( $last_active ) ) { 1664 1662 $reply_id = bbp_get_topic_last_reply_id( $topic_id ); 1665 1663 if ( !empty( $reply_id ) ) { -
includes/topics/functions.php
2381 2381 $new_time = get_post_field( 'post_date', bbp_get_public_child_last_id( $topic_id, bbp_get_reply_post_type() ) ); 2382 2382 2383 2383 // Update only if published 2384 if ( !empty( $new_time ) ) 2385 update_post_meta( $topic_id, '_bbp_last_active_time', $new_time ); 2384 if ( !empty( $new_time ) ) { 2385 $topic_to_update = array( 'ID' => $topic_id, 2386 'post_modified' => $new_time, 2387 'post_date' => get_post_field( 'post_date', $topic_id ) ); 2386 2388 2389 wp_update_post( $topic_to_update ); 2390 2391 unset( $topic_to_update ); 2392 } 2393 2387 2394 return apply_filters( 'bbp_update_topic_last_active_time', $new_time, $topic_id ); 2388 2395 } 2389 2396 … … 3239 3246 <guid><?php bbp_topic_permalink(); ?></guid> 3240 3247 <title><![CDATA[<?php bbp_topic_title(); ?>]]></title> 3241 3248 <link><?php bbp_topic_permalink(); ?></link> 3242 <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_ meta( bbp_get_topic_id(), '_bbp_last_active_time', true) ); ?></pubDate>3249 <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_field( 'post_modified', bbp_get_topic_id() ) ); ?></pubDate> 3243 3250 <dc:creator><?php the_author() ?></dc:creator> 3244 3251 3245 3252 <?php if ( !post_password_required() ) : ?> -
includes/forums/template-tags.php
453 453 454 454 // Verify forum and get last active meta 455 455 $forum_id = bbp_get_forum_id( $forum_id ); 456 $last_active = get_post_ meta( $forum_id, '_bbp_last_active_time', true);456 $last_active = get_post_field( 'post_modified', $forum_id ); 457 457 458 458 if ( empty( $last_active ) ) { 459 459 $reply_id = bbp_get_forum_last_reply_id( $forum_id ); -
includes/forums/functions.php
1077 1077 $post_vars = array( 1078 1078 'post_parent' => $forum_id, 1079 1079 'post_type' => bbp_get_topic_post_type(), 1080 ' meta_key' => '_bbp_last_active_time',1081 'order by' => 'meta_value',1080 'orderby' => 'modified', 1081 'order' => 'DESC', 1082 1082 'numberposts' => 1 1083 1083 ); 1084 1084 … … 1248 1248 */ 1249 1249 function bbp_update_forum_last_active_time( $forum_id = 0, $new_time = '' ) { 1250 1250 $forum_id = bbp_get_forum_id( $forum_id ); 1251 1252 1251 // Check time and use current if empty 1253 1252 if ( empty( $new_time ) ) 1254 1253 $new_time = get_post_field( 'post_date', bbp_get_forum_last_active_id( $forum_id ) ); 1255 1254 1256 1255 // Update only if there is a time 1257 if ( !empty( $new_time ) ) 1258 update_post_meta( $forum_id, '_bbp_last_active_time', $new_time ); 1256 if ( !empty( $new_time ) ) { 1259 1257 1258 $forum_to_update = array( 'ID' => $forum_id, 1259 'post_modified' => $new_time, 1260 'post_date' => get_post_field( 'post_date', $forum_id ) ); 1261 1262 wp_update_post( $forum_to_update ); 1263 1264 unset( $forum_to_update ); 1265 1266 } 1267 1260 1268 return (int) apply_filters( 'bbp_update_forum_last_active', $new_time, $forum_id ); 1261 1269 } 1262 1270 … … 1740 1748 * @return Position change based on sort 1741 1749 */ 1742 1750 function _bbp_forum_query_usort_subforum_ids( $a = 0, $b = 0 ) { 1743 $ta = get_post_ meta( $a, '_bbp_last_active_time', true);1744 $tb = get_post_ meta( $b, '_bbp_last_active_time', true);1751 $ta = get_post_field( 'post_modified', $a ); 1752 $tb = get_post_field( 'post_modified', $b ); 1745 1753 return ( $ta < $tb ) ? -1 : 1; 1746 1754 } 1747 1755