From 0480405afb9497714c3932ae1d87b2030d3109c0 Mon Sep 17 00:00:00 2001 From: nwb Date: Wed, 18 Jun 2014 11:08:44 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9=E5=8E=9F=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E5=90=84=E6=95=B0=E6=8D=AE=E8=BF=81=E7=A7=BB=E6=96=87=E4=BB=B6?= =?UTF-8?q?BUG=202.=E8=BF=81=E7=A7=BB=E8=AF=BE=E7=A8=8B=E5=AD=A6=E7=94=9F?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/bids_controller.rb | 1 + app/controllers/courses_controller.rb | 2 +- app/helpers/courses_helper.rb | 4 +-- app/helpers/watchers_helper.rb | 4 ++- ...0140603033359_add_boards_type_to_boards.rb | 21 ++++++------ ...3081801_add_courseid_to_enabled_modules.rb | 21 ++++++------ ...140604011630_add_courseid_to_to_members.rb | 21 ++++++------ ...name_project_id_to_homework_for_courses.rb | 10 ++++++ ...140605025302_migrate_course_attachments.rb | 1 + .../20140605025303_migrate_course_tags.rb | 1 + .../20140606027403_migrate_course_journals.rb | 1 + .../20140611161801_add_courseid_to_news.rb | 18 ++++++++-- .../20140618105213_migrate_course_students.rb | 13 +++++++ db/schema.rb | 34 ++++++++++--------- 14 files changed, 99 insertions(+), 53 deletions(-) create mode 100644 db/migrate/20140618105213_migrate_course_students.rb diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index 1862c782..633160c1 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -287,6 +287,7 @@ class BidsController < ApplicationController end #end + # 显示课程 def show_course bids = Bid.where('parent_id = ?', @bid.id) @courses = [] diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 4e74449e..49341d58 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -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 diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index f3eab89e..afb19454 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -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 diff --git a/app/helpers/watchers_helper.rb b/app/helpers/watchers_helper.rb index a5672766..00867d9f 100644 --- a/app/helpers/watchers_helper.rb +++ b/app/helpers/watchers_helper.rb @@ -85,7 +85,9 @@ module WatchersHelper link_to text, url_f, :remote => true, :method => method, :id => "#{course.id}", :class => []+options end end - + + # 用户是否允许加入课程判断 + # add by nwb def join_in_course_for_list(course, user, options=[]) return '' unless user && user.logged? # modify by nwb diff --git a/db/migrate/20140603033359_add_boards_type_to_boards.rb b/db/migrate/20140603033359_add_boards_type_to_boards.rb index ea06cc20..fcef8b11 100644 --- a/db/migrate/20140603033359_add_boards_type_to_boards.rb +++ b/db/migrate/20140603033359_add_boards_type_to_boards.rb @@ -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 diff --git a/db/migrate/20140603081801_add_courseid_to_enabled_modules.rb b/db/migrate/20140603081801_add_courseid_to_enabled_modules.rb index e31c3f95..be4fe7e6 100644 --- a/db/migrate/20140603081801_add_courseid_to_enabled_modules.rb +++ b/db/migrate/20140603081801_add_courseid_to_enabled_modules.rb @@ -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 diff --git a/db/migrate/20140604011630_add_courseid_to_to_members.rb b/db/migrate/20140604011630_add_courseid_to_to_members.rb index 9dd66c7f..583e3a2d 100644 --- a/db/migrate/20140604011630_add_courseid_to_to_members.rb +++ b/db/migrate/20140604011630_add_courseid_to_to_members.rb @@ -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 diff --git a/db/migrate/20140604071624_rename_project_id_to_homework_for_courses.rb b/db/migrate/20140604071624_rename_project_id_to_homework_for_courses.rb index e7cd811a..7336fe73 100644 --- a/db/migrate/20140604071624_rename_project_id_to_homework_for_courses.rb +++ b/db/migrate/20140604071624_rename_project_id_to_homework_for_courses.rb @@ -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 diff --git a/db/migrate/20140605025302_migrate_course_attachments.rb b/db/migrate/20140605025302_migrate_course_attachments.rb index 447624fa..358710c9 100644 --- a/db/migrate/20140605025302_migrate_course_attachments.rb +++ b/db/migrate/20140605025302_migrate_course_attachments.rb @@ -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 diff --git a/db/migrate/20140605025303_migrate_course_tags.rb b/db/migrate/20140605025303_migrate_course_tags.rb index 17f93d40..6e95839e 100644 --- a/db/migrate/20140605025303_migrate_course_tags.rb +++ b/db/migrate/20140605025303_migrate_course_tags.rb @@ -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 diff --git a/db/migrate/20140606027403_migrate_course_journals.rb b/db/migrate/20140606027403_migrate_course_journals.rb index 44b3e562..40c57e81 100644 --- a/db/migrate/20140606027403_migrate_course_journals.rb +++ b/db/migrate/20140606027403_migrate_course_journals.rb @@ -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 diff --git a/db/migrate/20140611161801_add_courseid_to_news.rb b/db/migrate/20140611161801_add_courseid_to_news.rb index 9e08a446..5ca62a6a 100644 --- a/db/migrate/20140611161801_add_courseid_to_news.rb +++ b/db/migrate/20140611161801_add_courseid_to_news.rb @@ -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 diff --git a/db/migrate/20140618105213_migrate_course_students.rb b/db/migrate/20140618105213_migrate_course_students.rb new file mode 100644 index 00000000..b9ac6671 --- /dev/null +++ b/db/migrate/20140618105213_migrate_course_students.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 2af470d0..6481ace3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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 @@ -742,18 +742,18 @@ ActiveRecord::Schema.define(:version => 20140611161801) do create_table "relative_memos", :force => true do |t| t.integer "osp_id" t.integer "parent_id" - t.string "subject", :null => false - t.text "content", :null => false + t.string "subject", :null => false + t.text "content", :limit => 16777215, :null => false t.integer "author_id" - t.integer "replies_count", :default => 0 + t.integer "replies_count", :default => 0 t.integer "last_reply_id" - t.boolean "lock", :default => false - t.boolean "sticky", :default => false - t.boolean "is_quote", :default => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - t.integer "viewed_count_crawl", :default => 0 - t.integer "viewed_count_local", :default => 0 + t.boolean "lock", :default => false + t.boolean "sticky", :default => false + t.boolean "is_quote", :default => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.integer "viewed_count_crawl", :default => 0 + t.integer "viewed_count_local", :default => 0 t.string "url" t.string "username" t.string "userhomeurl" @@ -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 "collaboration" - t.integer "influence" - t.integer "skill" - t.integer "activity" + t.integer "user_id", :null => false + t.integer "collaboration" + t.integer "influence" + t.integer "skill" + t.integer "active" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "user_statuses", :force => true do |t|