2023-02-27 15:26:56 +00:00
|
|
|
namespace :personal_journal do
|
|
|
|
desc 'set_journal_type'
|
2023-02-27 15:46:01 +00:00
|
|
|
task :set_journal_type => :environment do |task,args|
|
2023-02-27 15:26:56 +00:00
|
|
|
JournalPaper.where(:rss2_id.ne=>nil).update_all({"$unset"=>{"journal_type_ids"=>""}})
|
2023-03-03 14:00:53 +00:00
|
|
|
MemberTag.all.each do |mt|
|
|
|
|
journal_type = JournalType.where(:title=>mt.title).first
|
|
|
|
journal_type = JournalType.create(:title_translations=>mt.title_translations) if journal_type.nil?
|
|
|
|
journal_type_id = journal_type.id
|
|
|
|
journal_paper_ids = JournalPaper.where(:member_profile_id.in=>mt.member_profile_ids, :rss2_id.ne=>nil).pluck(:id)
|
|
|
|
JournalPaper.where(:id.in=>journal_paper_ids).update_all({"$addToSet"=>{"journal_type_ids"=>journal_type.id}})
|
|
|
|
# JournalType.where(:id=>journal_type_id).update_all({"$addToSet"=>{"journal_paper_ids"=>{"$each"=>journal_paper_ids}}})
|
|
|
|
end
|
2023-02-27 15:26:56 +00:00
|
|
|
end
|
|
|
|
end
|