diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-05-01 09:02:34 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-05-01 09:02:34 +0000 |
commit | 45093230a9c6328751a5604983239f6684e7bec7 (patch) | |
tree | 8e8a40bcff14beaad0b8cdbcac83c5260e874c47 /lib/redmine/plugin.rb | |
parent | f4b9d2a7ee48945ff948b69c4d7481139b076209 (diff) | |
download | redmine-45093230a9c6328751a5604983239f6684e7bec7.tar.gz redmine-45093230a9c6328751a5604983239f6684e7bec7.zip |
Adds deprecated tasks for plugins migration.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9597 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/redmine/plugin.rb')
-rw-r--r-- | lib/redmine/plugin.rb | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/lib/redmine/plugin.rb b/lib/redmine/plugin.rb index 090deb535..24f921f53 100644 --- a/lib/redmine/plugin.rb +++ b/lib/redmine/plugin.rb @@ -370,24 +370,41 @@ module Redmine #:nodoc: def migration_directory File.join(Rails.root, 'plugins', id.to_s, 'db', 'migrate') end - + # Returns the version number of the latest migration for this plugin. Returns # nil if this plugin has no migrations. def latest_migration migrations.last end - + # Returns the version numbers of all migrations for this plugin. def migrations migrations = Dir[migration_directory+"/*.rb"] migrations.map { |p| File.basename(p).match(/0*(\d+)\_/)[1].to_i }.sort end - + # Migrate this plugin to the given version def migrate(version = nil) + puts "Migrating #{id} (#{name})..." Redmine::Plugin::Migrator.migrate_plugin(self, version) 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 # We need to be able to set the 'current' plugin being migrated. cattr_accessor :current_plugin |