迁移课程原讨论区数据
This commit is contained in:
parent
ebe771db88
commit
388d14f075
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue