Fix implication antecedents with aliases

This commit is contained in:
Toks
2013-12-28 18:56:34 -05:00
parent f628a4c0ff
commit 9caa41d30a
2 changed files with 28 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
class UpdateAliasedImplicationAntecedents < ActiveRecord::Migration
def change
execute "set statement_timeout = 0"
TagImplication.find_each do |ti|
ta = TagAlias.where("antecedent_name = ? AND status != ?", ti.antecedent_name, "pending").first
if ta
if ta.consequent_name == ti.consequent_name
ti.destroy
elsif TagImplication.where("antecedent_name = ? AND consequent_name = ?", ta.consequent_name, ti.consequent_name).exists?
ti.destroy
else
ti.antecedent_name = ta.consequent_name
ti.save
end
ta.update_posts
end
end
end
end