/** * @covers ::bbp_admin_repair_forum_topic_count */ public function test_bbp_admin_repair_forum_topic_count() { $c = $this->factory->forum->create(array('forum_meta' => array('forum_type' => 'category', 'status' => 'open'))); $f = $this->factory->forum->create(array('post_parent' => $c, 'forum_meta' => array('forum_id' => $c, 'forum_type' => 'forum', 'status' => 'open'))); $t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f))); $count = bbp_get_forum_topic_count($f, true, true); $this->assertSame(1, $count); $t = $this->factory->topic->create_many(3, array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f))); bbp_update_forum_topic_count($c); bbp_update_forum_topic_count($f); // Category topic count. $count = bbp_get_forum_topic_count($c, false, true); $this->assertSame(0, $count); // Category total topic count. $count = bbp_get_forum_topic_count($c, true, true); $this->assertSame(4, $count); // Category topic count hidden. $count = bbp_get_forum_topic_count_hidden($c, true); $this->assertSame(0, $count); // Forum topic count. $count = bbp_get_forum_topic_count($f, false, true); $this->assertSame(4, $count); // Forum total topic count. $count = bbp_get_forum_topic_count($f, true, true); $this->assertSame(4, $count); // Forum topic count hidden. $count = bbp_get_forum_topic_count_hidden($f, true); $this->assertSame(0, $count); bbp_spam_topic($t[0]); bbp_unapprove_topic($t[2]); // Category topic count. $count = bbp_get_forum_topic_count($c, false, true); $this->assertSame(0, $count); // Category total topic count. $count = bbp_get_forum_topic_count($c, true, true); $this->assertSame(2, $count); // Category topic count hidden. $count = bbp_get_forum_topic_count_hidden($c, true); $this->assertSame(0, $count); // Forum topic count. $count = bbp_get_forum_topic_count($f, false, true); $this->assertSame(2, $count); // Forum total topic count. $count = bbp_get_forum_topic_count($f, true, true); $this->assertSame(2, $count); // Forum topic count hidden. $count = bbp_get_forum_topic_count_hidden($f, true); $this->assertSame(2, $count); // Delete the _bbp_total_topic_count meta key. $this->assertTrue(delete_post_meta_by_key('_bbp_topic_count_hidden')); // Delete the _bbp_total_topic_count meta key. $this->assertTrue(delete_post_meta_by_key('_bbp_total_topic_count')); // Delete the _bbp_topic_count meta key. $this->assertTrue(delete_post_meta_by_key('_bbp_topic_count')); // Category topic count. $count = bbp_get_forum_topic_count($c, false, true); $this->assertSame(0, $count); // Category total topic count. $count = bbp_get_forum_topic_count($c, true, true); $this->assertSame(0, $count); // Category topic count hidden. $count = bbp_get_forum_topic_count_hidden($c, true); $this->assertSame(0, $count); // Forum topic count. $count = bbp_get_forum_topic_count($f, false, true); $this->assertSame(0, $count); // Forum total topic count. $count = bbp_get_forum_topic_count($f, true, true); $this->assertSame(0, $count); // Forum topic count hidden. $count = bbp_get_forum_topic_count_hidden($f, true); $this->assertSame(0, $count); // Repair the forum topic count meta. bbp_admin_repair_forum_topic_count(); // Category topic count. $count = bbp_get_forum_topic_count($c, false, true); $this->assertSame(0, $count); // Category total topic count. $count = bbp_get_forum_topic_count($c, true, true); $this->assertSame(2, $count); // Category topic count hidden. $count = bbp_get_forum_topic_count_hidden($c, true); $this->assertSame(0, $count); // Forum topic count. $count = bbp_get_forum_topic_count($f, false, true); $this->assertSame(2, $count); // Forum total topic count. $count = bbp_get_forum_topic_count($f, true, true); $this->assertSame(2, $count); // Forum topic count hidden. $count = bbp_get_forum_topic_count_hidden($f, true); $this->assertSame(2, $count); }
/** * Perform the export * * @access public * @since 1.0 * @uses bbp_Export::csv_rows_out() * @return void */ public function import() { if (!$this->can_import()) { wp_die(__('You do not have permission to import data.', 'bbp-export-import'), __('Error', 'bbp-export-import')); } $csv_array = $this->csv_to_array($_FILES['bbp_csv_file']['tmp_name'], ';'); foreach ($csv_array as $key => $line) { $post_args = $line; $meta_args = array(); // Setup author date if ($post_args['anonymous'] == '1') { $meta_args['anonymous_email'] = $line['post_author']; } else { $user = get_user_by('email', $post_args['post_author']); if (!$user) { // The user doesn't exist, so create them $user = wp_insert_user(array('user_email' => $post_args['post_author'], 'user_login' => $post_args['user_login'])); } $post_args['post_author'] = $user->ID; } // Decode content $post_args['post_content'] = html_entity_decode($post_args['post_content']); $topic_type = bbp_get_topic_post_type(); $reply_type = bbp_get_reply_post_type(); // Remove the post args we don't want sent to wp_insert_post unset($post_args['anonymous']); unset($post_args['user_login']); switch ($line['post_type']) { case $topic_type: // Set the forum parent for topics $post_args['post_parent'] = $this->forum_id; $meta_args['voice_count'] = $line['voices']; $meta_args['reply_count'] = $post_args['reply_count']; $topic_id = bbp_insert_topic($post_args, $meta_args); // Subscribe the original poster to the topic bbp_add_user_subscription($post_args['post_author'], $topic_id); // Add the topic to the user's favorites if (bbp_is_user_favorite($post_args['post_author'], $topic_id)) { bbp_add_user_favorite($post_args['post_author'], $topic_id); } // Set topic as resolved if GetShopped Support Forum is active if ($post_args['resolved'] == '1') { add_post_meta($topic_id, '_bbps_topic_status', '2'); } break; case $reply_type: // Set the forum parent for replies. The topic ID is created above when the replie's topic is first created $post_args['post_parent'] = $topic_id; $reply_id = bbp_insert_reply($post_args, $meta_args); // Subscribe reply author, if not already if (!bbp_is_user_subscribed($post_args['post_author'], $topic_id)) { bbp_add_user_subscription($post_args['post_author'], $topic_id); } // Mark as favorite if (bbp_is_user_favorite($post_args['post_author'], $topic_id)) { bbp_add_user_favorite($post_args['post_author'], $topic_id); } // Check if the next row is a topic, meaning we have reached the last reply and need to update the last active time if ($csv_array[$key + 1]['post_type'] == bbp_get_topic_post_type()) { bbp_update_forum_last_active_time($this->forum_id, $post_args['post_date']); } break; } } // Recount forum topic / reply counts bbp_admin_repair_forum_topic_count(); bbp_admin_repair_forum_reply_count(); wp_redirect(admin_url('post.php?post=' . $this->forum_id . '&action=edit')); exit; }