socialforge/db/migrate/20140710030426_update_attac...

23 lines
838 B
Ruby

class UpdateAttachmentPublicAttr < ActiveRecord::Migration
def up
# 更新资源文件的is_public属性
Attachment.all.each do |res|
if res.is_public
if(res.container.nil? ||
(res.container.class.to_s=="Project" && res.container.is_public == false) ||
(res.container.has_attribute?(:project) && res.container.project && res.container.project.is_public == false) ||
(res.container.class.to_s=="HomeworkAttach" && res.container.bid.reward_type == 3) ||
(res.container.class.to_s=="Course" && res.container.is_public == false) ||
(res.container.has_attribute?(:course) && res.container.course && res.container.course.is_public == false)
)
res.is_public = false
res.save
end
end
end
end
def down
end
end