Commit becdcf37421d9c9cd24e4c87ec4b2027867c722d

Authored by Rodrigo Souto
1 parent 5aa5b5ef

Avoiding plugins to be loaded during rake

  Letting the plugins enabled during the rake was breaking some tasks
  like db:schema:load becouse some models were eventually loaded without
  the tables being created yet.
Showing 2 changed files with 39 additions and 0 deletions   Show diff stats
lib/tasks/env.rake
  1 +enabled_plugins = Dir.glob(File.join(Rails.root, 'config', 'plugins', '*')).map {|path| File.basename(path)}.reject {|a| a == "README"}
  2 +sh './script/noosfero-plugins disableall'
1 3 require File.join(File.dirname(__FILE__), '../../config/environment.rb')
  4 +enabled_plugins.each do |plugin|
  5 + sh "./script/noosfero-plugins enable #{plugin}"
  6 +end
... ...
lib/tasks/plugins.rake
... ... @@ -8,6 +8,39 @@ namespace :noosfero do
8 8 ActiveRecord::Migrator.migrate(path, ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
9 9 end
10 10 end
  11 +
  12 + task :save_enabled do
  13 + ENV['ENABLED_PLUGINS'] = Dir.glob(File.join(Rails.root, 'config', 'plugins', '*')).map {|path| File.basename(path)}.reject {|a| a == "README"}.join(',')
  14 + end
  15 +
  16 + task :temporary_config, :action, :needs => [:save_enabled] do |t, args|
  17 + sh "./script/noosfero-plugins #{args.action}all"
  18 + end
  19 +
  20 + task :restore_config do
  21 + sh "./script/noosfero-plugins disableall"
  22 + enabled_plugins = ENV['ENABLED_PLUGINS'].split(',')
  23 + enabled_plugins.each do |plugin|
  24 + sh "./script/noosfero-plugins enable #{plugin}"
  25 + end
  26 + end
  27 +
  28 + task :prepare_environment_disable do
  29 + Rake::Task['noosfero:plugins:temporary_config'].invoke('disable')
  30 +
  31 + Rake::Task['environment'].enhance do
  32 + Rake::Task['noosfero:plugins:restore_config'].invoke
  33 + end
  34 + end
  35 +
  36 + task :prepare_environment_enable do
  37 + Rake::Task['noosfero:plugins:temporary_config'].invoke('enable')
  38 +
  39 + Rake::Task['environment'].enhance do
  40 + Rake::Task['noosfero:plugins:restore_config'].invoke
  41 + end
  42 + end
  43 +
11 44 task :abort_if_pending_migrations do
12 45 if defined? ActiveRecord
13 46 plugin_migration_dirs.each do |path|
... ... @@ -28,3 +61,4 @@ end
28 61  
29 62 task 'db:migrate' => 'noosfero:plugins:migrate'
30 63 task 'db:abort_if_pending_migrations' => 'noosfero:plugins:abort_if_pending_migrations'
  64 +task 'environment' => 'noosfero:plugins:prepare_environment_disable'
... ...