This commit is contained in:
Toks
2013-05-02 22:25:44 -04:00
parent d5d68fcff9
commit 0f5fe4e7b6
5 changed files with 50 additions and 3 deletions

View File

@@ -6,7 +6,7 @@ module Admin
end
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!
flash[:notice] = "Import queued"
redirect_to new_admin_alias_and_implication_import_path

View File

@@ -1,9 +1,10 @@
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
@text = text
@rename_aliased_pages = rename_aliased_pages
end
def process!
@@ -11,6 +12,10 @@ class AliasAndImplicationImporter
parse(tokens)
end
def rename_aliased_pages?
@rename_aliased_pages == "1"
end
private
def tokenize(text)
@@ -40,6 +45,7 @@ private
case token[0]
when :create_alias
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!
when :create_implication

View File

@@ -139,4 +139,27 @@ class TagAlias < ActiveRecord::Base
antecedent_tag.fix_post_count if antecedent_tag
consequent_tag.fix_post_count if consequent_tag
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

View File

@@ -26,6 +26,13 @@ create implication aaa -> bbb
<%= text_field "batch", "forum_id" %>
</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 %>
<% end %>
</div>

View File

@@ -51,5 +51,16 @@ class AliasAndImplicationImporterTest < ActiveSupport::TestCase
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