DEV: Improve phpBB3 import script (#15956)

* Optional import of custom user fields from phpBB 3.1+
* Optional import of likes from phpBB3
  Requires the phpBB "Thanks for posts" extension
* Fix import of bookmarks from phpBB3
* Update `created_at` of existing user
* Support mapping of phpBB forums to existing Discourse categories
  This is in addition to the ability of merging phpBB forums and importing into newly created Discourse categories.
This commit is contained in:
Gerhard Schlager
2022-02-16 13:04:31 +01:00
committed by GitHub
parent e945f301d1
commit 6394d7cddf
9 changed files with 171 additions and 22 deletions

View File

@ -366,6 +366,7 @@ class ImportScripts::Base
# try based on email
if e.try(:record).try(:errors).try(:messages).try(:[], :primary_email).present?
if existing = User.find_by_email(opts[:email].downcase)
existing.created_at = opts[:created_at] if opts[:created_at]
existing.custom_fields["import_id"] = import_id
existing.save!
u = existing
@ -630,6 +631,35 @@ class ImportScripts::Base
[created, skipped]
end
def create_likes(results, opts = {})
created = 0
skipped = 0
total = opts[:total] || results.count
results.each do |result|
params = yield(result)
if params.nil?
skipped += 1
else
created_by = User.find_by(id: user_id_from_imported_user_id(params[:user_id]))
post = Post.find_by(id: post_id_from_imported_post_id(params[:post_id]))
if created_by && post
PostActionCreator.create(created_by, post, :like, created_at: params[:created_at])
created += 1
else
skipped += 1
puts "Skipping like for user id #{params[:user_id]} and post id #{params[:post_id]}"
end
end
print_status(created + skipped + (opts[:offset] || 0), total, get_start_time("likes"))
end
[created, skipped]
end
def close_inactive_topics(opts = {})
num_days = opts[:days] || 30
puts '', "Closing topics that have been inactive for more than #{num_days} days."