Ticket #2876: latest_activity.patch
File latest_activity.patch, 8.8 KB (added by , 9 years ago) |
---|
-
includes/admin/tools.php
diff --git a/includes/admin/tools.php b/includes/admin/tools.php index 3803aab..7e22df0 100644
a b function bbp_admin_repair_forum_reply_count() { 500 500 if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) { 501 501 return array( 1, sprintf( $statement, $result ) ); 502 502 } 503 503 504 504 // Recalculate the metas key _bbp_reply_count and _bbp_total_reply_count for each forum 505 505 $forums = get_posts( array( 'post_type' => bbp_get_forum_post_type(), 'numberposts' => -1 ) ); 506 506 if ( !empty( $forums ) ) { … … function bbp_admin_repair_freshness() { 864 864 return array( 1, sprintf( $statement, $result ) ); 865 865 866 866 // Next, give all the topics with replies the ID their last reply. 867 if ( is_wp_error( $wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`) 868 ( SELECT `topic`.`ID`, '_bbp_last_reply_id', MAX( `reply`.`ID` ) 869 FROM `$wpdb->posts` AS `topic` INNER JOIN `$wpdb->posts` AS `reply` ON `topic`.`ID` = `reply`.`post_parent` 870 WHERE `reply`.`post_status` IN ( '" . bbp_get_public_status_id() . "' ) AND `topic`.`post_type` = 'topic' AND `reply`.`post_type` = 'reply' 871 GROUP BY `topic`.`ID` );" ) ) ) 867 if ( is_wp_error( $wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`) ( 868 SELECT `post_parent`, '_bbp_last_reply_id', `ID` FROM `wp_posts` WHERE `post_date` IN 869 (SELECT MAX( `reply`.`post_date`) as rDate 870 FROM `wp_posts` AS `topic` 871 INNER JOIN `wp_posts` AS `reply` 872 ON `topic`.`ID` = `reply`.`post_parent` 873 WHERE `reply`.`post_status` IN ( 'publish' ) 874 AND `topic`.`post_type` = 'topic' 875 AND `reply`.`post_type` = 'reply' 876 GROUP BY `topic`.`ID`) );" ) ) ) 872 877 return array( 2, sprintf( $statement, $result ) ); 873 878 874 879 // For any remaining topics, give a reply ID of 0. … … function bbp_admin_repair_freshness() { 880 885 return array( 3, sprintf( $statement, $result ) ); 881 886 882 887 // Now we give all the forums with topics the ID their last topic. 883 if ( is_wp_error( $wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`) 884 ( SELECT `forum`.`ID`, '_bbp_last_topic_id', `topic`.`ID` 885 FROM `$wpdb->posts` AS `forum` INNER JOIN `$wpdb->posts` AS `topic` ON `forum`.`ID` = `topic`.`post_parent` 886 WHERE `topic`.`post_status` IN ( '" . bbp_get_public_status_id() . "' ) AND `forum`.`post_type` = 'forum' AND `topic`.`post_type` = 'topic' 887 GROUP BY `forum`.`ID` );" ) ) ) 888 // This gives the last topic created vs the last topic updated. 889 if ( is_wp_error( $wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`) ( 890 SELECT `post_parent` as fID, '_bbp_last_topic_id', `ID` as tID FROM `wp_posts` WHERE `post_date` IN ( 891 SELECT MAX( `topic`.`post_date`) as tDate 892 FROM `wp_posts` AS `forum` 893 INNER JOIN `wp_posts` AS `topic` 894 ON `forum`.`ID` = `topic`.`post_parent` 895 WHERE `topic`.`post_status` IN ( 'publish' ) 896 AND `forum`.`post_type` = 'forum' 897 AND `topic`.`post_type` = 'topic' 898 GROUP BY `forum`.`ID` ) );" ) ) ) 899 888 900 return array( 4, sprintf( $statement, $result ) ); 889 901 890 902 // For any remaining forums, give a topic ID of 0. … … function bbp_admin_repair_freshness() { 896 908 return array( 5, sprintf( $statement, $result ) ); 897 909 898 910 // After that, we give all the topics with replies the ID their last reply (again, this time for a different reason). 899 if ( is_wp_error( $wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`) 900 ( SELECT `topic`.`ID`, '_bbp_last_active_id', MAX( `reply`.`ID` ) 901 FROM `$wpdb->posts` AS `topic` INNER JOIN `$wpdb->posts` AS `reply` ON `topic`.`ID` = `reply`.`post_parent` 902 WHERE `reply`.`post_status` IN ( '" . bbp_get_public_status_id() . "' ) AND `topic`.`post_type` = 'topic' AND `reply`.`post_type` = 'reply' 903 GROUP BY `topic`.`ID` );" ) ) ) 911 if ( is_wp_error( $wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`)( 912 SELECT `post_parent`, '_bbp_last_active_id', `ID` FROM `wp_posts` WHERE `post_date` IN 913 (SELECT MAX( `reply`.`post_date`) as rDate 914 FROM `wp_posts` AS `topic` 915 INNER JOIN `wp_posts` AS `reply` 916 ON `topic`.`ID` = `reply`.`post_parent` 917 WHERE `reply`.`post_status` IN ( 'publish' ) 918 AND `topic`.`post_type` = 'topic' 919 AND `reply`.`post_type` = 'reply' 920 GROUP BY `topic`.`ID`) );" ) ) ) 904 921 return array( 6, sprintf( $statement, $result ) ); 905 922 906 923 // For any remaining topics, give a reply ID of themself. … … function bbp_admin_repair_reply_menu_order() { 1149 1166 1150 1167 // Delete cases where `_bbp_reply_to` was accidentally set to itself 1151 1168 if ( is_wp_error( $wpdb->query( "DELETE FROM `{$wpdb->postmeta}` WHERE `meta_key` = '_bbp_reply_to' AND `post_id` = `meta_value`;" ) ) ) { 1152 return array( 1, sprintf( $statement, $result ) ); 1169 return array( 1, sprintf( $statement, $result ) ); 1153 1170 } 1154 1171 1155 1172 // Post type -
includes/common/functions.php
diff --git a/includes/common/functions.php b/includes/common/functions.php index bd5c481..69dcb4e 100644
a b function bbp_get_public_child_ids( $parent_id = 0, $post_type = 'post' ) { 1596 1596 // Join post statuses together 1597 1597 $post_status = "'" . implode( "', '", $post_status ) . "'"; 1598 1598 1599 $child_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY IDDESC;", $parent_id, $post_type ) );1599 $child_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY post_date DESC;", $parent_id, $post_type ) ); 1600 1600 wp_cache_set( $cache_id, $child_ids, 'bbpress_posts' ); 1601 1601 } 1602 1602 … … function bbp_get_all_child_ids( $parent_id = 0, $post_type = 'post' ) { 1659 1659 // Join post statuses together 1660 1660 $post_status = "'" . implode( "', '", $post_status ) . "'"; 1661 1661 1662 $child_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY IDDESC;", $parent_id, $post_type ) );1662 $child_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY post_date DESC;", $parent_id, $post_type ) ); 1663 1663 wp_cache_set( $cache_id, $child_ids, 'bbpress_posts' ); 1664 1664 } 1665 1665 -
includes/forums/functions.php
diff --git a/includes/forums/functions.php b/includes/forums/functions.php index 050791d..f92d863 100644
a b function bbp_update_forum_last_reply_id( $forum_id = 0, $reply_id = 0 ) { 1236 1236 1237 1237 // If this forum has topics... 1238 1238 $topic_ids = bbp_forum_query_topic_ids( $forum_id ); 1239 1239 1240 if ( !empty( $topic_ids ) ) { 1240 1241 1241 1242 // ...get the most recent reply from those topics... 1242 1243 $reply_id = bbp_forum_query_last_reply_id( $forum_id, $topic_ids ); 1243 1244 1244 // ...and compare it to the most recent topic id... 1245 $reply_id = ( $reply_id > max( $topic_ids ) ) ? $reply_id : max( $topic_ids );1245 // ...and compare it to the most recent topic id... (most recent refers to date not ID) 1246 // $reply_id = ( $reply_id > max( $topic_ids ) ) ? $reply_id : max( $topic_ids ); 1246 1247 } 1247 1248 } 1248 1249 … … function bbp_update_forum_last_active_id( $forum_id = 0, $active_id = 0 ) { 1302 1303 $topic_ids = bbp_forum_query_topic_ids( $forum_id ); 1303 1304 if ( !empty( $topic_ids ) ) { 1304 1305 $active_id = bbp_forum_query_last_reply_id( $forum_id, $topic_ids ); 1305 $active_id = $active_id > max( $topic_ids ) ? $active_id : max( $topic_ids );1306 //$active_id = $active_id > max( $topic_ids ) ? $active_id : max( $topic_ids ); 1306 1307 1307 1308 // Forum has no topics 1308 1309 } else { … … function bbp_forum_query_last_reply_id( $forum_id, $topic_ids = 0 ) { 1933 1934 $cache_id = 'bbp_get_forum_' . $forum_id . '_reply_id'; 1934 1935 $reply_id = (int) wp_cache_get( $cache_id, 'bbpress_posts' ); 1935 1936 1936 if ( false === $reply_id ) {1937 if ( 0 === $reply_id || false === $reply_id ) { 1937 1938 1938 1939 if ( empty( $topic_ids ) ) { 1939 1940 $topic_ids = bbp_forum_query_topic_ids( $forum_id ); 1940 1941 } 1941 1942 1942 1943 if ( !empty( $topic_ids ) ) { 1944 1943 1945 $topic_ids = implode( ',', wp_parse_id_list( $topic_ids ) ); 1944 $reply_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent IN ( {$topic_ids} ) AND post_status = '%s' AND post_type = '%s' ORDER BY IDDESC LIMIT 1;", bbp_get_public_status_id(), bbp_get_reply_post_type() ) );1946 $reply_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent IN ( {$topic_ids} ) AND post_status = '%s' AND post_type = '%s' ORDER BY post_date DESC LIMIT 1;", bbp_get_public_status_id(), bbp_get_reply_post_type() ) ); 1945 1947 wp_cache_set( $cache_id, $reply_id, 'bbpress_posts' ); // May be (int) 0 1948 1946 1949 } else { 1947 1950 wp_cache_set( $cache_id, '0', 'bbpress_posts' ); 1948 1951 }