消息数据迁移(未完)
This commit is contained in:
parent
5ce5fa218f
commit
f438d300dd
|
@ -37,7 +37,8 @@ class Course < ActiveRecord::Base
|
||||||
has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy
|
has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy
|
||||||
|
|
||||||
has_many :course_activities
|
has_many :course_activities
|
||||||
has_many :course_messages
|
# 课程消息
|
||||||
|
has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy
|
||||||
|
|
||||||
acts_as_taggable
|
acts_as_taggable
|
||||||
acts_as_nested_set :order => 'name', :dependent => :destroy
|
acts_as_nested_set :order => 'name', :dependent => :destroy
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
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
|
|
@ -0,0 +1,38 @@
|
||||||
|
class CourseMessages < ActiveRecord::Migration
|
||||||
|
def up
|
||||||
|
Course.all.each do |course|
|
||||||
|
transaction do
|
||||||
|
course.course_messages << CourseActivity.new(:user_id => course.tea_id,:course_id => course.id)
|
||||||
|
#作业
|
||||||
|
course.homework_commons.each do |homework_common|
|
||||||
|
homework_common.course_acts << CourseActivity.new(:user_id => homework_common.user_id,:course_id => course.id)
|
||||||
|
end
|
||||||
|
#通知
|
||||||
|
course.news.each do |new|
|
||||||
|
new.course_acts << CourseActivity.new(:user_id => new.author_id,:course_id => course.id)
|
||||||
|
end
|
||||||
|
#资源
|
||||||
|
course.attachments.each do |attachment|
|
||||||
|
attachment.course_acts << CourseActivity.new(:user_id => attachment.author_id,:course_id => course.id)
|
||||||
|
end
|
||||||
|
#讨论区
|
||||||
|
if course.boards.first
|
||||||
|
course.boards.first.messages.each do |message|
|
||||||
|
message.course_acts << CourseActivity.new(:user_id => message.author_id,:course_id => course.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
#留言
|
||||||
|
course.journals_for_messages.each do |jour|
|
||||||
|
jour.course_acts << CourseActivity.new(:user_id => jour.user_id,:course_id => course.id)
|
||||||
|
end
|
||||||
|
#问卷
|
||||||
|
Poll.where("polls_type = 'Course' and polls_group_id = #{course.id}").each do |poll|
|
||||||
|
poll.course_acts << CourseActivity.new(:user_id => poll.user_id,:course_id => course.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue