From c972968338b5c9ba0dca4b3749d4a5c9c79b4731 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Fri, 17 Feb 2012 15:22:55 +0600 Subject: [PATCH] [refs #134] some hook task improvements --- lib/tasks/hook.rake | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/tasks/hook.rake b/lib/tasks/hook.rake index 67c5e8140..d41bbafdb 100644 --- a/lib/tasks/hook.rake +++ b/lib/tasks/hook.rake @@ -14,7 +14,8 @@ namespace :hook do say "Install process.." count = 0 - Project.all.each do |project| + projects = ENV['project_id'] ? Project.where(:id => eval(ENV['project_id'])) : Project + projects.where('created_at >= ?', Time.now.ago(ENV['period'] ? eval(ENV['period']) : 100.years)).each do |project| hook_file = File.join(project.path, 'hooks', 'post-receive') FileUtils.cp(hook, hook_file) count = count + 1 @@ -28,7 +29,11 @@ namespace :hook do task :remove => :environment do say "process.." count = 0 - Project.all.each { |project| FileUtils.rm_rf File.join(project.path, 'hooks', 'post-receive'); count = count + 1} + projects = ENV['project_id'] ? Project.where(:id => eval(ENV['project_id'])) : Project + projects.where('created_at >= ?', Time.now.ago(ENV['period'] ? eval(ENV['period']) : 100.years)).each do |project| + FileUtils.rm_rf File.join(project.path, 'hooks', 'post-receive') + count = count + 1 + end say "Done! Removing from #{count.to_s} repo(s)" end end