Project

General

Profile

Patch #14971 » redmine_plugin_rollback_RMV2.3.2.diff

Jérôme BATAILLE, 2013-09-23 12:50

View differences:

lib/tasks/redmine.rake (copie de travail)
79 79
      Rake::Task["db:schema:dump"].invoke
80 80
    end
81 81

  
82
    desc 'Rollbacks installed plugins by 1 or many steps.'
83
    task :rollback => :environment do
84
      name = ENV['NAME']
85
      steps = nil
86
      steps_string = ENV['STEP']
87

  
88
      if name.nil?
89
        abort "The VERSION argument requires a plugin NAME."
90
      end
91

  
92
      begin
93
        steps = Integer(steps_string)
94
      rescue
95
        abort "Invalid STEP #{steps_string} given."
96
      end
97

  
98
      begin
99
        Redmine::Plugin.rollback(name, steps)
100
      rescue Redmine::PluginNotFound
101
        abort "Plugin #{name} was not found."
102
      end
103

  
104
      Rake::Task["db:schema:dump"].invoke
105
    end
106

  
82 107
    desc 'Copies plugins assets into the public directory.'
83 108
    task :assets => :environment do
84 109
      name = ENV['NAME']
lib/redmine/plugin.rb (copie de travail)
425 425
      Redmine::Plugin::Migrator.migrate_plugin(self, version)
426 426
    end
427 427

  
428
    # Rollback this plugin to the previous version
429
    def rollback(steps=1)
430
      puts "Rollback #{steps} migration#{ '(s)' if steps > 1 } before (#{name})..."
431
      Redmine::Plugin::Migrator.rollback_plugin(self, steps)
432
    end
433

  
428 434
    # Migrates all plugins or a single plugin to a given version
429 435
    # Exemples:
430 436
    #   Plugin.migrate
......
441 447
      end
442 448
    end
443 449

  
450
    # Rollbacks a single plugin by one or more step
451
    # Exemples:
452
    #   Plugin.rollback('sample_plugin')
453
    #   Plugin.rollback('sample_plugin', 2)
454
    #
455
    def self.rollback(name=nil, steps=nil)
456
      if name.present?
457
        find(name).rollback(steps)
458
      end
459
    end
460

  
444 461
    class Migrator < ActiveRecord::Migrator
445 462
      # We need to be able to set the 'current' plugin being migrated.
446 463
      cattr_accessor :current_plugin
......
452 469
          return if current_version(plugin) == version
453 470
          migrate(plugin.migration_directory, version)
454 471
        end
455
        
472

  
473
        def rollback_plugin(plugin, steps=1)
474
          self.current_plugin = plugin
475
          rollback(plugin.migration_directory, steps)
476
        end
477

  
456 478
        def current_version(plugin=current_plugin)
457 479
          # Delete migrations that don't match .. to_i will work because the number comes first
458 480
          ::ActiveRecord::Base.connection.select_values(
    (1-1/1)