1.修改原课程各数据迁移文件BUG

2.迁移课程学生数据
This commit is contained in:
nwb 2014-06-18 11:08:44 +08:00
parent 3afb70bf84
commit 0480405afb
14 changed files with 99 additions and 53 deletions

View File

@ -287,6 +287,7 @@ class BidsController < ApplicationController
end
#end
# 显示课程
def show_course
bids = Bid.where('parent_id = ?', @bid.id)
@courses = []

View File

@ -105,7 +105,7 @@ class CoursesController < ApplicationController
@course_count = @courses_all.count
@course_pages = Paginator.new @course_count, per_page_option, params['page']
# 课程的动态数
@course_activity_count=Hash.new
@courses_all.each do |course|
@course_activity_count[course.id]=0

View File

@ -91,8 +91,8 @@ module CoursesHelper
end
alias studentCountOrigin studentCount
def studentCount project
count = studentCountOrigin project
def studentCount course
count = studentCountOrigin course
garble count
end

View File

@ -86,6 +86,8 @@ module WatchersHelper
end
end
# 用户是否允许加入课程判断
# add by nwb
def join_in_course_for_list(course, user, options=[])
return '' unless user && user.logged?
# modify by nwb

View File

@ -2,17 +2,18 @@ class AddBoardsTypeToBoards < ActiveRecord::Migration
def change
add_column :boards, :course_id, :int
Board.where('project_id IN (SELECT id FROM projects WHERE project_type=1)').update_all("course_id = project_id")
Board.where('project_id IN (SELECT id FROM projects WHERE project_type=1)').update_all(project_id: -1)
# course_id不能直接设置为 project_id
#Board.where('project_id IN (SELECT id FROM projects WHERE project_type=1)').update_all("course_id = project_id")
#Board.where('project_id IN (SELECT id FROM projects WHERE project_type=1)').update_all(project_id: -1)
#Board.all.each do |board|
# project = Project.find_by_id(board.project_id)
# if project && project.project_type == 1
# board.course_id = board.project_id
# board.project_id = -1
# board.save
# end
# end
Board.all.each do |board|
project = Project.find_by_id(board.project_id)
if project && project.project_type == 1
board.course_id = project.course_extra.id
board.project_id = -1
board.save
end
end
end
end

View File

@ -2,16 +2,17 @@ class AddCourseidToEnabledModules < ActiveRecord::Migration
def change
add_column :enabled_modules, :course_id, :int
EnabledModule.where('project_id IN (SELECT id FROM projects WHERE project_type=1)').update_all("course_id = project_id")
EnabledModule.where('project_id IN (SELECT id FROM projects WHERE project_type=1)').update_all(project_id: -1)
#couese_id不能直接设置为project_id
#EnabledModule.where('project_id IN (SELECT id FROM projects WHERE project_type=1)').update_all("course_id = project_id")
#EnabledModule.where('project_id IN (SELECT id FROM projects WHERE project_type=1)').update_all(project_id: -1)
#EnabledModule.all.each do |enablemodule|
# project = Project.find_by_id(enablemodule.project_id)
# if project && project.project_type == 1
# enablemodule.course_id = enablemodule.project_id
# enablemodule.project_id = -1
# enablemodule.save
# end
#end
EnabledModule.all.each do |enablemodule|
project = Project.find_by_id(enablemodule.project_id)
if project && project.project_type == 1
enablemodule.course_id = project.course_extra.id
enablemodule.project_id = -1
enablemodule.save
end
end
end
end

View File

@ -5,17 +5,18 @@ class AddCourseidToToMembers < ActiveRecord::Migration
remove_index :members, name: 'index_members_on_user_id_and_project_id'
add_index "members", ["user_id", "project_id","course_id"], :name => "index_members_on_user_id_and_project_id", :unique => true
Member.where('project_id IN (SELECT id FROM projects WHERE project_type=1)').update_all("course_id = project_id")
Member.where('project_id IN (SELECT id FROM projects WHERE project_type=1)').update_all(project_id: -1)
#couese_id不能直接设置为project_id
#Member.where('project_id IN (SELECT id FROM projects WHERE project_type=1)').update_all("course_id = project_id")
#Member.where('project_id IN (SELECT id FROM projects WHERE project_type=1)').update_all(project_id: -1)
# 课程成员数据迁移
#Member.all.each do |member|
# project = Project.find_by_id(member.project_id)
# if project && project.project_type == 1
# member.course_id = member.project_id
# member.project_id = -1
# member.save
# end
#end
Member.all.each do |member|
project = Project.find_by_id(member.project_id)
if project && project.project_type == 1
member.course_id = project.course_extra.id
member.project_id = -1
member.save
end
end
end
end

View File

@ -1,5 +1,15 @@
class RenameProjectIdToHomeworkForCourses < ActiveRecord::Migration
def change
rename_column(:homework_for_courses, :project_id, :course_id)
# 作业数据迁移
HomeworkForCourse.all.each do |work|
project = Project.find_by_id(work.project_id)
if project && project.project_type == 1
work.course_id = project.course_extra.id
work.project_id = -1
work.save
end
end
end
end

View File

@ -6,6 +6,7 @@ class MigrateCourseAttachments < ActiveRecord::Migration
project = Project.find_by_id(attach.container_id)
if project && project.project_type == 1
attach.container_type= 'Course'
attach.container_id = project.course_extra.id
attach.save
end
end

View File

@ -6,6 +6,7 @@ class MigrateCourseTags < ActiveRecord::Migration
project = Project.find_by_id(tagging.taggable_id)
if project && project.project_type == 1
tagging.taggable_type= 'Course'
tagging.taggable_id = project.course_extra.id
tagging.save
end
end

View File

@ -5,6 +5,7 @@ class MigrateCourseJournals < ActiveRecord::Migration
project = Project.find_by_id(journal.jour_id)
if project && project.project_type == 1
journal.jour_type = 'Course'
journal.jour_id = project.course_extra.id
journal.save
end
end

View File

@ -1,10 +1,22 @@
class AddCourseidToNews < ActiveRecord::Migration
#迁移原课程新闻数据
#迁移原课程通知数据
def change
add_column :news, :course_id, :int
News.where('project_id IN (SELECT id FROM projects WHERE project_type=1)').update_all("course_id = project_id")
News.where('project_id IN (SELECT id FROM projects WHERE project_type=1)').update_all(project_id: -1)
# course_id不能直接设置为 project_id
#News.where('project_id IN (SELECT id FROM projects WHERE project_type=1)').update_all("course_id = project_id")
#News.where('project_id IN (SELECT id FROM projects WHERE project_type=1)').update_all(project_id: -1)
News.all.each do |news|
project = Project.find_by_id(news.project_id)
if project && project.project_type == 1
news.course_id = project.course_extra.id
news.project_id = -1
news.save
end
end
end
end

View File

@ -0,0 +1,13 @@
class MigrateCourseStudents < ActiveRecord::Migration
def change
# 原课程的学生数据迁移成新模式
StudentsForCourse.all.each do |student|
project = Project.find_by_id(student.course_id)
if project
student.course_id = project.course_extra.id
student.save
end
end
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20140611161801) do
ActiveRecord::Schema.define(:version => 20140618105213) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -743,7 +743,7 @@ ActiveRecord::Schema.define(:version => 20140611161801) do
t.integer "osp_id"
t.integer "parent_id"
t.string "subject", :null => false
t.text "content", :null => false
t.text "content", :limit => 16777215, :null => false
t.integer "author_id"
t.integer "replies_count", :default => 0
t.integer "last_reply_id"
@ -972,11 +972,13 @@ ActiveRecord::Schema.define(:version => 20140611161801) do
add_index "user_preferences", ["user_id"], :name => "index_user_preferences_on_user_id"
create_table "user_scores", :force => true do |t|
t.integer "user_id"
t.integer "user_id", :null => false
t.integer "collaboration"
t.integer "influence"
t.integer "skill"
t.integer "activity"
t.integer "active"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "user_statuses", :force => true do |t|