This commit is contained in:
rulingcom 2025-08-08 22:46:20 +08:00
parent 5bb521685f
commit 6f93538e60
1 changed files with 4 additions and 2 deletions

View File

@ -4,14 +4,16 @@
# end # end
namespace :video_pro_tasks do namespace :video_pro_tasks do
desc "Migrate old tags to new tags" desc "Migrate old tags to new tags"
task :migrate_tags => :environment do task :migrate_hashtags => :environment do
module_app = ModuleApp.find_by_key("video_pro") module_app = ModuleApp.find_by_key("video_pro")
dataset = {} dataset = {}
VideoTag.all.each do |vt| VideoTag.all.each do |vt|
next if vt.title.blank? # Skip if tag name is blank next if vt.title.blank? # Skip if tag name is blank
next if vt.video_images.empty? # Skip if no images are associated with the tag
puts "Processing tag: #{vt.title}" puts "Processing tag: #{vt.title}"
module_app.reload module_app.reload
hashtag = module_app.hashtags.where(name: vt.title).first_or_initialize tag_str = vt.title.gsub(/^#+/, '').downcase.strip
hashtag = module_app.hashtags.where(name: tag_str).first_or_initialize
hashtag.module_app_ids << module_app.id.to_s unless hashtag.module_app_ids.include?(module_app.id.to_s) hashtag.module_app_ids << module_app.id.to_s unless hashtag.module_app_ids.include?(module_app.id.to_s)
puts "New record #{hashtag.new_record?}" puts "New record #{hashtag.new_record?}"
hashtag.save if hashtag.new_record? hashtag.save if hashtag.new_record?