Adds deprecated tasks for plugins migration.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9597 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
f4b9d2a7ee
commit
45093230a9
@ -370,24 +370,41 @@ module Redmine #:nodoc:
|
|||||||
def migration_directory
|
def migration_directory
|
||||||
File.join(Rails.root, 'plugins', id.to_s, 'db', 'migrate')
|
File.join(Rails.root, 'plugins', id.to_s, 'db', 'migrate')
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the version number of the latest migration for this plugin. Returns
|
# Returns the version number of the latest migration for this plugin. Returns
|
||||||
# nil if this plugin has no migrations.
|
# nil if this plugin has no migrations.
|
||||||
def latest_migration
|
def latest_migration
|
||||||
migrations.last
|
migrations.last
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the version numbers of all migrations for this plugin.
|
# Returns the version numbers of all migrations for this plugin.
|
||||||
def migrations
|
def migrations
|
||||||
migrations = Dir[migration_directory+"/*.rb"]
|
migrations = Dir[migration_directory+"/*.rb"]
|
||||||
migrations.map { |p| File.basename(p).match(/0*(\d+)\_/)[1].to_i }.sort
|
migrations.map { |p| File.basename(p).match(/0*(\d+)\_/)[1].to_i }.sort
|
||||||
end
|
end
|
||||||
|
|
||||||
# Migrate this plugin to the given version
|
# Migrate this plugin to the given version
|
||||||
def migrate(version = nil)
|
def migrate(version = nil)
|
||||||
|
puts "Migrating #{id} (#{name})..."
|
||||||
Redmine::Plugin::Migrator.migrate_plugin(self, version)
|
Redmine::Plugin::Migrator.migrate_plugin(self, version)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Migrates all plugins or a single plugin to a given version
|
||||||
|
# Exemples:
|
||||||
|
# Plugin.migrate
|
||||||
|
# Plugin.migrate('sample_plugin')
|
||||||
|
# Plugin.migrate('sample_plugin', 1)
|
||||||
|
#
|
||||||
|
def self.migrate(name=nil, version=nil)
|
||||||
|
if name.present?
|
||||||
|
find(name).migrate(version)
|
||||||
|
else
|
||||||
|
all.each do |plugin|
|
||||||
|
plugin.migrate
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class Migrator < ActiveRecord::Migrator
|
class Migrator < ActiveRecord::Migrator
|
||||||
# We need to be able to set the 'current' plugin being migrated.
|
# We need to be able to set the 'current' plugin being migrated.
|
||||||
cattr_accessor :current_plugin
|
cattr_accessor :current_plugin
|
||||||
|
@ -8,3 +8,4 @@ deprecated_task :load_default_data, "redmine:load_default_data"
|
|||||||
deprecated_task :migrate_from_mantis, "redmine:migrate_from_mantis"
|
deprecated_task :migrate_from_mantis, "redmine:migrate_from_mantis"
|
||||||
deprecated_task :migrate_from_trac, "redmine:migrate_from_trac"
|
deprecated_task :migrate_from_trac, "redmine:migrate_from_trac"
|
||||||
deprecated_task "db:migrate_plugins", "redmine:plugins:migrate"
|
deprecated_task "db:migrate_plugins", "redmine:plugins:migrate"
|
||||||
|
deprecated_task "db:migrate:plugin", "redmine:plugins:migrate"
|
||||||
|
@ -51,9 +51,24 @@ namespace :redmine do
|
|||||||
namespace :plugins do
|
namespace :plugins do
|
||||||
desc 'Migrates installed plugins.'
|
desc 'Migrates installed plugins.'
|
||||||
task :migrate => :environment do
|
task :migrate => :environment do
|
||||||
Redmine::Plugin.all.each do |plugin|
|
name = ENV['name']
|
||||||
puts "Migrating #{plugin.name}..."
|
version = nil
|
||||||
plugin.migrate
|
version_string = ENV['version']
|
||||||
|
if version_string
|
||||||
|
if version_string =~ /^\d+$/
|
||||||
|
version = version_string.to_i
|
||||||
|
if name.nil?
|
||||||
|
abort "The VERSION argument requires a plugin NAME."
|
||||||
|
end
|
||||||
|
else
|
||||||
|
abort "Invalid version #{version_string} given."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
|
Redmine::Plugin.migrate(name, version)
|
||||||
|
rescue Redmine::PluginNotFound
|
||||||
|
abort "Plugin #{name} was not found."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user