mirror of
https://github.com/discourse/discourse.git
synced 2025-05-16 18:26:19 +08:00
Merge pull request #3124 from gschlager/import_scripts
Improve the base importer
This commit is contained in:
commit
f22809c067
@ -22,7 +22,7 @@ class ImportScripts::Base
|
|||||||
include ActionView::Helpers::NumberHelper
|
include ActionView::Helpers::NumberHelper
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
require File.expand_path(File.dirname(__FILE__) + "/../../config/environment")
|
require_relative '../../config/environment'
|
||||||
preload_i18n
|
preload_i18n
|
||||||
|
|
||||||
@bbcode_to_md = true if ARGV.include?('bbcode-to-md')
|
@bbcode_to_md = true if ARGV.include?('bbcode-to-md')
|
||||||
@ -34,6 +34,7 @@ class ImportScripts::Base
|
|||||||
@existing_posts = {}
|
@existing_posts = {}
|
||||||
@topic_lookup = {}
|
@topic_lookup = {}
|
||||||
@old_site_settings = {}
|
@old_site_settings = {}
|
||||||
|
@start_time = Time.now
|
||||||
|
|
||||||
puts "loading existing groups..."
|
puts "loading existing groups..."
|
||||||
GroupCustomField.where(name: 'import_id').pluck(:group_id, :value).each do |group_id, import_id|
|
GroupCustomField.where(name: 'import_id').pluck(:group_id, :value).each do |group_id, import_id|
|
||||||
@ -85,7 +86,8 @@ class ImportScripts::Base
|
|||||||
update_topic_count_replies
|
update_topic_count_replies
|
||||||
reset_topic_counters
|
reset_topic_counters
|
||||||
|
|
||||||
puts "", "Done"
|
elapsed = Time.now - @start_time
|
||||||
|
puts '', "Done (#{elapsed.to_s} seconds)"
|
||||||
|
|
||||||
ensure
|
ensure
|
||||||
reset_site_settings
|
reset_site_settings
|
||||||
@ -226,10 +228,8 @@ class ImportScripts::Base
|
|||||||
# user in the original datasource. The given id will not be used to
|
# user in the original datasource. The given id will not be used to
|
||||||
# create the Discourse user record.
|
# create the Discourse user record.
|
||||||
def create_users(results, opts={})
|
def create_users(results, opts={})
|
||||||
num_users_before = User.count
|
|
||||||
users_created = 0
|
users_created = 0
|
||||||
users_skipped = 0
|
users_skipped = 0
|
||||||
progress = 0
|
|
||||||
total = opts[:total] || results.size
|
total = opts[:total] || results.size
|
||||||
|
|
||||||
results.each do |result|
|
results.each do |result|
|
||||||
@ -289,7 +289,7 @@ class ImportScripts::Base
|
|||||||
end
|
end
|
||||||
opts[:email] = opts[:email].downcase
|
opts[:email] = opts[:email].downcase
|
||||||
opts[:trust_level] = TrustLevel[1] unless opts[:trust_level]
|
opts[:trust_level] = TrustLevel[1] unless opts[:trust_level]
|
||||||
opts[:active] = true
|
opts[:active] = opts.fetch(:active, true)
|
||||||
opts[:import_mode] = true
|
opts[:import_mode] = true
|
||||||
|
|
||||||
u = User.new(opts)
|
u = User.new(opts)
|
||||||
@ -470,8 +470,8 @@ class ImportScripts::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def close_inactive_topics(opts={})
|
def close_inactive_topics(opts={})
|
||||||
puts "", "Closing topics that have been inactive for more than #{num_days} days."
|
|
||||||
num_days = opts[:days] || 30
|
num_days = opts[:days] || 30
|
||||||
|
puts '', "Closing topics that have been inactive for more than #{num_days} days."
|
||||||
|
|
||||||
query = Topic.where('last_posted_at < ?', num_days.days.ago).where(closed: false)
|
query = Topic.where('last_posted_at < ?', num_days.days.ago).where(closed: false)
|
||||||
total_count = query.count
|
total_count = query.count
|
||||||
@ -523,7 +523,7 @@ class ImportScripts::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def reset_topic_counters
|
def reset_topic_counters
|
||||||
puts "", "reseting topic counters"
|
puts "", "resetting topic counters"
|
||||||
|
|
||||||
total_count = Topic.count
|
total_count = Topic.count
|
||||||
progress_count = 0
|
progress_count = 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user