[Replacements] Prevent double increment in fixer script

It's live on e9 already, so some replacements might already contain the
correct information.
This commit is contained in:
Earlopain 2022-01-03 17:55:01 +01:00
parent 50a64c7eef
commit 9597b3228a
No known key found for this signature in database
GPG Key ID: 6CFB948E15246897

View File

@ -10,10 +10,13 @@ end
PostReplacement.select(:post_id).where(status: ["approved", "original"]).group(:post_id)
.having("count(post_id) = 2").map(&:post_id).each do |post_id|
replacements = PostReplacement.where(post_id: post_id).order(:status)
approved = replacements[0]
original = replacements[1]
# Don't double increment
next if approved.uploader_id_on_approve.blank?
approved.uploader_id_on_approve = original.creator_id
approved.penalize_uploader_on_approve = true
approved.save!