fix user lookup by email in disqus import script
This commit is contained in:
parent
678e28794a
commit
94ceb06b02
|
@ -269,7 +269,7 @@ class ImportScripts::Base
|
|||
merge = opts.delete(:merge)
|
||||
post_create_action = opts.delete(:post_create_action)
|
||||
|
||||
existing = User.joins(:user_emails).where("user_emails.email = ? OR username = ?", opts[:email].downcase, opts[:username]).first
|
||||
existing = find_existing_user(opts[:email], opts[:username])
|
||||
return existing if existing && (merge || existing.custom_fields["import_id"].to_s == import_id.to_s)
|
||||
|
||||
bio_raw = opts.delete(:bio_raw)
|
||||
|
@ -369,6 +369,10 @@ class ImportScripts::Base
|
|||
u # If there was an error creating the user, u.errors has the messages
|
||||
end
|
||||
|
||||
def find_existing_user(email, username)
|
||||
User.joins(:user_emails).where("user_emails.email = ? OR username = ?", email.downcase, username).first
|
||||
end
|
||||
|
||||
def created_category(category)
|
||||
# override if needed
|
||||
end
|
||||
|
|
|
@ -67,7 +67,7 @@ class ImportScripts::Disqus < ImportScripts::Base
|
|||
|
||||
puts "Creating #{title}... (#{t[:posts].size} posts)"
|
||||
|
||||
topic_user = User.where('email = ? OR username = ?', t[:author_email].downcase, t[:author_username]).first
|
||||
topic_user = find_existing_user(t[:author_email], t[:author_username])
|
||||
begin
|
||||
post = TopicEmbed.import_remote(topic_user, t[:link], title: title)
|
||||
post.topic.update_column(:category_id, @category.id)
|
||||
|
@ -77,7 +77,7 @@ class ImportScripts::Disqus < ImportScripts::Base
|
|||
|
||||
if post.present? && post.topic.posts_count <= 1
|
||||
(t[:posts] || []).each do |p|
|
||||
post_user = User.where('email = ? OR username = ?', (p[:author_email] || '').downcase, p[:author_username]).first
|
||||
post_user = find_existing_user(p[:author_email] || '', p[:author_username])
|
||||
next unless post_user.present?
|
||||
|
||||
attrs = {
|
||||
|
|
Loading…
Reference in New Issue