课程动态,历史数据的迁移
This commit is contained in:
parent
465af5e2d3
commit
ce76308864
|
@ -1,7 +1,7 @@
|
|||
class CourseActivity < ActiveRecord::Base
|
||||
attr_accessible :user_id, :course_act_id,:course_act_type,:course_id
|
||||
# 虚拟关联
|
||||
belongs_to :act ,:polymorphic => true
|
||||
belongs_to :course_act ,:polymorphic => true
|
||||
belongs_to :course
|
||||
belongs_to :user
|
||||
end
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
#encoding=UTF-8
|
||||
class CourseActivities < ActiveRecord::Migration
|
||||
def up
|
||||
Course.all.each do |course|
|
||||
transaction do
|
||||
#作业
|
||||
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
|
||||
CourseActivity.destroy_all
|
||||
end
|
||||
end
|
|
@ -0,0 +1,22 @@
|
|||
class UpdateCourseActivityTime < ActiveRecord::Migration
|
||||
def up
|
||||
count = CourseActivity.all.count / 10 + 1
|
||||
transaction do
|
||||
for i in 1 ... count do i
|
||||
CourseActivity.page(i).per(10).each do |activity|
|
||||
if activity.course_act
|
||||
if activity.course_act.respond_to?("created_at")
|
||||
activity.created_at = activity.course_act.created_at
|
||||
elsif activity.course_act.respond_to?("created_on")
|
||||
activity.created_at = activity.course_act.created_on
|
||||
end
|
||||
activity.save
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
end
|
||||
end
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20150811065543) do
|
||||
ActiveRecord::Schema.define(:version => 20150811083234) do
|
||||
|
||||
create_table "activities", :force => true do |t|
|
||||
t.integer "act_id", :null => false
|
||||
|
|
Loading…
Reference in New Issue