fixes #1092, fixes naming for tag alias|implication requests, includes fix method
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
|
||||
<%= form_tag(tag_alias_request_path, :class => "simple_form") do %>
|
||||
<div class="input">
|
||||
<label>Antecedent</label>
|
||||
<label>From</label>
|
||||
<%= text_field "tag_alias_request", "antecedent_name" %>
|
||||
</div>
|
||||
|
||||
<div class="input">
|
||||
<label>Consequent</label>
|
||||
<label>To</label>
|
||||
<%= text_field "tag_alias_request", "consequent_name" %>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
<tbody>
|
||||
<% @tag_aliases.each do |tag_alias| %>
|
||||
<tr id="tag-alias-<%= tag_alias.id %>">
|
||||
<td><%= link_to tag_alias.antecedent_name, posts_path(:tags => tag_alias.antecedent_name) %> <span class="count"><%= tag_alias.antecedent_tag.post_count rescue 0 %></span></td>
|
||||
<td><%= link_to tag_alias.consequent_name, posts_path(:tags => tag_alias.consequent_name) %> <span class="count"><%= tag_alias.consequent_tag.post_count rescue 0 %></span></td>
|
||||
<td class="category-<%= tag_alias.antecedent_tag.category %>"><%= link_to tag_alias.antecedent_name, posts_path(:tags => tag_alias.antecedent_name) %> <span class="count"><%= tag_alias.antecedent_tag.post_count rescue 0 %></span></td>
|
||||
<td class="category-<%= tag_alias.consequent_tag.try(:category) %>"><%= link_to tag_alias.consequent_name, posts_path(:tags => tag_alias.consequent_name) %> <span class="count"><%= tag_alias.consequent_tag.post_count rescue 0 %></span></td>
|
||||
<td>
|
||||
<% if tag_alias.forum_topic_id %>
|
||||
<%= link_to tag_alias.forum_topic_id, forum_topic_path(tag_alias.forum_topic_id) %>
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
|
||||
<%= form_tag(tag_implication_request_path, :class => "simple_form") do %>
|
||||
<div class="input">
|
||||
<label>Antecedent</label>
|
||||
<label>From</label>
|
||||
<%= text_field "tag_implication_request", "antecedent_name" %>
|
||||
</div>
|
||||
|
||||
<div class="input">
|
||||
<label>Consequent</label>
|
||||
<label>To</label>
|
||||
<%= text_field "tag_implication_request", "consequent_name" %>
|
||||
</div>
|
||||
|
||||
|
||||
13
script/fixes/010.rb
Normal file
13
script/fixes/010.rb
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user