/** * @covers ::bbp_forum_subforum_count * @covers ::bbp_get_forum_subforum_count */ public function test_bbp_get_forum_subforum_count() { $f1 = $this->factory->forum->create(); $int_value = 3; $formatted_value = bbp_number_format($int_value); $this->factory->forum->create_many($int_value, array('post_parent' => $f1)); bbp_update_forum_subforum_count($f1); // Output. $count = bbp_get_forum_subforum_count($f1, false); $this->expectOutputString($formatted_value); bbp_forum_subforum_count($f1); // Formatted string. $count = bbp_get_forum_subforum_count($f1, false); $this->assertSame($formatted_value, $count); // Integer. $count = bbp_get_forum_subforum_count($f1, true); $this->assertSame($int_value, $count); // Direct query. $count = count(bbp_forum_query_subforum_ids($f1)); $this->assertSame($int_value, $count); }
/** * 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']))); } }
/** * 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))); } }
/** * 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']))); } }
/** * @covers ::bbp_update_forum_subforum_count */ public function test_bbp_update_forum_subforum_count() { $f1 = $this->factory->forum->create(); $f2 = $this->factory->forum->create_many(3, array('post_parent' => $f1)); $count = bbp_get_forum_subforum_count($f1, true); $this->assertSame(0, $count); bbp_update_forum_subforum_count($f1); $count = bbp_get_forum_subforum_count($f1, true); $this->assertSame(3, $count); }