# Migrate a XenForo forum to Discourse

**URL:** https://meta.discourse.org/t/migrate-a-xenforo-forum-to-discourse/45232
**Category:** Sysadmins
**Tags:** how-to
**Created:** [June 4, 2016, 1:38am UTC](https://meta.discourse.org/t/migrate-a-xenforo-forum-to-discourse/45232 "2016-06-04T01:38:22Z")
**Posts on this page:** 1
**Showing post:** 60

<div class="post-metadata">

### Author: ![AstonJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/astonj/32/215041_2.png) [@AstonJ](https://meta.discourse.org/u/AstonJ)
#### Post date: [January 25, 2021, 4:31am UTC](https://meta.discourse.org/t/migrate-a-xenforo-forum-to-discourse/45232/60 "2021-01-25T04:31:00Z")

</div>

> [@justin](#):
>
> From a quick look at the importer, it appears it only imports uploads to posts. Avatar support would need to be added.

Thanks Justin, I’ve had a quick look at it - does this seem ok to you? (Feel free to add it to the official importer if you like)

```plaintext
  XENFORO_DB = "xenforo_db_3"
  TABLE_PREFIX = "xf_"
  BATCH_SIZE = 1000
  ATTACHMENT_DIR = '/FULL/PATH/TO/attachments'
  AVATAR_DIR = '/FULL/PATH/TO/avatars'

```

(Added last line^^ - means you’ll need to copy avatars there)

```plaintext
  def execute
    import_users
    import_categories
    import_posts
    import_avatars
  end

```

(Added last line^^)

```ruby
  def import_avatars
    if AVATAR_DIR
      users = User.all
      users.each do |u|
        unless u.custom_fields["import_id"].nil?
          import_id = u.custom_fields["import_id"]
          if import_id.to_i < 1000
            dir_num = "0"
          elsif import_id.to_i > 1000
            dir_num = import_id.first
          end
        
          avatar_filename = "#{import_id}.jpg"
          file_path = "#{AVATAR_DIR}/l/#{dir_num}"
          file_path_and_name = "#{file_path}/#{avatar_filename}"

          if File.exists?(file_path_and_name)
            upload = create_upload(u.id, file_path_and_name, avatar_filename)
            if upload.persisted?
              u.import_mode = false
              u.create_user_avatar
              u.import_mode = true
              u.user_avatar.update(custom_upload_id: upload.id)
              u.update(uploaded_avatar_id: upload.id)
            else
              puts "Error: Upload did not persist for #{u.username} #{avatar_filename}!"
            end
          end
        end
      end
    end
  end

```

Its very late here so I may have made some mistakes or missed a load of stuff out but this is assuming all avatars are .jpg (which seems like all of mine are). I wasn’t too sure about the `u.import_mode` switches tho so just commented them out.

Totally untested (it.s nearly 5am here 💤)

> [@RoldanLT](#):
>
> I’m still waiting for big board importer, to try and test my 18m post forum.

I did a test on my dev machine on a forum with 100K posts and it took 90minutes. The one I want to do the import on has a couple million posts so 10 times as long maybe?

> [@TheDarkWizard](#):
>
> We are working on our own in-house bulk importer for 27 million posts. It went from a bit over a week (not counting attachments) to under a day with everything. We completed our first import test without any errors yesterday. Really exciting stuff.

Nice! Will you be sharing it with us? Any idea when?

---

_[View the full topic](https://meta.discourse.org/t/migrate-a-xenforo-forum-to-discourse/45232)._
