30 lines
1.1 KiB
Ruby
30 lines
1.1 KiB
Ruby
class AuthorsUsersSeparationUpdater
|
|
def run
|
|
all_users = User.all
|
|
all_authors_mods = all_users.map{|u| AuthorsMod.where(author_id: u.id).load }
|
|
all_users.each_with_index do |user, i|
|
|
#LN "============ Updating user: #{user.name} #{user.id}"
|
|
authors_mods = all_authors_mods[i]
|
|
unless authors_mods.empty?
|
|
author = Author.create! name: user.name, forum_name: user.name
|
|
#LN "Has mods! Author created! #{author.id}"
|
|
authors_mods.each do |am|
|
|
#LN "Updating authors_mod #{am.mod.name}---#{user.name} #{user.id} -> #{author.id}"
|
|
am.update! author_id: author.id
|
|
end
|
|
Author.reset_counters(author.id, :mods)
|
|
if user.autogenerated?
|
|
#LN "User was autogenerated, destroying!"
|
|
user.destroy!
|
|
elsif author.mods.where(owner: user).count > 0
|
|
#LN "User was legit and marked as owner! Associating them!"
|
|
author.user = user
|
|
author.save!
|
|
else
|
|
#LN "User was legit! But didn't have ownership of any mods!"
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|