From 64d305f2a85c1647bf4d2bb80069600df5d60432 Mon Sep 17 00:00:00 2001 From: James Herdman Date: Sat, 29 Aug 2009 14:20:08 -0400 Subject: [PATCH] Don't make ANY assumptions about the environment. Use the model and Rails to do as much work as possible. --- lib/tasks/upgrade_instiki.rake | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/tasks/upgrade_instiki.rake b/lib/tasks/upgrade_instiki.rake index be075a5e..b629ffb5 100644 --- a/lib/tasks/upgrade_instiki.rake +++ b/lib/tasks/upgrade_instiki.rake @@ -1,15 +1,14 @@ -require 'active_record' - task :upgrade_instiki => :environment do - ActiveRecord::Base.establish_connection(:production) - webs = ActiveRecord::Base.connection.execute( "select * from webs" ) - webs.each do |row| - if File.exists?('public/' + row[4]) - if File.exists?('webs/' + row[4]) - print "Warning! The directory webs/#{row[4]} already exists. Skipping.\n" + Web.all.each do |web| + public_path = Rails.root.join("public", web.address) + + if public_path.exist? + webs_path = Rails.root.join("webs", web.address) + if webs_path.exist? + puts "Warning! The directory #{webs_path} already exists. Skipping." else - File.rename('public/' + row[4], 'webs/' + row[4]) - print "Moved: #{row[4]}\n" + public_path.rename(webs_path) + puts "Moved #{public_path} to #{webs_path}" end end end