##// END OF EJS Templates
Adds deprecated tasks for plugins migration....
Jean-Philippe Lang -
r9414:45093230a9c6
parent child
Show More
@@ -370,24 +370,41 module Redmine #:nodoc:
370 def migration_directory
370 def migration_directory
371 File.join(Rails.root, 'plugins', id.to_s, 'db', 'migrate')
371 File.join(Rails.root, 'plugins', id.to_s, 'db', 'migrate')
372 end
372 end
373
373
374 # Returns the version number of the latest migration for this plugin. Returns
374 # Returns the version number of the latest migration for this plugin. Returns
375 # nil if this plugin has no migrations.
375 # nil if this plugin has no migrations.
376 def latest_migration
376 def latest_migration
377 migrations.last
377 migrations.last
378 end
378 end
379
379
380 # Returns the version numbers of all migrations for this plugin.
380 # Returns the version numbers of all migrations for this plugin.
381 def migrations
381 def migrations
382 migrations = Dir[migration_directory+"/*.rb"]
382 migrations = Dir[migration_directory+"/*.rb"]
383 migrations.map { |p| File.basename(p).match(/0*(\d+)\_/)[1].to_i }.sort
383 migrations.map { |p| File.basename(p).match(/0*(\d+)\_/)[1].to_i }.sort
384 end
384 end
385
385
386 # Migrate this plugin to the given version
386 # Migrate this plugin to the given version
387 def migrate(version = nil)
387 def migrate(version = nil)
388 puts "Migrating #{id} (#{name})..."
388 Redmine::Plugin::Migrator.migrate_plugin(self, version)
389 Redmine::Plugin::Migrator.migrate_plugin(self, version)
389 end
390 end
390
391
392 # Migrates all plugins or a single plugin to a given version
393 # Exemples:
394 # Plugin.migrate
395 # Plugin.migrate('sample_plugin')
396 # Plugin.migrate('sample_plugin', 1)
397 #
398 def self.migrate(name=nil, version=nil)
399 if name.present?
400 find(name).migrate(version)
401 else
402 all.each do |plugin|
403 plugin.migrate
404 end
405 end
406 end
407
391 class Migrator < ActiveRecord::Migrator
408 class Migrator < ActiveRecord::Migrator
392 # We need to be able to set the 'current' plugin being migrated.
409 # We need to be able to set the 'current' plugin being migrated.
393 cattr_accessor :current_plugin
410 cattr_accessor :current_plugin
@@ -8,3 +8,4 deprecated_task :load_default_data, "redmine:load_default_data"
8 deprecated_task :migrate_from_mantis, "redmine:migrate_from_mantis"
8 deprecated_task :migrate_from_mantis, "redmine:migrate_from_mantis"
9 deprecated_task :migrate_from_trac, "redmine:migrate_from_trac"
9 deprecated_task :migrate_from_trac, "redmine:migrate_from_trac"
10 deprecated_task "db:migrate_plugins", "redmine:plugins:migrate"
10 deprecated_task "db:migrate_plugins", "redmine:plugins:migrate"
11 deprecated_task "db:migrate:plugin", "redmine:plugins:migrate"
@@ -51,9 +51,24 namespace :redmine do
51 namespace :plugins do
51 namespace :plugins do
52 desc 'Migrates installed plugins.'
52 desc 'Migrates installed plugins.'
53 task :migrate => :environment do
53 task :migrate => :environment do
54 Redmine::Plugin.all.each do |plugin|
54 name = ENV['name']
55 puts "Migrating #{plugin.name}..."
55 version = nil
56 plugin.migrate
56 version_string = ENV['version']
57 if version_string
58 if version_string =~ /^\d+$/
59 version = version_string.to_i
60 if name.nil?
61 abort "The VERSION argument requires a plugin NAME."
62 end
63 else
64 abort "Invalid version #{version_string} given."
65 end
66 end
67
68 begin
69 Redmine::Plugin.migrate(name, version)
70 rescue Redmine::PluginNotFound
71 abort "Plugin #{name} was not found."
57 end
72 end
58 end
73 end
59
74
General Comments 0
You need to be logged in to leave comments. Login now