Skip to:
Content

bbPress.org

Ticket #2533: 2533.1.diff

File 2533.1.diff, 3.5 KB (added by netweb, 7 years ago)
  • includes/admin/tools.php

     
    908908                        WHERE `topic`.`meta_id` IS NULL AND `forum`.`post_type` = '{$fpt}' );" ) ) )
    909909                return array( 5, sprintf( $statement, $result ) );
    910910
    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.
    912912        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}' );" ) ) )
    917918                return array( 6, sprintf( $statement, $result ) );
    918919
    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 
    927920        // Give topics with replies their last update time.
    928921        if ( is_wp_error( $wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`)
    929922                        ( SELECT `topic`.`ID`, '_bbp_last_active_time', MAX( `reply`.`post_date` )
     
    930923                        FROM `$wpdb->posts` AS `topic` INNER JOIN `$wpdb->posts` AS `reply` ON `topic`.`ID` = `reply`.`post_parent`
    931924                        WHERE `reply`.`post_status` = '{$pps}' AND `topic`.`post_type` = '{$tpt}' AND `reply`.`post_type` = '{$rpt}'
    932925                        GROUP BY `topic`.`ID` );" ) ) )
    933                 return array( 8, sprintf( $statement, $result ) );
     926                return array( 7, sprintf( $statement, $result ) );
    934927
    935928        // Give topics without replies their last update time.
    936929        if ( is_wp_error( $wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`)
     
    938931                        FROM `$wpdb->posts` AS `topic` LEFT JOIN `$wpdb->postmeta` AS `reply`
    939932                        ON `topic`.`ID` = `reply`.`post_id` AND `reply`.`meta_key` = '_bbp_last_active_time'
    940933                        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 ) );
    942935
    943936        // Forums need to know what their last active item is as well. Now it gets a bit more complex to do in the database.
    944937        $forums = $wpdb->get_col( "SELECT `ID` FROM `$wpdb->posts` WHERE `post_type` = '{$fpt}' and `post_status` != 'auto-draft';" );
    945938        if ( is_wp_error( $forums ) )
    946                 return array( 10, sprintf( $statement, $result ) );
     939                return array( 9, sprintf( $statement, $result ) );
    947940
    948941        // Loop through forums
    949942        foreach ( $forums as $forum_id ) {