From 6f93538e60d6c3474626fd0d795cbfbfb5cd28d5 Mon Sep 17 00:00:00 2001 From: rulingcom Date: Fri, 8 Aug 2025 22:46:20 +0800 Subject: [PATCH] fixes --- lib/tasks/video_pro_tasks.rake | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/tasks/video_pro_tasks.rake b/lib/tasks/video_pro_tasks.rake index 8734878..d0f1cc1 100644 --- a/lib/tasks/video_pro_tasks.rake +++ b/lib/tasks/video_pro_tasks.rake @@ -4,14 +4,16 @@ # end namespace :video_pro_tasks do 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") dataset = {} VideoTag.all.each do |vt| 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}" 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) puts "New record #{hashtag.new_record?}" hashtag.save if hashtag.new_record?