Ticket #2533: 2533.1.diff
File 2533.1.diff, 3.5 KB (added by , 7 years ago) |
---|
-
includes/admin/tools.php
908 908 WHERE `topic`.`meta_id` IS NULL AND `forum`.`post_type` = '{$fpt}' );" ) ) ) 909 909 return array( 5, sprintf( $statement, $result ) ); 910 910 911 // After that, we give all the topics with replies the ID their last reply (again, this time for a different reason).911 // Give all the topics with replies the ID of their last reply or topics without a reply an ID of themself. 912 912 if ( is_wp_error( $wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`) 913 ( SELECT `topic`.`ID`, '_bbp_last_active_id', MAX( `reply`.`ID` ) 914 FROM `$wpdb->posts` AS `topic` INNER JOIN `$wpdb->posts` AS `reply` ON `topic`.`ID` = `reply`.`post_parent` 915 WHERE `reply`.`post_status` = '{$pps}' AND `topic`.`post_type` = '{$tpt}' AND `reply`.`post_type` = '{$rpt}' 916 GROUP BY `topic`.`ID` );" ) ) ) 913 ( SELECT `topic`.`ID`, '_bbp_last_active_id', COALESCE( ( SELECT MAX( `reply`.`ID` ) 914 FROM `$wpdb->posts` AS `reply` 915 WHERE `topic`.`ID` = `reply`.`post_parent` AND `reply`.`post_status` = '{$pps}') , `topic`.`ID` ) 916 FROM `$wpdb->posts` AS `topic` 917 WHERE `topic`.`post_type` = '{$tpt}' );" ) ) ) 917 918 return array( 6, sprintf( $statement, $result ) ); 918 919 919 // For any remaining topics, give a reply ID of themself.920 if ( is_wp_error( $wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`)921 ( SELECT `ID`, '_bbp_last_active_id', `ID`922 FROM `$wpdb->posts` AS `topic` LEFT JOIN `$wpdb->postmeta` AS `reply`923 ON `topic`.`ID` = `reply`.`post_id` AND `reply`.`meta_key` = '_bbp_last_active_id'924 WHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = '{$tpt}' );" ) ) )925 return array( 7, sprintf( $statement, $result ) );926 927 920 // Give topics with replies their last update time. 928 921 if ( is_wp_error( $wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`) 929 922 ( SELECT `topic`.`ID`, '_bbp_last_active_time', MAX( `reply`.`post_date` ) … … 930 923 FROM `$wpdb->posts` AS `topic` INNER JOIN `$wpdb->posts` AS `reply` ON `topic`.`ID` = `reply`.`post_parent` 931 924 WHERE `reply`.`post_status` = '{$pps}' AND `topic`.`post_type` = '{$tpt}' AND `reply`.`post_type` = '{$rpt}' 932 925 GROUP BY `topic`.`ID` );" ) ) ) 933 return array( 8, sprintf( $statement, $result ) );926 return array( 7, sprintf( $statement, $result ) ); 934 927 935 928 // Give topics without replies their last update time. 936 929 if ( is_wp_error( $wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`) … … 938 931 FROM `$wpdb->posts` AS `topic` LEFT JOIN `$wpdb->postmeta` AS `reply` 939 932 ON `topic`.`ID` = `reply`.`post_id` AND `reply`.`meta_key` = '_bbp_last_active_time' 940 933 WHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = '{$tpt}' );" ) ) ) 941 return array( 9, sprintf( $statement, $result ) );934 return array( 8, sprintf( $statement, $result ) ); 942 935 943 936 // Forums need to know what their last active item is as well. Now it gets a bit more complex to do in the database. 944 937 $forums = $wpdb->get_col( "SELECT `ID` FROM `$wpdb->posts` WHERE `post_type` = '{$fpt}' and `post_status` != 'auto-draft';" ); 945 938 if ( is_wp_error( $forums ) ) 946 return array( 10, sprintf( $statement, $result ) );939 return array( 9, sprintf( $statement, $result ) ); 947 940 948 941 // Loop through forums 949 942 foreach ( $forums as $forum_id ) {