# XenForo 导入脚本导入了被封禁的用户以及软删除的主题和帖子

**URL:** <https://meta.discourse.org/t/xenforo-import-script-imported-banned-users-and-soft-deleted-topics-and-posts/266055>\
**Category:** Migration\
**Created:** [2019 年6 月 16 日 00:23 UTC](https://meta.discourse.org/t/xenforo-import-script-imported-banned-users-and-soft-deleted-topics-and-posts/266055 "2019-06-16T00:23:26Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

作者： ![msinger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/msinger/32/144985_2.png) [@msinger](https://meta.discourse.org/u/msinger)\
发布日期： [2019 年6 月 16 日 00:23 UTC](https://meta.discourse.org/t/xenforo-import-script-imported-banned-users-and-soft-deleted-topics-and-posts/266055/1 "2019-06-16T00:23:26Z")

</div>

我今天使用了这个脚本，运行效果良好。唯一的问题是它导入了所有被禁止的用户以及 XenForo 中被软删除（隐藏）的帖子/主题。这导致在导入后，Discourse 中出现了数百条垃圾帖子/主题。

如果您有大量不希望导入的垃圾帖子/主题，那么建议对“xenforo.rb”脚本进行以下 SQL 修改：

1. 添加以下 WHERE 子句，以确保仅导入活跃且未被禁止的用户。

```rb
       def import_users
        puts '', "creating users"

        total_count = mysql_query("SELECT count(*) count FROM #{TABLE_PREFIX}user;").first['count']

        batches(BATCH_SIZE) do |offset|
          results = mysql_query(
            "SELECT user_id id, username, email, custom_title title, register_date created_at,
                    last_activity last_visit_time, user_group_id, is_moderator, is_admin, is_staff
             FROM #{TABLE_PREFIX}user
             WHERE user_state = 'valid' AND is_banned = 0
             LIMIT #{BATCH_SIZE}
             OFFSET #{offset};")

```

1. 修改以下 WHERE 子句，以确保仅导入可见的主题/帖子。

```rb
       def import_posts
        puts "", "creating topics and posts"

        total_count = mysql_query("SELECT count(*) count from #{TABLE_PREFIX}post").first["count"]

        posts_sql = "
            SELECT p.post_id id,
                   t.thread_id topic_id,
                   #{@prefix_as_category ? 't.prefix_id' : 't.node_id'} category_id,
                   t.title title,
                   t.first_post_id first_post_id,
                   p.user_id user_id,
                   p.message raw,
                   p.post_date created_at
            FROM #{TABLE_PREFIX}post p,
                 #{TABLE_PREFIX}thread t
            WHERE p.thread_id = t.thread_id AND p.message_state = 'visible' AND t.discussion_state = 'visible'
            ORDER BY p.post_date
            LIMIT #{BATCH_SIZE}" # needs OFFSET

```

---

_[View the full topic](https://meta.discourse.org/t/xenforo-import-script-imported-banned-users-and-soft-deleted-topics-and-posts/266055)._
