From 888e93a7fd1e4c6d1a0d1a34f52d8366cb3abcd2 Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Sat, 29 Aug 2009 23:31:39 -0500 Subject: [PATCH] Streamline Rake Task Refactor the upgrade_instiki rake task. Based on the (very nice) JHerdman's http://github.com/jherdman/instiki/commit/64d305f2a85c1647bf4d2bb80069600df5d60432 but defaults to 'production' environment, instead. Instiki users don't know about production/development/test. Instiki defaults to 'production'. So should its associated rake tasks. --- lib/chunks/engines.rb | 4 ++-- lib/tasks/upgrade_instiki.rake | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/chunks/engines.rb b/lib/chunks/engines.rb index d7324013..a19b0978 100644 --- a/lib/chunks/engines.rb +++ b/lib/chunks/engines.rb @@ -85,7 +85,7 @@ module Engines :html_math_output_mathml => false, :html_math_output_png => true, :html_png_engine => 'blahtex', - :html_png_dir => @content.web.files_path + '/pngs', + :html_png_dir => @content.web.files_path.join('pngs').to_s, :html_png_url => '../files/pngs/', :content_only => true, :author => @content.options[:engine_opts][:author], @@ -99,7 +99,7 @@ module Engines :html_math_output_mathml => false, :html_math_output_png => true, :html_png_engine => 'blahtex', - :html_png_dir => @content.web.files_path + '/pngs', + :html_png_dir => @content.web.files_path.join('pngs').to_s, :html_png_url => '../files/pngs/'}).to_html html.gsub(/\A
\n?(.*?)\n?<\/div>\Z/m, '\1') end diff --git a/lib/tasks/upgrade_instiki.rake b/lib/tasks/upgrade_instiki.rake index be075a5e..ef242c42 100644 --- a/lib/tasks/upgrade_instiki.rake +++ b/lib/tasks/upgrade_instiki.rake @@ -1,15 +1,16 @@ -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" + RAILS_ENV = 'production' unless ENV['RAILS_ENV'] + puts "Upgrading Instiki in #{RAILS_ENV} environment." + + 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