2024-10-13 13:42:37 +00:00
|
|
|
module Announcement
|
|
|
|
module Migrate
|
|
|
|
def self.call
|
|
|
|
puts ['announcement migrate start']
|
|
|
|
gem_root = Announcement::Engine.root
|
|
|
|
require File.join(gem_root, 'app/models/announcement_setting')
|
|
|
|
require File.join(gem_root, 'app/models/bulletin')
|
|
|
|
require File.join(gem_root, 'app/models/bulletin_feed')
|
|
|
|
require File.join(gem_root, 'app/models/bulletin_feed_cache')
|
2024-11-07 14:12:16 +00:00
|
|
|
require File.join(gem_root, 'app/models/anns_cache')
|
2024-10-13 13:42:37 +00:00
|
|
|
|
2024-11-07 14:12:16 +00:00
|
|
|
setting = AnnouncementSetting.first || AnnouncementSetting.create
|
2024-10-13 13:42:37 +00:00
|
|
|
|
|
|
|
if !setting.migrate_flag.include?("v1")
|
|
|
|
Bulletin.all.pluck(:id, :title).each do |id, title_translations|
|
|
|
|
if title_translations.nil?
|
|
|
|
next
|
|
|
|
end
|
|
|
|
Bulletin.where(id: id).view.update_many({
|
|
|
|
"$set" => {
|
|
|
|
title_plain_text: OrbitHelper.get_plain_text_translations(title_translations)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
setting.migrate_flag << "v1"
|
|
|
|
setting.save
|
|
|
|
end
|
|
|
|
|
|
|
|
AnnsCache.all.delete
|
|
|
|
|
|
|
|
#solve bug for thousands of generated feed cache
|
|
|
|
if BulletinFeedCache.count > BulletinFeed.count*5
|
|
|
|
BulletinFeedCache.collection.drop
|
|
|
|
end
|
|
|
|
BulletinFeedCache.regenerate_all
|
|
|
|
|
|
|
|
puts ['announcement migrate end']
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|