From 41aa81f9660ad5bc8c0e50ac1d5fa287166e9801 Mon Sep 17 00:00:00 2001 From: huang Date: Mon, 18 Apr 2016 14:44:29 +0800 Subject: [PATCH] =?UTF-8?q?rake=20=E4=BB=BB=E5=8A=A1=EF=BC=9A=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E6=96=87=E4=BB=B6=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/sync_files.rake | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 lib/tasks/sync_files.rake diff --git a/lib/tasks/sync_files.rake b/lib/tasks/sync_files.rake new file mode 100644 index 000000000..5c9326356 --- /dev/null +++ b/lib/tasks/sync_files.rake @@ -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