项目资源库历史数据迁移

搜索功能添加Version类型判断
This commit is contained in:
huang 2016-01-08 11:01:29 +08:00
parent e56382a899
commit fd2197a73d
4 changed files with 15 additions and 2 deletions

View File

@ -268,6 +268,8 @@ class FilesController < ApplicationController
else
sort = "#{Attachment.table_name}.created_on desc"
end
# @containers = [ Project.includes(:attachments).find(@project.id)]
# @containers += @project.versions.includes(:attachments).all
@containers = [ Project.includes(:attachments).reorder(sort).find(@project.id)]

View File

@ -618,7 +618,7 @@ class Attachment < ActiveRecord::Base
end
end
def update_attachment_ealasticsearch_index
if self.is_public == 1 && ( (self.container_type == 'Project' && Project.find(self.container_id).is_public == 1) ||
if self.is_public == 1 && ( ((self.container_type == 'Project' or self.container_type == 'Version') && Project.find(self.container_id).is_public == 1) ||
( self.container_type == 'Course' && Course.find(self.container_id).is_public == 1) ||
self.container_type == 'Principal')
begin

View File

@ -0,0 +1,11 @@
class ChangeAttachmentHistory < ActiveRecord::Migration
def up
attachments = Attachment.where("container_type =?", "Version")
attachments.each do |am|
am.update_attribute(:container_type, "Project") unless am.nil?
end
end
def 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 => 20160105073350) do
ActiveRecord::Schema.define(:version => 20160108021447) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false