Don't make ANY assumptions about the environment. Use the model and

Rails to do as much work as possible.
This commit is contained in:
James Herdman 2009-08-29 14:20:08 -04:00
parent 23890d6ec0
commit 64d305f2a8

View file

@ -1,15 +1,14 @@
require 'active_record'
task :upgrade_instiki => :environment do task :upgrade_instiki => :environment do
ActiveRecord::Base.establish_connection(:production) Web.all.each do |web|
webs = ActiveRecord::Base.connection.execute( "select * from webs" ) public_path = Rails.root.join("public", web.address)
webs.each do |row|
if File.exists?('public/' + row[4]) if public_path.exist?
if File.exists?('webs/' + row[4]) webs_path = Rails.root.join("webs", web.address)
print "Warning! The directory webs/#{row[4]} already exists. Skipping.\n" if webs_path.exist?
puts "Warning! The directory #{webs_path} already exists. Skipping."
else else
File.rename('public/' + row[4], 'webs/' + row[4]) public_path.rename(webs_path)
print "Moved: #{row[4]}\n" puts "Moved #{public_path} to #{webs_path}"
end end
end end
end end