rake 任务:同步文件数

This commit is contained in:
huang 2016-04-18 14:44:29 +08:00
parent 5e5f677bab
commit 41aa81f966
1 changed files with 38 additions and 0 deletions

38
lib/tasks/sync_files.rake Normal file
View File

@ -0,0 +1,38 @@
require 'trustie/gitlab/sync'
namespace :trustie do
namespace :files do
desc "sync course'file"
task :course => :environment do
# Course.all.each do |course|
# unless course.attachments.count.to_i == 0
# attachment_count = Attachment.find_by_sql("SELECT * FROM `attachments` where container_id = #{course.id} and container_type ='Course'").count
# project_score = ProjectScore.where("project_id=?", project.id).first
# if project_score.nil?
# ProjectScore.create(:project_id => project.id, :attach_num => 0)
# else
# project_score.attach_num = attachment_count
# project_score.save
# end
# end
# end
end
desc "sync project'file"
task :project => :environment do
Project.all.each do |project|
unless project.attachments.count.to_i == 0
attachment_count = Attachment.find_by_sql("SELECT * FROM `attachments` where container_id = #{project.id} and container_type ='Project'").count
project_score = ProjectScore.where("project_id=?", project.id).first
if project_score.nil?
ProjectScore.create(:project_id => project.id, :attach_num => 0)
else
project_score.attach_num = attachment_count
project_score.save
end
end
end
end
end
end