迁移课程原讨论区数据

This commit is contained in:
nwb 2014-06-06 08:50:46 +08:00
parent ebe771db88
commit 388d14f075
4 changed files with 22 additions and 1 deletions

View File

@ -1,5 +1,6 @@
class CoursesController < ApplicationController
include CoursesHelper
helper :activities
menu_item l(:label_sort_by_time), :only => :index
menu_item l(:label_sort_by_active), :only => :index

View File

@ -18,6 +18,9 @@ class JournalsForMessage < ActiveRecord::Base
belongs_to :project,
:foreign_key => 'jour_id',
:conditions => "#{self.table_name}.jour_type = 'Project' "
belongs_to :course,
:foreign_key => 'jour_id',
:conditions => "#{self.table_name}.jour_type = 'Course' "
belongs_to :jour, :polymorphic => true
belongs_to :user
@ -87,6 +90,8 @@ class JournalsForMessage < ActiveRecord::Base
end
elsif self.jour_type == 'Project'
self.acts << Activity.new(:user_id => self.reply_id)
elsif self.jour_type == 'Course'
self.acts << Activity.new(:user_id => self.reply_id)
else
end
end

View File

@ -0,0 +1,15 @@
class MigrateCourseJournals < ActiveRecord::Migration
def self.up
# 原课程的讨论区数据迁移成新模式
JournalsForMessage.find_all_by_jour_type('Project').each do |journal|
project = Project.find_by_id(journal.jour_id)
if project && project.project_type == 1
journal.jour_type = 'Course'
journal.save
end
end
end
def self.down
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 => 20140605025303) do
ActiveRecord::Schema.define(:version => 20140606027403) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false