parent
b8bc32c127
commit
98d533e8f9
|
@ -10,7 +10,7 @@ class CourseActivity < ActiveRecord::Base
|
|||
|
||||
#在个人动态里面增加当前动态
|
||||
def add_user_activity
|
||||
user_activity = UserActivity.where("act_type = '#{self.class.to_s}' and act_id = '#{self.id}'").first
|
||||
user_activity = UserActivity.where("act_type = '#{self.course_act_type.to_s}' and act_id = '#{self.course_act_id}'").first
|
||||
if user_activity
|
||||
user_activity.save
|
||||
else
|
||||
|
@ -24,7 +24,7 @@ class CourseActivity < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def destroy_user_activity
|
||||
user_activity = UserActivity.where("act_type = '#{self.class.to_s}' and act_id = '#{self.id}'")
|
||||
user_activity = UserActivity.where("act_type = '#{self.course_act_type.to_s}' and act_id = '#{self.course_act_id}'")
|
||||
user_activity.destroy_all
|
||||
end
|
||||
end
|
||||
|
|
|
@ -25,7 +25,7 @@ class ForgeActivity < ActiveRecord::Base
|
|||
|
||||
#在个人动态里面增加当前动态
|
||||
def add_user_activity
|
||||
user_activity = UserActivity.where("act_type = '#{self.class.to_s}' and act_id = '#{self.id}'").first
|
||||
user_activity = UserActivity.where("act_type = '#{self.forge_act_type.to_s}' and act_id = '#{self.forge_act_id}'").first
|
||||
if user_activity
|
||||
user_activity.save
|
||||
else
|
||||
|
@ -39,7 +39,7 @@ class ForgeActivity < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def destroy_user_activity
|
||||
user_activity = UserActivity.where("act_type = '#{self.class.to_s}' and act_id = '#{self.id}'")
|
||||
user_activity = UserActivity.where("act_type = '#{self.forge_act_type.to_s}' and act_id = '#{self.forge_act_id}'")
|
||||
user_activity.destroy_all
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,6 +3,6 @@ class AddCreatedAtToActivities < ActiveRecord::Migration
|
|||
add_column :activities, :created_at, :timestamp
|
||||
end
|
||||
def end
|
||||
remove_column :activities, :created_at
|
||||
remove_column :activities, :created_at
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
class UpdateActivitiesData < ActiveRecord::Migration
|
||||
def up
|
||||
count = Activity.all.count / 20 + 1
|
||||
transaction do
|
||||
for i in 1 ... count do i
|
||||
Activity.page(i).per(20).each do |activity|
|
||||
type = activity.act_type
|
||||
if type=='Contest' || type=='Message' || type=='News'|| type=='Journal'|| type=='Issue'|| type=='Principal'||type=='JournalsForMessage'
|
||||
activity.created_at = activity.act.created_on if activity.act
|
||||
elsif type=='Contestnotification' || type=='HomeworkCommon' || type=='Poll'
|
||||
activity.created_at = activity.act.created_at if activity.act
|
||||
end
|
||||
activity.save
|
||||
end
|
||||
end
|
||||
end
|
||||
# count = Activity.all.count / 20 + 1
|
||||
# transaction do
|
||||
# for i in 1 ... count do i
|
||||
# Activity.page(i).per(20).each do |activity|
|
||||
# type = activity.act_type
|
||||
# if type=='Contest' || type=='Message' || type=='News'|| type=='Journal'|| type=='Issue'|| type=='Principal'||type=='JournalsForMessage'
|
||||
# activity.created_at = activity.act.created_on if activity.act
|
||||
# elsif type=='Contestnotification' || type=='HomeworkCommon' || type=='Poll'
|
||||
# activity.created_at = activity.act.created_at if activity.act
|
||||
# end
|
||||
# activity.save
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -1,5 +1,14 @@
|
|||
class AddCourseActivities < ActiveRecord::Migration
|
||||
def up
|
||||
create_table :user_activities do |t|
|
||||
t.string :act_type
|
||||
t.integer :act_id
|
||||
t.string :container_type
|
||||
t.integer :container_id
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
create_table :course_activities do |t|
|
||||
t.integer :user_id
|
||||
t.integer :course_id
|
||||
|
@ -11,5 +20,6 @@ class AddCourseActivities < ActiveRecord::Migration
|
|||
|
||||
def down
|
||||
drop_table :course_activities
|
||||
drop_table :user_activities
|
||||
end
|
||||
end
|
||||
|
|
|
@ -35,6 +35,6 @@ class CourseActivities < ActiveRecord::Migration
|
|||
end
|
||||
|
||||
def down
|
||||
CourseActivity.destroy_all
|
||||
# CourseActivity.destroy_all
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
class UpdateCourseActivityTime < ActiveRecord::Migration
|
||||
def up
|
||||
count = CourseActivity.all.count / 10 + 1
|
||||
count = CourseActivity.all.count / 30 + 1
|
||||
transaction do
|
||||
for i in 1 ... count do i
|
||||
CourseActivity.page(i).per(10).each do |activity|
|
||||
CourseActivity.page(i).per(30).each do |activity|
|
||||
if activity.course_act
|
||||
if activity.course_act.respond_to?("created_at")
|
||||
activity.created_at = activity.course_act.created_at
|
||||
|
@ -11,6 +11,10 @@ class UpdateCourseActivityTime < ActiveRecord::Migration
|
|||
activity.created_at = activity.course_act.created_on
|
||||
end
|
||||
activity.save
|
||||
|
||||
user_activity = UserActivity.where("act_type = '#{activity.course_act_type.to_s}' and act_id = '#{activity.course_act_id}'").first
|
||||
user_activity.created_at = activity.created_at
|
||||
user_activity.save
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,16 +1,9 @@
|
|||
class CreateUserActivity < ActiveRecord::Migration
|
||||
def up
|
||||
create_table :user_activities do |t|
|
||||
t.string :act_type
|
||||
t.integer :act_id
|
||||
t.string :container_type
|
||||
t.integer :container_id
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
drop_table :user_activities
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,23 +15,23 @@ class AboutUserActivities < ActiveRecord::Migration
|
|||
end
|
||||
end
|
||||
|
||||
course_count = CourseActivity.all.count / 30 + 2
|
||||
transaction do
|
||||
for i in 1 ... course_count do i
|
||||
CourseActivity.page(i).per(30).each do |activity|
|
||||
user_activity = UserActivity.new
|
||||
user_activity.act_id = activity.course_act_id
|
||||
user_activity.act_type = activity.course_act_type
|
||||
user_activity.container_type = "Course"
|
||||
user_activity.container_id = activity.course_id
|
||||
user_activity.created_at = activity.created_at
|
||||
user_activity.save
|
||||
end
|
||||
end
|
||||
end
|
||||
# course_count = CourseActivity.all.count / 30 + 2
|
||||
# transaction do
|
||||
# for i in 1 ... course_count do i
|
||||
# CourseActivity.page(i).per(30).each do |activity|
|
||||
# user_activity = UserActivity.new
|
||||
# user_activity.act_id = activity.course_act_id
|
||||
# user_activity.act_type = activity.course_act_type
|
||||
# user_activity.container_type = "Course"
|
||||
# user_activity.container_id = activity.course_id
|
||||
# user_activity.created_at = activity.created_at
|
||||
# user_activity.save
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
end
|
||||
|
||||
def down
|
||||
UserActivity.destroy_all
|
||||
# UserActivity.destroy_all
|
||||
end
|
||||
end
|
||||
|
|
|
@ -913,7 +913,6 @@ ActiveRecord::Schema.define(:version => 20150826061843) do
|
|||
t.datetime "created_on"
|
||||
t.integer "comments_count", :default => 0, :null => false
|
||||
t.integer "course_id"
|
||||
t.datetime "updated_on"
|
||||
end
|
||||
|
||||
add_index "news", ["author_id"], :name => "index_news_on_author_id"
|
||||
|
|
Loading…
Reference in New Issue