socialforge/lib/tasks/sync_files.rake

39 lines
1.4 KiB
Ruby
Raw Permalink Normal View History

2016-04-18 14:44:29 +08:00
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