tags: ensure aliased tag categories stay in sync.
* When a tag's category is changed, also change the category of any aliases pointing to it. For example, if "ff7" is aliased to "final_fantasy_vii", and "final_fantasy_vii" is changed to a copyright tag, then change the empty "ff7" tag to be a copyright tag too. * Don't allow changing the category of an aliased tag. For example, if "ff7" is aliased to "final_fantasy_vii", then don't allow changing the "ff7" tag to be a non-copyright tag. This ensures that the categories of aliased tags stay in sync with that of their parent tags. This way aliased tags are colored correctly in wikis and other places.
This commit is contained in:
15
script/fixes/131_fix_aliased_tag_categories.rb
Executable file
15
script/fixes/131_fix_aliased_tag_categories.rb
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
require_relative "base"
|
||||
|
||||
with_confirmation do
|
||||
fix = ENV.fetch("FIX", "false").truthy?
|
||||
|
||||
aliases = TagAlias.active.joins(:antecedent_tag, :consequent_tag).where("tags.category != consequent_tags_tag_aliases.category")
|
||||
aliases.find_each do |tag_alias|
|
||||
tag_alias.antecedent_tag.assign_attributes(category: tag_alias.consequent_tag.category, updater: User.system)
|
||||
|
||||
puts ({ id: tag_alias.id, from: tag_alias.antecedent_tag.name, to: tag_alias.consequent_tag.name, changes: tag_alias.antecedent_tag.changes }).to_json
|
||||
tag_alias.antecedent_tag.save!(touch: false) if fix
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user