|
|
|
@@ -79,25 +79,11 @@ class Tag < ApplicationRecord |
|
|
|
|
|
|
|
def material_id = materials.first&.id |
|
|
|
|
|
|
|
def self.tagme |
|
|
|
@tagme ||= find_or_create_by_tag_name!('タグ希望', category: :meta) |
|
|
|
end |
|
|
|
|
|
|
|
def self.bot |
|
|
|
@bot ||= find_or_create_by_tag_name!('bot操作', category: :meta) |
|
|
|
end |
|
|
|
|
|
|
|
def self.no_deerjikist |
|
|
|
@no_deerjikist ||= find_or_create_by_tag_name!('ニジラー情報不詳', category: :meta) |
|
|
|
end |
|
|
|
|
|
|
|
def self.video |
|
|
|
@video ||= find_or_create_by_tag_name!('動画', category: :meta) |
|
|
|
end |
|
|
|
|
|
|
|
def self.niconico |
|
|
|
@niconico ||= find_or_create_by_tag_name!('ニコニコ', category: :meta) |
|
|
|
end |
|
|
|
def self.tagme = find_or_create_by_tag_name!('タグ希望', category: :meta) |
|
|
|
def self.bot = find_or_create_by_tag_name!('bot操作', category: :meta) |
|
|
|
def self.no_deerjikist = find_or_create_by_tag_name!('ニジラー情報不詳', category: :meta) |
|
|
|
def self.video = find_or_create_by_tag_name!('動画', category: :meta) |
|
|
|
def self.niconico = find_or_create_by_tag_name!('ニコニコ', category: :meta) |
|
|
|
|
|
|
|
def self.normalise_tags tag_names, with_tagme: true, |
|
|
|
with_no_deerjikist: true, |
|
|
|
@@ -159,11 +145,15 @@ class Tag < ApplicationRecord |
|
|
|
affected_post_ids = Set.new |
|
|
|
|
|
|
|
Tag.transaction do |
|
|
|
TagVersioning.ensure_snapshot!(target_tag, created_by_user:) |
|
|
|
|
|
|
|
Array(source_tags).compact.uniq.each do |source_tag| |
|
|
|
source_tag => Tag |
|
|
|
|
|
|
|
next if source_tag == target_tag |
|
|
|
|
|
|
|
TagVersioning.ensure_snapshot!(source_tag, created_by_user:) |
|
|
|
|
|
|
|
source_tag.post_tags.kept.find_each do |source_pt| |
|
|
|
post_id = source_pt.post_id |
|
|
|
affected_post_ids << post_id |
|
|
|
@@ -179,6 +169,7 @@ class Tag < ApplicationRecord |
|
|
|
raise ActiveRecord::RecordInvalid.new(source_tag_name) |
|
|
|
end |
|
|
|
|
|
|
|
TagVersioning.record!(source_tag, event_type: :discard, created_by_user:) |
|
|
|
source_tag.discard! |
|
|
|
|
|
|
|
if source_tag.nico? |
|
|
|
@@ -188,11 +179,11 @@ class Tag < ApplicationRecord |
|
|
|
updated_at: Time.current) |
|
|
|
end |
|
|
|
|
|
|
|
TagVersioning.record!(source_tag, event_type: :discard, created_by_user:) |
|
|
|
TagVersioning.record!(target_tag, event_type: :update, created_by_user:) |
|
|
|
end |
|
|
|
|
|
|
|
Post.where(id: affected_post_ids.to_a).find_each do |post| |
|
|
|
PostVersionRecorder.ensure_snapshot!(post, created_by_user:) |
|
|
|
PostVersionRecorder.record!(post:, event_type: :update, created_by_user:) |
|
|
|
end |
|
|
|
|
|
|
|
|