class ForgeMessages < ActiveRecord::Migration def up Project.all.each do |project| transaction do project.forge_messages << ForgeMessage.new(:user_id => project.user_id, :course_id => project.id) # 新闻 project.news.each do |new| new.project.members.each do |m| if m.user_id != new.author_id if m.created_on < new.created_on # 在成员加入项目之后 new.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => self.project_id, :viewed => true) end end end end # 讨论区 if project.boards.first project.boards.first.messages.each do |message| if message.parent_id.nil? # 主贴 message.project.members.each do |m| if m.user_id != message.author_id if m.created_on < message.created_on message.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => message.board.project_id, :viewed => true) end end end else # 回帖 message.project.members.each do |m| if m.user_id == Message.find(message.parent_id).author_id && m.user_id != message.author_id # 只针对主贴回复,回复自己的帖子不发消息 if m.created_on < message.created_on message.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => message.board.project_id, :viewed => true) end end end end end end # 缺陷 project.issues.each do |issue| unless issue.author_id == issue.assigned_to_id issue.forge_messages << ForgeMessage.new(:user_id => issue.assigned_to_id, :project_id => issue.project_id, :viewed => true) end end # 缺陷更新 project.issues.each do |issue| issue.journals.each do |journal| if journal.user_id != journal.issue.author_id journal.forge_messages << ForgeMessage.new(:user_id => journal.issue.author_id, :project_id => journal.issue.project_id, :viewed => true) end if journal.user_id != journal.issue.assigned_to_id && journal.issue.assigned_to_id != journal.issue.author_id # 指派人不是自己的话,则给指派人发送 journal.forge_messages << ForgeMessage.new(:user_id => journal.issue.assigned_to_id, :project_id => journal.issue.project_id, :viewed => true) end end end end end end def down end end