fixes #1234
This commit is contained in:
@@ -6,7 +6,7 @@ module Admin
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@importer = AliasAndImplicationImporter.new(params[:batch][:text], params[:batch][:forum_id])
|
@importer = AliasAndImplicationImporter.new(params[:batch][:text], params[:batch][:forum_id], params[:batch][:rename_aliased_pages])
|
||||||
@importer.process!
|
@importer.process!
|
||||||
flash[:notice] = "Import queued"
|
flash[:notice] = "Import queued"
|
||||||
redirect_to new_admin_alias_and_implication_import_path
|
redirect_to new_admin_alias_and_implication_import_path
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
class AliasAndImplicationImporter
|
class AliasAndImplicationImporter
|
||||||
attr_accessor :text, :commands, :forum_id
|
attr_accessor :text, :commands, :forum_id, :rename_aliased_pages
|
||||||
|
|
||||||
def initialize(text, forum_id)
|
def initialize(text, forum_id, rename_aliased_pages = "0")
|
||||||
@forum_id = forum_id
|
@forum_id = forum_id
|
||||||
@text = text
|
@text = text
|
||||||
|
@rename_aliased_pages = rename_aliased_pages
|
||||||
end
|
end
|
||||||
|
|
||||||
def process!
|
def process!
|
||||||
@@ -11,6 +12,10 @@ class AliasAndImplicationImporter
|
|||||||
parse(tokens)
|
parse(tokens)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def rename_aliased_pages?
|
||||||
|
@rename_aliased_pages == "1"
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def tokenize(text)
|
def tokenize(text)
|
||||||
@@ -40,6 +45,7 @@ private
|
|||||||
case token[0]
|
case token[0]
|
||||||
when :create_alias
|
when :create_alias
|
||||||
tag_alias = TagAlias.create(:forum_topic_id => forum_id, :status => "pending", :antecedent_name => token[1], :consequent_name => token[2])
|
tag_alias = TagAlias.create(:forum_topic_id => forum_id, :status => "pending", :antecedent_name => token[1], :consequent_name => token[2])
|
||||||
|
tag_alias.rename_wiki_and_artist if rename_aliased_pages?
|
||||||
tag_alias.delay(:queue => "default").process!
|
tag_alias.delay(:queue => "default").process!
|
||||||
|
|
||||||
when :create_implication
|
when :create_implication
|
||||||
|
|||||||
@@ -139,4 +139,27 @@ class TagAlias < ActiveRecord::Base
|
|||||||
antecedent_tag.fix_post_count if antecedent_tag
|
antecedent_tag.fix_post_count if antecedent_tag
|
||||||
consequent_tag.fix_post_count if consequent_tag
|
consequent_tag.fix_post_count if consequent_tag
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def rename_wiki_and_artist
|
||||||
|
antecedent_wiki = WikiPage.titled(antecedent_name).first
|
||||||
|
if antecedent_wiki.present? && WikiPage.titled(consequent_name).blank?
|
||||||
|
CurrentUser.scoped(creator, creator_ip_addr) do
|
||||||
|
antecedent_wiki.update_attributes(
|
||||||
|
:title => consequent_name,
|
||||||
|
:body => "[i]This page was automatically renamed from [[#{antecedent_name}]] by a tag alias.[/i]\n\n#{antecedent_wiki.body}"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if antecedent_tag.category == Tag.categories.artist
|
||||||
|
antecedent_artist = Artist.name_matches(antecedent_name).first
|
||||||
|
if antecedent_artist.present? && Artist.name_matches(consequent_name).blank?
|
||||||
|
CurrentUser.scoped(creator, creator_ip_addr) do
|
||||||
|
antecedent_artist.update_attributes(
|
||||||
|
:name => consequent_name
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -26,6 +26,13 @@ create implication aaa -> bbb
|
|||||||
<%= text_field "batch", "forum_id" %>
|
<%= text_field "batch", "forum_id" %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="input">
|
||||||
|
<label for="batch_rename_aliased_pages">
|
||||||
|
<%= check_box "batch", "rename_aliased_pages" %>
|
||||||
|
Automatically rename all wiki pages and artists for aliases in this batch
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
<%= submit_tag %>
|
<%= submit_tag %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -51,5 +51,16 @@ class AliasAndImplicationImporterTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "rename an aliased tag's artist entry and wiki page" do
|
||||||
|
tag1 = FactoryGirl.create(:tag, :name => "aaa", :category => 1)
|
||||||
|
tag2 = FactoryGirl.create(:tag, :name => "bbb")
|
||||||
|
artist = FactoryGirl.create(:artist, :name => "aaa", :notes => "testing")
|
||||||
|
@importer = AliasAndImplicationImporter.new("create alias aaa -> bbb", "", "1")
|
||||||
|
@importer.process!
|
||||||
|
artist.reload
|
||||||
|
assert_equal("bbb", artist.name)
|
||||||
|
assert_match(/automatically renamed/, artist.notes)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user