personal-thesis-guidance/lib/tasks/personal_thesis_guidance.rake

14 lines
970 B
Ruby

namespace :personal_thesis_guidance do
desc 'set_thesis_guidance_type'
task :set_thesis_guidance_type => :environment do |task,args|
ThesisGuidancePaper.where(:rss2_id.ne=>nil).update_all({"$unset"=>{"thesis_guidance_type_ids"=>""}})
MemberTag.all.each do |mt|
thesis_guidance_type = ThesisGuidanceType.where(:title=>mt.title).first
thesis_guidance_type = ThesisGuidanceType.create(:title_translations=>mt.title_translations) if thesis_guidance_type.nil?
thesis_guidance_type_id = thesis_guidance_type.id
thesis_guidance_paper_ids = ThesisGuidancePaper.where(:member_profile_id.in=>mt.member_profile_ids, :rss2_id.ne=>nil).pluck(:id)
ThesisGuidancePaper.where(:id.in=>thesis_guidance_paper_ids).update_all({"$addToSet"=>{"thesis_guidance_type_ids"=>thesis_guidance_type.id}})
# ThesisGuidanceType.where(:id=>thesis_guidance_type_id).update_all({"$addToSet"=>{"thesis_guidance_paper_ids"=>{"$each"=>thesis_guidance_paper_ids}}})
end
end
end