socialforge/db/migrate/20161015054820_update_homew...

21 lines
799 B
Ruby
Raw Normal View History

class UpdateHomeworkCommentStatus < ActiveRecord::Migration
def up
homeworks = HomeworkCommon.joins(:homework_detail_manual).where("publish_time is not NULL and publish_time <= '#{Date.today}' and homework_detail_manuals.comment_status = 0")
homeworks.each do |homework|
hw_dm = homework.homework_detail_manual
if hw_dm && hw_dm.comment_status == 0
if hw_dm.evaluation_end < Date.today && homework.anonymous_comment == 0
hw_dm.update_column("comment_status", 3)
elsif homework.anonymous_comment == 0 && hw_dm.evaluation_end >= Date.today && hw_dm.evaluation_start <= Date.today
hw_dm.update_column("comment_status", 2)
else
hw_dm.update_column("comment_status", 1)
end
end
end
end
def down
end
end