personal-journal/lib/tasks/personal_journal.rake

14 lines
776 B
Ruby
Raw Normal View History

2023-02-27 15:26:56 +00:00
namespace :personal_journal do
desc 'set_journal_type'
task :set_journal_type do |task,args|
JournalPaper.where(:rss2_id.ne=>nil).update_all({"$unset"=>{"journal_type_ids"=>""}})
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
end
end