From fdb535ebbd54c56e292b3ed0b7f39da21eca8f5c Mon Sep 17 00:00:00 2001 From: albert Date: Mon, 25 Mar 2013 23:07:49 -0400 Subject: [PATCH] fixes #1092, fixes naming for tag alias|implication requests, includes fix method --- app/models/tag_alias.rb | 14 ++++++++++++-- app/views/tag_alias_requests/new.html.erb | 4 ++-- app/views/tag_aliases/index.html.erb | 4 ++-- app/views/tag_implication_requests/new.html.erb | 4 ++-- script/fixes/010.rb | 13 +++++++++++++ 5 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 script/fixes/010.rb diff --git a/app/models/tag_alias.rb b/app/models/tag_alias.rb index 052468557..bef397702 100644 --- a/app/models/tag_alias.rb +++ b/app/models/tag_alias.rb @@ -1,6 +1,6 @@ class TagAlias < ActiveRecord::Base + before_save :ensure_tags_exist after_save :clear_all_cache - after_save :ensure_category_consistency after_destroy :clear_all_cache before_validation :initialize_creator, :on => :create validates_presence_of :creator_id, :antecedent_name, :consequent_name @@ -13,6 +13,10 @@ class TagAlias < ActiveRecord::Base def name_matches(name) where("(antecedent_name like ? escape E'\\\\' or consequent_name like ? escape E'\\\\')", name.downcase.to_escaped_for_sql_like, name.downcase.to_escaped_for_sql_like) end + + def active + where("status = ?", "active") + end def search(params) q = scoped @@ -70,6 +74,7 @@ class TagAlias < ActiveRecord::Base def process! update_column(:status, "processing") clear_all_cache + ensure_category_consistency update_posts update_column(:status, "active") rescue Exception => e @@ -105,8 +110,13 @@ class TagAlias < ActiveRecord::Base end end + def ensure_tags_exist + Tag.find_or_create_by_name(antecedent_name) + Tag.find_or_create_by_name(consequent_name) + end + def ensure_category_consistency - if antecedent_tag && consequent_tag && antecedent_tag.category != consequent_tag.category + if antecedent_tag.category != consequent_tag.category consequent_tag.update_attribute(:category, antecedent_tag.category) end diff --git a/app/views/tag_alias_requests/new.html.erb b/app/views/tag_alias_requests/new.html.erb index baa1f1276..0f06bbf6c 100644 --- a/app/views/tag_alias_requests/new.html.erb +++ b/app/views/tag_alias_requests/new.html.erb @@ -6,12 +6,12 @@ <%= form_tag(tag_alias_request_path, :class => "simple_form") do %>
- + <%= text_field "tag_alias_request", "antecedent_name" %>
- + <%= text_field "tag_alias_request", "consequent_name" %>
diff --git a/app/views/tag_aliases/index.html.erb b/app/views/tag_aliases/index.html.erb index 47e61abed..bdd922f5b 100644 --- a/app/views/tag_aliases/index.html.erb +++ b/app/views/tag_aliases/index.html.erb @@ -21,8 +21,8 @@ <% @tag_aliases.each do |tag_alias| %> - <%= link_to tag_alias.antecedent_name, posts_path(:tags => tag_alias.antecedent_name) %> <%= tag_alias.antecedent_tag.post_count rescue 0 %> - <%= link_to tag_alias.consequent_name, posts_path(:tags => tag_alias.consequent_name) %> <%= tag_alias.consequent_tag.post_count rescue 0 %> + <%= link_to tag_alias.antecedent_name, posts_path(:tags => tag_alias.antecedent_name) %> <%= tag_alias.antecedent_tag.post_count rescue 0 %> + <%= link_to tag_alias.consequent_name, posts_path(:tags => tag_alias.consequent_name) %> <%= tag_alias.consequent_tag.post_count rescue 0 %> <% if tag_alias.forum_topic_id %> <%= link_to tag_alias.forum_topic_id, forum_topic_path(tag_alias.forum_topic_id) %> diff --git a/app/views/tag_implication_requests/new.html.erb b/app/views/tag_implication_requests/new.html.erb index 73d78cb7c..2925aec7f 100644 --- a/app/views/tag_implication_requests/new.html.erb +++ b/app/views/tag_implication_requests/new.html.erb @@ -6,12 +6,12 @@ <%= form_tag(tag_implication_request_path, :class => "simple_form") do %>
- + <%= text_field "tag_implication_request", "antecedent_name" %>
- + <%= text_field "tag_implication_request", "consequent_name" %>
diff --git a/script/fixes/010.rb b/script/fixes/010.rb new file mode 100644 index 000000000..26331c8c8 --- /dev/null +++ b/script/fixes/010.rb @@ -0,0 +1,13 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment')) + +ActiveRecord::Base.connection.execute("set statement_timeout = 0") + +TagAlias.active.find_each do |tag_alias| + Tag.find_or_create_by_name(tag_alias.antecedent_name) + Tag.find_or_create_by_name(tag_alias.consequent_name) + if tag_alias.antecedent_tag.category != 0 && tag_alias.antecedent_tag.category != tag_alias.consequent_tag.category + tag_alias.consequent_tag.update_attribute(:category, tag_alias.antecedent_tag.category) + end +end