# XenForo 移行スクリプトで、BANされたユーザーやソフト削除されたトピック・投稿がインポートされました

**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 日午前 12: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:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![msinger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/msinger/32/144985_2.png) [@msinger](https://meta.discourse.org/u/msinger)
#### Post date: [2019 年 6 月 16 日午前 12: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

```

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2019 年 6 月 16 日午前 6:24 UTC](https://meta.discourse.org/t/xenforo-import-script-imported-banned-users-and-soft-deleted-topics-and-posts/266055/2 "2019-06-16T06:24:14Z")

</div>

ありがとうございます。その変更をスクリプトに反映できますか、@techAPJ？

---

<div class="post-metadata">

### Author: ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)
#### Post date: [2019 年 6 月 18 日午前 10:24 UTC](https://meta.discourse.org/t/xenforo-import-script-imported-banned-users-and-soft-deleted-topics-and-posts/266055/3 "2019-06-18T10:24:04Z")

</div>

以下により完了しました：

> <https://github.com/discourse/discourse/commit/6d30be1f94538218fd3f2857b11a6db766bea4fb>
>
> \- ensure only active, unbanned users are imported.
> \- ensure only visible threads…/posts are imported.

@msinger さん、アドバイスありがとうございます。👍

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [2023 年 5 月 24 日午後 12:33 UTC](https://meta.discourse.org/t/xenforo-import-script-imported-banned-users-and-soft-deleted-topics-and-posts/266055/4 "2023-05-24T12:33:27Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
