예제 #1
0
/**
 * Updates the counts of a forum.
 *
 * This calls a few internal functions that all run manual queries against the
 * database to get their results. As such, this function can be costly to run
 * but is necessary to keep everything accurate.
 *
 * @since bbPress (r2908)
 *
 * @param mixed $args Supports these arguments:
 *  - forum_id: Forum id
 *  - last_topic_id: Last topic id
 *  - last_reply_id: Last reply id
 *  - last_active_id: Last active post id
 *  - last_active_time: last active time
 * @uses bbp_update_forum_last_topic_id() To update the forum last topic id
 * @uses bbp_update_forum_last_reply_id() To update the forum last reply id
 * @uses bbp_update_forum_last_active_id() To update the last active post id
 * @uses get_post_field() To get the post date of the last active id
 * @uses bbp_update_forum_last_active_time()  To update the last active time
 * @uses bbp_update_forum_subforum_count() To update the subforum count
 * @uses bbp_update_forum_topic_count() To update the forum topic count
 * @uses bbp_update_forum_reply_count() To update the forum reply count
 * @uses bbp_update_forum_topic_count_hidden() To update the hidden topic count
 */
function bbp_update_forum($args = '')
{
    // Parse arguments against default values
    $r = bbp_parse_args($args, array('forum_id' => 0, 'post_parent' => 0, 'last_topic_id' => 0, 'last_reply_id' => 0, 'last_active_id' => 0, 'last_active_time' => 0, 'last_active_status' => bbp_get_public_status_id()), 'update_forum');
    // Last topic and reply ID's
    bbp_update_forum_last_topic_id($r['forum_id'], $r['last_topic_id']);
    bbp_update_forum_last_reply_id($r['forum_id'], $r['last_reply_id']);
    // Active dance
    $r['last_active_id'] = bbp_update_forum_last_active_id($r['forum_id'], $r['last_active_id']);
    // If no active time was passed, get it from the last_active_id
    if (empty($r['last_active_time'])) {
        $r['last_active_time'] = get_post_field('post_date', $r['last_active_id']);
    }
    if (bbp_get_public_status_id() === $r['last_active_status']) {
        bbp_update_forum_last_active_time($r['forum_id'], $r['last_active_time']);
    }
    // Counts
    bbp_update_forum_subforum_count($r['forum_id']);
    bbp_update_forum_reply_count($r['forum_id']);
    bbp_update_forum_topic_count($r['forum_id']);
    bbp_update_forum_topic_count_hidden($r['forum_id']);
    // Update the parent forum if one was passed
    if (!empty($r['post_parent']) && is_numeric($r['post_parent'])) {
        bbp_update_forum(array('forum_id' => $r['post_parent'], 'post_parent' => get_post_field('post_parent', $r['post_parent'])));
    }
}
예제 #2
0
파일: tools.php 프로젝트: joeyblake/bbpress
/**
 * Recount forum topics
 *
 * @since 2.0.0 bbPress (r2613)
 *
 * @uses wpdb::query() To run our recount sql queries
 * @uses is_wp_error() To check if the executed query returned {@link WP_Error}
 * @uses bbp_get_forum_post_type() To get the forum post type
 * @uses get_posts() To get the forums
 * @uses bbp_update_forum_topic_count() To update the forum topic count
 * @return array An array of the status code and the message
 */
function bbp_admin_repair_forum_topic_count()
{
    // Define variables
    $bbp_db = bbp_db();
    $statement = __('Counting the number of topics in each forum… %s', 'bbpress');
    $result = __('Failed!', 'bbpress');
    $sql_delete = "DELETE FROM {$bbp_db->postmeta} WHERE meta_key IN ( '_bbp_topic_count', '_bbp_total_topic_count', '_bbp_topic_count_hidden' );";
    if (is_wp_error($bbp_db->query($sql_delete))) {
        return array(1, sprintf($statement, $result));
    }
    $forums = get_posts(array('post_type' => bbp_get_forum_post_type(), 'numberposts' => -1));
    if (!empty($forums)) {
        foreach ($forums as $forum) {
            bbp_update_forum_topic_count($forum->ID);
            bbp_update_forum_topic_count_hidden($forum->ID);
        }
    } else {
        return array(2, sprintf($statement, $result));
    }
    return array(0, sprintf($statement, __('Complete!', 'bbpress')));
}
예제 #3
0
/**
 * Updates the counts of a forum.
 *
 * This calls a few internal functions that all run manual queries against the
 * database to get their results. As such, this function can be costly to run
 * but is necessary to keep everything accurate.
 *
 * @since bbPress (r2908)
 *
 * @param mixed $args Supports these arguments:
 *  - forum_id: Forum id
 *  - last_topic_id: Last topic id
 *  - last_reply_id: Last reply id
 *  - last_active_id: Last active post id
 *  - last_active_time: last active time
 * @uses bbp_update_forum_last_topic_id() To update the forum last topic id
 * @uses bbp_update_forum_last_reply_id() To update the forum last reply id
 * @uses bbp_update_forum_last_active_id() To update the last active post id
 * @uses get_post_field() To get the post date of the last active id
 * @uses bbp_update_forum_last_active_time()  To update the last active time
 * @uses bbp_update_forum_subforum_count() To update the subforum count
 * @uses bbp_update_forum_topic_count() To update the forum topic count
 * @uses bbp_update_forum_reply_count() To update the forum reply count
 * @uses bbp_update_forum_topic_count_hidden() To update the hidden topic count
 */
function bbp_update_forum($args = '')
{
    $defaults = array('forum_id' => 0, 'post_parent' => 0, 'last_topic_id' => 0, 'last_reply_id' => 0, 'last_active_id' => 0, 'last_active_time' => 0, 'last_active_status' => bbp_get_public_status_id());
    $r = bbp_parse_args($args, $defaults, 'update_forum');
    extract($r);
    // Last topic and reply ID's
    bbp_update_forum_last_topic_id($forum_id, $last_topic_id);
    bbp_update_forum_last_reply_id($forum_id, $last_reply_id);
    // Active dance
    $last_active_id = bbp_update_forum_last_active_id($forum_id, $last_active_id);
    // If no active time was passed, get it from the last_active_id
    if (empty($last_active_time)) {
        $last_active_time = get_post_field('post_date', $last_active_id);
    }
    if (bbp_get_public_status_id() == $last_active_status) {
        bbp_update_forum_last_active_time($forum_id, $last_active_time);
    }
    // Counts
    bbp_update_forum_subforum_count($forum_id);
    bbp_update_forum_reply_count($forum_id);
    bbp_update_forum_topic_count($forum_id);
    bbp_update_forum_topic_count_hidden($forum_id);
    // Update the parent forum if one was passed
    if (!empty($post_parent) && is_numeric($post_parent)) {
        bbp_update_forum(array('forum_id' => $post_parent, 'post_parent' => get_post_field('post_parent', $post_parent)));
    }
}
예제 #4
0
 /**
  * @covers ::bbp_forum_topic_count_hidden
  * @covers ::bbp_get_forum_topic_count_hidden
  */
 public function test_bbp_get_forum_topic_count_hidden()
 {
     $c = $this->factory->forum->create(array('forum_meta' => array('forum_type' => 'category')));
     $f = $this->factory->forum->create(array('post_parent' => $c, 'forum_meta' => array('forum_id' => $c)));
     $int_value = 3;
     $formatted_value = bbp_number_format($int_value);
     $this->factory->topic->create_many($int_value, array('post_parent' => $f, 'post_status' => bbp_get_spam_status_id()));
     bbp_update_forum_topic_count_hidden($c);
     bbp_update_forum_topic_count_hidden($f);
     // Forum output.
     $count = bbp_get_forum_topic_count_hidden($f, false);
     $this->expectOutputString($formatted_value);
     bbp_forum_topic_count_hidden($f);
     // Forum formatted string.
     $count = bbp_get_forum_topic_count_hidden($f, false);
     $this->assertSame($formatted_value, $count);
     // Forum integer.
     $count = bbp_get_forum_topic_count_hidden($f, true);
     $this->assertSame($int_value, $count);
     // Category topic count hidden.
     $count = bbp_get_forum_topic_count_hidden($c, true);
     $this->assertSame(0, $count);
     // Category total topic count hidden.
     $count = bbp_get_forum_topic_count_hidden($c, true);
     $this->assertSame(0, $count);
 }
예제 #5
0
/**
 * Updates the counts of a forum.
 *
 * This calls a few internal functions that all run manual queries against the
 * database to get their results. As such, this function can be costly to run
 * but is necessary to keep everything accurate.
 *
 * @since 2.0.0 bbPress (r2908)
 *
 * @param array $args Supports these arguments:
 *  - forum_id: Forum id
 *  - last_topic_id: Last topic id
 *  - last_reply_id: Last reply id
 *  - last_active_id: Last active post id
 *  - last_active_time: last active time
 * @uses bbp_update_forum_last_topic_id() To update the forum last topic id
 * @uses bbp_update_forum_last_reply_id() To update the forum last reply id
 * @uses bbp_update_forum_last_active_id() To update the last active post id
 * @uses get_post_field() To get the post date of the last active id
 * @uses bbp_update_forum_last_active_time()  To update the last active time
 * @uses bbp_update_forum_subforum_count() To update the subforum count
 * @uses bbp_update_forum_topic_count() To update the forum topic count
 * @uses bbp_update_forum_reply_count() To update the forum reply count
 * @uses bbp_update_forum_topic_count_hidden() To update the hidden topic count
 */
function bbp_update_forum($args = array())
{
    // Parse arguments against default values
    $r = bbp_parse_args($args, array('forum_id' => 0, 'post_parent' => 0, 'last_topic_id' => 0, 'last_reply_id' => 0, 'last_active_id' => 0, 'last_active_time' => 0, 'last_active_status' => bbp_get_public_status_id()), 'update_forum');
    // Last topic and reply ID's
    bbp_update_forum_last_topic_id($r['forum_id'], $r['last_topic_id']);
    bbp_update_forum_last_reply_id($r['forum_id'], $r['last_reply_id']);
    // Active dance
    $r['last_active_id'] = bbp_update_forum_last_active_id($r['forum_id'], $r['last_active_id']);
    // If no active time was passed, get it from the last_active_id
    if (empty($r['last_active_time'])) {
        $r['last_active_time'] = get_post_field('post_date', $r['last_active_id']);
    }
    if (bbp_get_public_status_id() === $r['last_active_status']) {
        bbp_update_forum_last_active_time($r['forum_id'], $r['last_active_time']);
    }
    // Counts
    bbp_update_forum_subforum_count($r['forum_id']);
    // Only update topic count if we're deleting a topic, or in the dashboard.
    if (in_array(current_filter(), array('bbp_deleted_topic', 'save_post'), true)) {
        bbp_update_forum_reply_count($r['forum_id']);
        bbp_update_forum_topic_count($r['forum_id']);
        bbp_update_forum_topic_count_hidden($r['forum_id']);
    }
    // Update the parent forum if one was passed
    if (!empty($r['post_parent']) && is_numeric($r['post_parent'])) {
        bbp_update_forum(array('forum_id' => $r['post_parent'], 'post_parent' => get_post_field('post_parent', $r['post_parent'])));
    }
}
예제 #6
0
 /**
  * @covers ::bbp_update_forum_topic_count_hidden
  */
 public function test_bbp_update_forum_topic_count_hidden()
 {
     $f = $this->factory->forum->create();
     $count = bbp_get_forum_topic_count($f, false, true);
     $this->assertSame(0, $count);
     $t = $this->factory->topic->create_many(3, array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f)));
     bbp_update_forum_topic_count_hidden($f);
     $count = bbp_get_forum_topic_count_hidden($f, true);
     $this->assertSame(0, $count);
     bbp_spam_topic($t[2]);
     bbp_update_forum_topic_count_hidden($f);
     $count = bbp_get_forum_topic_count_hidden($f, true);
     $this->assertSame(1, $count);
     bbp_unapprove_topic($t[0]);
     bbp_update_forum_topic_count_hidden($f);
     $count = bbp_get_forum_topic_count_hidden($f, true);
     $this->assertSame(2, $count);
 }
예제 #7
0
 /**
  * @covers ::bbp_forum_topic_count_hidden
  * @covers ::bbp_get_forum_topic_count_hidden
  */
 public function test_bbp_get_forum_topic_count_hidden()
 {
     $f = $this->factory->forum->create();
     $int_value = 3;
     $formatted_value = bbp_number_format($int_value);
     $this->factory->topic->create_many($int_value, array('post_parent' => $f, 'post_status' => bbp_get_spam_status_id()));
     bbp_update_forum_topic_count_hidden($f);
     // Output
     $count = bbp_get_forum_topic_count_hidden($f, false);
     $this->expectOutputString($formatted_value);
     bbp_forum_topic_count_hidden($f);
     // Formatted string
     $count = bbp_get_forum_topic_count_hidden($f, false);
     $this->assertSame($formatted_value, $count);
     // Integer
     $count = bbp_get_forum_topic_count_hidden($f, true, true);
     $this->assertSame($int_value, $count);
 }