Fix #4017: Artist tag in upload page should account for aliases

Disallow creating artist entries for aliased tags. Add a fix script to
move existing artist entries for tags that have been aliased.
This commit is contained in:
evazion
2022-02-01 12:17:52 -06:00
parent 2d47ae70b0
commit 6d2a2eee59
3 changed files with 47 additions and 6 deletions

View File

@@ -0,0 +1,29 @@
#!/usr/bin/env ruby
require_relative "base"
# Fix artist entries where the tag was aliased but the URLs weren't moved to
# the new artist entry.
with_confirmation do
CurrentUser.scoped(User.system, "127.0.0.1") do
aliased_artists = Artist.joins(:tag_alias).where.associated(:urls).distinct
aliased_artists.each do |artist|
next if artist.tag.category_name != "Artist"
next if artist.tag_alias.consequent_tag.category_name != "Artist"
old_name = artist.name
new_name = artist.tag_alias.consequent_name
artist.update_attribute(:is_deleted, false) # undelete first so the tag move works
TagMover.new(old_name, new_name).move_artist!
added_urls = (artist.urls - Artist.find_by_name(new_name).urls).map(&:url)
puts({
old_name: old_name,
new_name: new_name,
added_urls: added_urls,
}.to_json)
end
end
end