Project

General

Profile

Defect #31116 » redmine-4.0.2.plugin-upgrade.patch

Martijn Vernooij, 2019-04-17 17:47

View differences:

/usr/share/redmine/redmine-4.0.2/lib/redmine/plugin.rb 2019-04-17 17:35:44.815629390 +0200
515 515
      def open
516 516
        Migrator.new(:up, migrations, nil)
517 517
      end
518

  
519
      def set_current_plugin(p)
520
	      @current_plugin = p
521
      end
522

  
523

  
524
      def get_all_versions(plugin = @current_plugin)
525
        # Delete migrations that don't match .. to_i will work because the number comes first
526
        @all_versions ||= {}
527
        @all_versions[plugin.id.to_s] ||= begin
528
          sm_table = ::ActiveRecord::SchemaMigration.table_name
529
          migration_versions  = ActiveRecord::Base.connection.select_values("SELECT version FROM #{sm_table}")
530
          versions_by_plugins = migration_versions.group_by { |version| version.match(/-(.*)$/).try(:[], 1) }
531
          @all_versions       = versions_by_plugins.transform_values! {|versions| versions.map!(&:to_i).sort! }
532
          @all_versions[plugin.id.to_s] || []
533
        end
534
      end
518 535
    end
519 536

  
520 537
    class Migrator < ActiveRecord::Migrator
......
527 544
          self.current_plugin = plugin
528 545
          return if current_version(plugin) == version
529 546

  
530
          MigrationContext.new(plugin.migration_directory).migrate(version)
547
          ctx = MigrationContext.new(plugin.migration_directory)
548
          ctx.set_current_plugin(plugin)
549
          ctx.migrate(version)
531 550
        end
532 551

  
533 552
        def get_all_versions(plugin = current_plugin)
(2-2/3)