# phpBB 3 Importer (old)

**URL:** https://meta.discourse.org/t/phpbb-3-importer-old/17397
**Category:** Feature
**Created:** [7월 9, 2014, 6:57오후 UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397 "2014-07-09T18:57:02Z")
**Posts on this page:** 20
**Page:** 2

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [8월 16, 2014, 1:46오후 UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/21 "2014-08-16T13:46:49Z")

</div>

Thanks. I had to change it a little bit since the `bundle install` as user discourse resulted in a permission denied error. But the following works:

```
apt-get update && apt-get install libmysqlclient-dev -y
git clone https://github.com/nlalonde/ruby-bbcode-to-md.git /tmp/ruby-bbcode-to-md
cd /tmp/ruby-bbcode-to-md
gem build ruby-bbcode-to-md.gemspec
gem install ruby-bbcode-to-md-0.0.13.gem

su - discourse
echo "gem 'mysql2'" >> /var/www/discourse/Gemfile
echo "gem 'ruby-bbcode-to-md', path: '/tmp/ruby-bbcode-to-md'" >> /var/www/discourse/Gemfile
exit

cd /var/www/discourse
bundle install --no-deployment --path vendor/bundle

su - discourse
cd /var/www/discourse
RAILS_ENV=production bundle exec ruby script/import_scripts/phpbb3.rb bbcode-to-md

```

---

<div class="post-metadata">

### Author: ![Jeff\_Vienneau](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jeff_vienneau/32/108772_2.png) [@Jeff\_Vienneau](https://meta.discourse.org/u/Jeff_Vienneau)
#### Post date: [8월 29, 2014, 5:52오후 UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/22 "2014-08-29T17:52:45Z")

</div>

Thanks for all the excellent work here. I have just imported my phpBB forum to discourse.

I am seeing an issue with attachments.

When the jpg is added to the post as an attachment and inserted using the [attachment] tag, the result is simply the tag:  
[attachment=0]IMG\_2911a.JPG[/attachment]

Has anyone encountered this?  
Does the attachment get pulled over to discourse anywhere, so I could fix this manually?

thanks

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [8월 29, 2014, 5:54오후 UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/23 "2014-08-29T17:54:48Z")

</div>

The current version of the importer can’t import attachments. I’m going to implement this in the next few weeks unless someone else does it earlier…

---

<div class="post-metadata">

### Author: ![Jeff\_Vienneau](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jeff_vienneau/32/108772_2.png) [@Jeff\_Vienneau](https://meta.discourse.org/u/Jeff_Vienneau)
#### Post date: [8월 29, 2014, 5:57오후 UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/24 "2014-08-29T17:57:01Z")

</div>

Thanks for the info, Gerhard.

If you run the import a second time, what happens? I have users on the system already making new posts.

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [8월 29, 2014, 6:20오후 UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/25 "2014-08-29T18:20:48Z")

</div>

The importer detects the already imported topics/posts and does nothing. I’m not sure yet, but I think the import function I’m planning to implement wont be able to update already imported posts and add those attachments…

---

<div class="post-metadata">

### Author: ![Jeff\_Vienneau](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jeff_vienneau/32/108772_2.png) [@Jeff\_Vienneau](https://meta.discourse.org/u/Jeff_Vienneau)
#### Post date: [9월 2, 2014, 12:11오전 UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/26 "2014-09-02T00:11:45Z")

</div>

Is there a way to clear the imported posts? And still keep the posts that were used to load images for logo etc..

---

<div class="post-metadata">

### Author: ![elberet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/elberet/32/122404_2.png) [@elberet](https://meta.discourse.org/u/elberet)
#### Post date: [9월 2, 2014, 1:10오전 UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/27 "2014-09-02T01:10:58Z")

</div>

Not automatically. But you can do this in the Rails console, **if** the converter script has set some custom field on imported posts. This should be the case for most current importer scripts.

```ruby
system_user = Discourse.system_user
PostCustomField.joins(:post).includes(:post).where(name: 'import_id').map {|pcf| pcf.post.topic_id }.sort.uniq.each do |topic_id|
  PostDestroyer.new(system_user, Topic.find(topic_id).ordered_posts.first).destroy
end

```

---

<div class="post-metadata">

### Author: ![Jeff\_Vienneau](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jeff_vienneau/32/108772_2.png) [@Jeff\_Vienneau](https://meta.discourse.org/u/Jeff_Vienneau)
#### Post date: [9월 2, 2014, 8:13오후 UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/28 "2014-09-02T20:13:17Z")

</div>

Does anyone know if the phpBB script sets such a custom field?

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [9월 2, 2014, 8:43오후 UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/29 "2014-09-02T20:43:43Z")

</div>

Yes, it does set the custom field. Actually all the official importers set that field.

---

<div class="post-metadata">

### Author: ![Jeff\_Vienneau](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jeff_vienneau/32/108772_2.png) [@Jeff\_Vienneau](https://meta.discourse.org/u/Jeff_Vienneau)
#### Post date: [9월 2, 2014, 10:27오후 UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/30 "2014-09-02T22:27:08Z")

</div>

Excellent.

I think I’ll give these scripts a good look over. I’m new to ruby but it looks neat.

---

<div class="post-metadata">

### Author: ![Jeff\_Vienneau](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jeff_vienneau/32/108772_2.png) [@Jeff\_Vienneau](https://meta.discourse.org/u/Jeff_Vienneau)
#### Post date: [9월 3, 2014, 5:56오후 UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/31 "2014-09-03T17:56:24Z")

</div>

Looking at the code, trying to understand the ruby…

I see that there is a method “create\_upload” in base but that does not seem to be called anywhere in base or in phpBB script yet some posts have uploads that were pulled across. What am I missing?

Note, when the script rendered the links to these uploads, the _ **IP address was used and not my host name** _. Is this a script issue or configuration on my part?

---

<div class="post-metadata">

### Author: ![neil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neil/32/102150_2.png) [@neil](https://meta.discourse.org/u/neil)
#### Post date: [9월 3, 2014, 6:27오후 UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/32 "2014-09-03T18:27:50Z")

</div>

Have you edited the variables at the top of the script?

```plaintext
  ORIGINAL_SITE_PREFIX = "oldsite.example.com/forums" # without http(s)://
  NEW_SITE_PREFIX = "http://discourse.example.com" # with http:// or https://

```

Also, as discussed earlier, that script isn’t handling phpbb uploads at all. I’m working on it now, but with a site that has already been imported. I’ll try to backport my work to that script.

@gerhard said he was going to work on it “in the next few weeks”, but I can’t wait. I’ll try to share what I come up with.

---

<div class="post-metadata">

### Author: ![Jeff\_Vienneau](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jeff_vienneau/32/108772_2.png) [@Jeff\_Vienneau](https://meta.discourse.org/u/Jeff_Vienneau)
#### Post date: [9월 3, 2014, 7:59오후 UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/33 "2014-09-03T19:59:45Z")

</div>

Thanks @neil, I missed those variables.

That would be great. My site has no active users just an import from the phpBB site (with active users). I would be willing to test what you have.

---

<div class="post-metadata">

### Author: ![Jeff\_Vienneau](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jeff_vienneau/32/108772_2.png) [@Jeff\_Vienneau](https://meta.discourse.org/u/Jeff_Vienneau)
#### Post date: [9월 3, 2014, 8:39오후 UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/34 "2014-09-03T20:39:51Z")

</div>

When I try to reload, after running the destroy script (above), it will only import new posts. It also reports many posts as not having a parent post:

“Parent post pm:503 doesn’t exist. Skipping 506: …”

How does the imported keep track of where it left off? Do I need to reset something?

---

<div class="post-metadata">

### Author: ![elberet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/elberet/32/122404_2.png) [@elberet](https://meta.discourse.org/u/elberet)
#### Post date: [9월 3, 2014, 9:24오후 UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/35 "2014-09-03T21:24:38Z")

</div>

Ouch. Discourse doesn’t do recursive destroys. Which means that your database now contains a bunch of orphaned posts.

```ruby
[TopicAllowedUser, TopicAllowedGroup, TopicUser, TopicCustomField].each do |model|
  model.includes(:topic).select {|p| p.topic.nil? }.each(&:destroy)
end
system_user = Discourse.system_user
Post.includes(:topic).select {|p| p.topic.nil? }.each do |post|
  PostDestroyer.new(system_user, post).destroy
end

```

That should at least catch the most obnoxious garbage, but the remaining users may have wrong topic counters. At least for a while, until sidekiq updates the stats.

---

<div class="post-metadata">

### Author: ![Jeff\_Vienneau](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jeff_vienneau/32/108772_2.png) [@Jeff\_Vienneau](https://meta.discourse.org/u/Jeff_Vienneau)
#### Post date: [9월 3, 2014, 9:52오후 UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/36 "2014-09-03T21:52:12Z")

</div>

No worries. I’ll give that a try tonight. Thanks.

You should edit your post maybe to indicate the issue for others.

---

<div class="post-metadata">

### Author: ![elberet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/elberet/32/122404_2.png) [@elberet](https://meta.discourse.org/u/elberet)
#### Post date: [9월 3, 2014, 10:19오후 UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/37 "2014-09-03T22:19:20Z")

</div>

Good point, done. 👍

---

<div class="post-metadata">

### Author: ![Jeff\_Vienneau](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jeff_vienneau/32/108772_2.png) [@Jeff\_Vienneau](https://meta.discourse.org/u/Jeff_Vienneau)
#### Post date: [9월 3, 2014, 10:43오후 UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/38 "2014-09-03T22:43:52Z")

</div>

Tested this since @elberet’s last edit and it does seem to clean the imported posts. Thanks @elberet!

---

<div class="post-metadata">

### Author: ![Jeff\_Vienneau](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jeff_vienneau/32/108772_2.png) [@Jeff\_Vienneau](https://meta.discourse.org/u/Jeff_Vienneau)
#### Post date: [9월 4, 2014, 12:33오전 UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/39 "2014-09-04T00:33:05Z")

</div>

Still getting parent post does not exist. It looked like it cleaned out everything. Still not enough though.

---

<div class="post-metadata">

### Author: ![elberet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/elberet/32/122404_2.png) [@elberet](https://meta.discourse.org/u/elberet)
#### Post date: [9월 4, 2014, 1:19오전 UTC](https://meta.discourse.org/t/phpbb-3-importer-old/17397/40 "2014-09-04T01:19:13Z")

</div>

Drat. If we assume that _at least_ the topics table has been cleaned out, you could try to just flush the orphaned post custom fields, and live with a few orphan posts remaining in the database. Without those, the importer should not recognize anything as already imported.

```plaintext
PostCustomField.includes(:post => :topic).select {|f| f.post.topic.nil? }.each(&:destroy)

```

[이전 페이지](https://meta.discourse.org/t/phpbb-3-importer-old/17397.md?page=1)

[다음 페이지](https://meta.discourse.org/t/phpbb-3-importer-old/17397.md?page=3)
