annotate .svn/pristine/07/071c1af1d5f365dd709aaf606fafd0332e258d64.svn-base @ 1295:622f24f53b42 redmine-2.3

Update to Redmine SVN revision 11972 on 2.3-stable branch
author Chris Cannam
date Fri, 14 Jun 2013 09:02:21 +0100
parents
children
rev   line source
Chris@1295 1 # Redmine - project management software
Chris@1295 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
Chris@1295 3 #
Chris@1295 4 # This program is free software; you can redistribute it and/or
Chris@1295 5 # modify it under the terms of the GNU General Public License
Chris@1295 6 # as published by the Free Software Foundation; either version 2
Chris@1295 7 # of the License, or (at your option) any later version.
Chris@1295 8 #
Chris@1295 9 # This program is distributed in the hope that it will be useful,
Chris@1295 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1295 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1295 12 # GNU General Public License for more details.
Chris@1295 13 #
Chris@1295 14 # You should have received a copy of the GNU General Public License
Chris@1295 15 # along with this program; if not, write to the Free Software
Chris@1295 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1295 17
Chris@1295 18 module Redmine #:nodoc:
Chris@1295 19
Chris@1295 20 class PluginNotFound < StandardError; end
Chris@1295 21 class PluginRequirementError < StandardError; end
Chris@1295 22
Chris@1295 23 # Base class for Redmine plugins.
Chris@1295 24 # Plugins are registered using the <tt>register</tt> class method that acts as the public constructor.
Chris@1295 25 #
Chris@1295 26 # Redmine::Plugin.register :example do
Chris@1295 27 # name 'Example plugin'
Chris@1295 28 # author 'John Smith'
Chris@1295 29 # description 'This is an example plugin for Redmine'
Chris@1295 30 # version '0.0.1'
Chris@1295 31 # settings :default => {'foo'=>'bar'}, :partial => 'settings/settings'
Chris@1295 32 # end
Chris@1295 33 #
Chris@1295 34 # === Plugin attributes
Chris@1295 35 #
Chris@1295 36 # +settings+ is an optional attribute that let the plugin be configurable.
Chris@1295 37 # It must be a hash with the following keys:
Chris@1295 38 # * <tt>:default</tt>: default value for the plugin settings
Chris@1295 39 # * <tt>:partial</tt>: path of the configuration partial view, relative to the plugin <tt>app/views</tt> directory
Chris@1295 40 # Example:
Chris@1295 41 # settings :default => {'foo'=>'bar'}, :partial => 'settings/settings'
Chris@1295 42 # In this example, the settings partial will be found here in the plugin directory: <tt>app/views/settings/_settings.rhtml</tt>.
Chris@1295 43 #
Chris@1295 44 # When rendered, the plugin settings value is available as the local variable +settings+
Chris@1295 45 class Plugin
Chris@1295 46 cattr_accessor :directory
Chris@1295 47 self.directory = File.join(Rails.root, 'plugins')
Chris@1295 48
Chris@1295 49 cattr_accessor :public_directory
Chris@1295 50 self.public_directory = File.join(Rails.root, 'public', 'plugin_assets')
Chris@1295 51
Chris@1295 52 @registered_plugins = {}
Chris@1295 53 class << self
Chris@1295 54 attr_reader :registered_plugins
Chris@1295 55 private :new
Chris@1295 56
Chris@1295 57 def def_field(*names)
Chris@1295 58 class_eval do
Chris@1295 59 names.each do |name|
Chris@1295 60 define_method(name) do |*args|
Chris@1295 61 args.empty? ? instance_variable_get("@#{name}") : instance_variable_set("@#{name}", *args)
Chris@1295 62 end
Chris@1295 63 end
Chris@1295 64 end
Chris@1295 65 end
Chris@1295 66 end
Chris@1295 67 def_field :name, :description, :url, :author, :author_url, :version, :settings
Chris@1295 68 attr_reader :id
Chris@1295 69
Chris@1295 70 # Plugin constructor
Chris@1295 71 def self.register(id, &block)
Chris@1295 72 p = new(id)
Chris@1295 73 p.instance_eval(&block)
Chris@1295 74 # Set a default name if it was not provided during registration
Chris@1295 75 p.name(id.to_s.humanize) if p.name.nil?
Chris@1295 76
Chris@1295 77 # Adds plugin locales if any
Chris@1295 78 # YAML translation files should be found under <plugin>/config/locales/
Chris@1295 79 ::I18n.load_path += Dir.glob(File.join(p.directory, 'config', 'locales', '*.yml'))
Chris@1295 80
Chris@1295 81 # Prepends the app/views directory of the plugin to the view path
Chris@1295 82 view_path = File.join(p.directory, 'app', 'views')
Chris@1295 83 if File.directory?(view_path)
Chris@1295 84 ActionController::Base.prepend_view_path(view_path)
Chris@1295 85 ActionMailer::Base.prepend_view_path(view_path)
Chris@1295 86 end
Chris@1295 87
Chris@1295 88 # Adds the app/{controllers,helpers,models} directories of the plugin to the autoload path
Chris@1295 89 Dir.glob File.expand_path(File.join(p.directory, 'app', '{controllers,helpers,models}')) do |dir|
Chris@1295 90 ActiveSupport::Dependencies.autoload_paths += [dir]
Chris@1295 91 end
Chris@1295 92
Chris@1295 93 registered_plugins[id] = p
Chris@1295 94 end
Chris@1295 95
Chris@1295 96 # Returns an array of all registered plugins
Chris@1295 97 def self.all
Chris@1295 98 registered_plugins.values.sort
Chris@1295 99 end
Chris@1295 100
Chris@1295 101 # Finds a plugin by its id
Chris@1295 102 # Returns a PluginNotFound exception if the plugin doesn't exist
Chris@1295 103 def self.find(id)
Chris@1295 104 registered_plugins[id.to_sym] || raise(PluginNotFound)
Chris@1295 105 end
Chris@1295 106
Chris@1295 107 # Clears the registered plugins hash
Chris@1295 108 # It doesn't unload installed plugins
Chris@1295 109 def self.clear
Chris@1295 110 @registered_plugins = {}
Chris@1295 111 end
Chris@1295 112
Chris@1295 113 # Checks if a plugin is installed
Chris@1295 114 #
Chris@1295 115 # @param [String] id name of the plugin
Chris@1295 116 def self.installed?(id)
Chris@1295 117 registered_plugins[id.to_sym].present?
Chris@1295 118 end
Chris@1295 119
Chris@1295 120 def self.load
Chris@1295 121 Dir.glob(File.join(self.directory, '*')).sort.each do |directory|
Chris@1295 122 if File.directory?(directory)
Chris@1295 123 lib = File.join(directory, "lib")
Chris@1295 124 if File.directory?(lib)
Chris@1295 125 $:.unshift lib
Chris@1295 126 ActiveSupport::Dependencies.autoload_paths += [lib]
Chris@1295 127 end
Chris@1295 128 initializer = File.join(directory, "init.rb")
Chris@1295 129 if File.file?(initializer)
Chris@1295 130 require initializer
Chris@1295 131 end
Chris@1295 132 end
Chris@1295 133 end
Chris@1295 134 end
Chris@1295 135
Chris@1295 136 def initialize(id)
Chris@1295 137 @id = id.to_sym
Chris@1295 138 end
Chris@1295 139
Chris@1295 140 def directory
Chris@1295 141 File.join(self.class.directory, id.to_s)
Chris@1295 142 end
Chris@1295 143
Chris@1295 144 def public_directory
Chris@1295 145 File.join(self.class.public_directory, id.to_s)
Chris@1295 146 end
Chris@1295 147
Chris@1295 148 def to_param
Chris@1295 149 id
Chris@1295 150 end
Chris@1295 151
Chris@1295 152 def assets_directory
Chris@1295 153 File.join(directory, 'assets')
Chris@1295 154 end
Chris@1295 155
Chris@1295 156 def <=>(plugin)
Chris@1295 157 self.id.to_s <=> plugin.id.to_s
Chris@1295 158 end
Chris@1295 159
Chris@1295 160 # Sets a requirement on Redmine version
Chris@1295 161 # Raises a PluginRequirementError exception if the requirement is not met
Chris@1295 162 #
Chris@1295 163 # Examples
Chris@1295 164 # # Requires Redmine 0.7.3 or higher
Chris@1295 165 # requires_redmine :version_or_higher => '0.7.3'
Chris@1295 166 # requires_redmine '0.7.3'
Chris@1295 167 #
Chris@1295 168 # # Requires Redmine 0.7.x or higher
Chris@1295 169 # requires_redmine '0.7'
Chris@1295 170 #
Chris@1295 171 # # Requires a specific Redmine version
Chris@1295 172 # requires_redmine :version => '0.7.3' # 0.7.3 only
Chris@1295 173 # requires_redmine :version => '0.7' # 0.7.x
Chris@1295 174 # requires_redmine :version => ['0.7.3', '0.8.0'] # 0.7.3 or 0.8.0
Chris@1295 175 #
Chris@1295 176 # # Requires a Redmine version within a range
Chris@1295 177 # requires_redmine :version => '0.7.3'..'0.9.1' # >= 0.7.3 and <= 0.9.1
Chris@1295 178 # requires_redmine :version => '0.7'..'0.9' # >= 0.7.x and <= 0.9.x
Chris@1295 179 def requires_redmine(arg)
Chris@1295 180 arg = { :version_or_higher => arg } unless arg.is_a?(Hash)
Chris@1295 181 arg.assert_valid_keys(:version, :version_or_higher)
Chris@1295 182
Chris@1295 183 current = Redmine::VERSION.to_a
Chris@1295 184 arg.each do |k, req|
Chris@1295 185 case k
Chris@1295 186 when :version_or_higher
Chris@1295 187 raise ArgumentError.new(":version_or_higher accepts a version string only") unless req.is_a?(String)
Chris@1295 188 unless compare_versions(req, current) <= 0
Chris@1295 189 raise PluginRequirementError.new("#{id} plugin requires Redmine #{req} or higher but current is #{current.join('.')}")
Chris@1295 190 end
Chris@1295 191 when :version
Chris@1295 192 req = [req] if req.is_a?(String)
Chris@1295 193 if req.is_a?(Array)
Chris@1295 194 unless req.detect {|ver| compare_versions(ver, current) == 0}
Chris@1295 195 raise PluginRequirementError.new("#{id} plugin requires one the following Redmine versions: #{req.join(', ')} but current is #{current.join('.')}")
Chris@1295 196 end
Chris@1295 197 elsif req.is_a?(Range)
Chris@1295 198 unless compare_versions(req.first, current) <= 0 && compare_versions(req.last, current) >= 0
Chris@1295 199 raise PluginRequirementError.new("#{id} plugin requires a Redmine version between #{req.first} and #{req.last} but current is #{current.join('.')}")
Chris@1295 200 end
Chris@1295 201 else
Chris@1295 202 raise ArgumentError.new(":version option accepts a version string, an array or a range of versions")
Chris@1295 203 end
Chris@1295 204 end
Chris@1295 205 end
Chris@1295 206 true
Chris@1295 207 end
Chris@1295 208
Chris@1295 209 def compare_versions(requirement, current)
Chris@1295 210 requirement = requirement.split('.').collect(&:to_i)
Chris@1295 211 requirement <=> current.slice(0, requirement.size)
Chris@1295 212 end
Chris@1295 213 private :compare_versions
Chris@1295 214
Chris@1295 215 # Sets a requirement on a Redmine plugin version
Chris@1295 216 # Raises a PluginRequirementError exception if the requirement is not met
Chris@1295 217 #
Chris@1295 218 # Examples
Chris@1295 219 # # Requires a plugin named :foo version 0.7.3 or higher
Chris@1295 220 # requires_redmine_plugin :foo, :version_or_higher => '0.7.3'
Chris@1295 221 # requires_redmine_plugin :foo, '0.7.3'
Chris@1295 222 #
Chris@1295 223 # # Requires a specific version of a Redmine plugin
Chris@1295 224 # requires_redmine_plugin :foo, :version => '0.7.3' # 0.7.3 only
Chris@1295 225 # requires_redmine_plugin :foo, :version => ['0.7.3', '0.8.0'] # 0.7.3 or 0.8.0
Chris@1295 226 def requires_redmine_plugin(plugin_name, arg)
Chris@1295 227 arg = { :version_or_higher => arg } unless arg.is_a?(Hash)
Chris@1295 228 arg.assert_valid_keys(:version, :version_or_higher)
Chris@1295 229
Chris@1295 230 plugin = Plugin.find(plugin_name)
Chris@1295 231 current = plugin.version.split('.').collect(&:to_i)
Chris@1295 232
Chris@1295 233 arg.each do |k, v|
Chris@1295 234 v = [] << v unless v.is_a?(Array)
Chris@1295 235 versions = v.collect {|s| s.split('.').collect(&:to_i)}
Chris@1295 236 case k
Chris@1295 237 when :version_or_higher
Chris@1295 238 raise ArgumentError.new("wrong number of versions (#{versions.size} for 1)") unless versions.size == 1
Chris@1295 239 unless (current <=> versions.first) >= 0
Chris@1295 240 raise PluginRequirementError.new("#{id} plugin requires the #{plugin_name} plugin #{v} or higher but current is #{current.join('.')}")
Chris@1295 241 end
Chris@1295 242 when :version
Chris@1295 243 unless versions.include?(current.slice(0,3))
Chris@1295 244 raise PluginRequirementError.new("#{id} plugin requires one the following versions of #{plugin_name}: #{v.join(', ')} but current is #{current.join('.')}")
Chris@1295 245 end
Chris@1295 246 end
Chris@1295 247 end
Chris@1295 248 true
Chris@1295 249 end
Chris@1295 250
Chris@1295 251 # Adds an item to the given +menu+.
Chris@1295 252 # The +id+ parameter (equals to the project id) is automatically added to the url.
Chris@1295 253 # menu :project_menu, :plugin_example, { :controller => 'example', :action => 'say_hello' }, :caption => 'Sample'
Chris@1295 254 #
Chris@1295 255 # +name+ parameter can be: :top_menu, :account_menu, :application_menu or :project_menu
Chris@1295 256 #
Chris@1295 257 def menu(menu, item, url, options={})
Chris@1295 258 Redmine::MenuManager.map(menu).push(item, url, options)
Chris@1295 259 end
Chris@1295 260 alias :add_menu_item :menu
Chris@1295 261
Chris@1295 262 # Removes +item+ from the given +menu+.
Chris@1295 263 def delete_menu_item(menu, item)
Chris@1295 264 Redmine::MenuManager.map(menu).delete(item)
Chris@1295 265 end
Chris@1295 266
Chris@1295 267 # Defines a permission called +name+ for the given +actions+.
Chris@1295 268 #
Chris@1295 269 # The +actions+ argument is a hash with controllers as keys and actions as values (a single value or an array):
Chris@1295 270 # permission :destroy_contacts, { :contacts => :destroy }
Chris@1295 271 # permission :view_contacts, { :contacts => [:index, :show] }
Chris@1295 272 #
Chris@1295 273 # The +options+ argument is a hash that accept the following keys:
Chris@1295 274 # * :public => the permission is public if set to true (implicitly given to any user)
Chris@1295 275 # * :require => can be set to one of the following values to restrict users the permission can be given to: :loggedin, :member
Chris@1295 276 # * :read => set it to true so that the permission is still granted on closed projects
Chris@1295 277 #
Chris@1295 278 # Examples
Chris@1295 279 # # A permission that is implicitly given to any user
Chris@1295 280 # # This permission won't appear on the Roles & Permissions setup screen
Chris@1295 281 # permission :say_hello, { :example => :say_hello }, :public => true, :read => true
Chris@1295 282 #
Chris@1295 283 # # A permission that can be given to any user
Chris@1295 284 # permission :say_hello, { :example => :say_hello }
Chris@1295 285 #
Chris@1295 286 # # A permission that can be given to registered users only
Chris@1295 287 # permission :say_hello, { :example => :say_hello }, :require => :loggedin
Chris@1295 288 #
Chris@1295 289 # # A permission that can be given to project members only
Chris@1295 290 # permission :say_hello, { :example => :say_hello }, :require => :member
Chris@1295 291 def permission(name, actions, options = {})
Chris@1295 292 if @project_module
Chris@1295 293 Redmine::AccessControl.map {|map| map.project_module(@project_module) {|map|map.permission(name, actions, options)}}
Chris@1295 294 else
Chris@1295 295 Redmine::AccessControl.map {|map| map.permission(name, actions, options)}
Chris@1295 296 end
Chris@1295 297 end
Chris@1295 298
Chris@1295 299 # Defines a project module, that can be enabled/disabled for each project.
Chris@1295 300 # Permissions defined inside +block+ will be bind to the module.
Chris@1295 301 #
Chris@1295 302 # project_module :things do
Chris@1295 303 # permission :view_contacts, { :contacts => [:list, :show] }, :public => true
Chris@1295 304 # permission :destroy_contacts, { :contacts => :destroy }
Chris@1295 305 # end
Chris@1295 306 def project_module(name, &block)
Chris@1295 307 @project_module = name
Chris@1295 308 self.instance_eval(&block)
Chris@1295 309 @project_module = nil
Chris@1295 310 end
Chris@1295 311
Chris@1295 312 # Registers an activity provider.
Chris@1295 313 #
Chris@1295 314 # Options:
Chris@1295 315 # * <tt>:class_name</tt> - one or more model(s) that provide these events (inferred from event_type by default)
Chris@1295 316 # * <tt>:default</tt> - setting this option to false will make the events not displayed by default
Chris@1295 317 #
Chris@1295 318 # A model can provide several activity event types.
Chris@1295 319 #
Chris@1295 320 # Examples:
Chris@1295 321 # register :news
Chris@1295 322 # register :scrums, :class_name => 'Meeting'
Chris@1295 323 # register :issues, :class_name => ['Issue', 'Journal']
Chris@1295 324 #
Chris@1295 325 # Retrieving events:
Chris@1295 326 # Associated model(s) must implement the find_events class method.
Chris@1295 327 # ActiveRecord models can use acts_as_activity_provider as a way to implement this class method.
Chris@1295 328 #
Chris@1295 329 # The following call should return all the scrum events visible by current user that occured in the 5 last days:
Chris@1295 330 # Meeting.find_events('scrums', User.current, 5.days.ago, Date.today)
Chris@1295 331 # Meeting.find_events('scrums', User.current, 5.days.ago, Date.today, :project => foo) # events for project foo only
Chris@1295 332 #
Chris@1295 333 # Note that :view_scrums permission is required to view these events in the activity view.
Chris@1295 334 def activity_provider(*args)
Chris@1295 335 Redmine::Activity.register(*args)
Chris@1295 336 end
Chris@1295 337
Chris@1295 338 # Registers a wiki formatter.
Chris@1295 339 #
Chris@1295 340 # Parameters:
Chris@1295 341 # * +name+ - human-readable name
Chris@1295 342 # * +formatter+ - formatter class, which should have an instance method +to_html+
Chris@1295 343 # * +helper+ - helper module, which will be included by wiki pages
Chris@1295 344 def wiki_format_provider(name, formatter, helper)
Chris@1295 345 Redmine::WikiFormatting.register(name, formatter, helper)
Chris@1295 346 end
Chris@1295 347
Chris@1295 348 # Returns +true+ if the plugin can be configured.
Chris@1295 349 def configurable?
Chris@1295 350 settings && settings.is_a?(Hash) && !settings[:partial].blank?
Chris@1295 351 end
Chris@1295 352
Chris@1295 353 def mirror_assets
Chris@1295 354 source = assets_directory
Chris@1295 355 destination = public_directory
Chris@1295 356 return unless File.directory?(source)
Chris@1295 357
Chris@1295 358 source_files = Dir[source + "/**/*"]
Chris@1295 359 source_dirs = source_files.select { |d| File.directory?(d) }
Chris@1295 360 source_files -= source_dirs
Chris@1295 361
Chris@1295 362 unless source_files.empty?
Chris@1295 363 base_target_dir = File.join(destination, File.dirname(source_files.first).gsub(source, ''))
Chris@1295 364 begin
Chris@1295 365 FileUtils.mkdir_p(base_target_dir)
Chris@1295 366 rescue Exception => e
Chris@1295 367 raise "Could not create directory #{base_target_dir}: " + e.message
Chris@1295 368 end
Chris@1295 369 end
Chris@1295 370
Chris@1295 371 source_dirs.each do |dir|
Chris@1295 372 # strip down these paths so we have simple, relative paths we can
Chris@1295 373 # add to the destination
Chris@1295 374 target_dir = File.join(destination, dir.gsub(source, ''))
Chris@1295 375 begin
Chris@1295 376 FileUtils.mkdir_p(target_dir)
Chris@1295 377 rescue Exception => e
Chris@1295 378 raise "Could not create directory #{target_dir}: " + e.message
Chris@1295 379 end
Chris@1295 380 end
Chris@1295 381
Chris@1295 382 source_files.each do |file|
Chris@1295 383 begin
Chris@1295 384 target = File.join(destination, file.gsub(source, ''))
Chris@1295 385 unless File.exist?(target) && FileUtils.identical?(file, target)
Chris@1295 386 FileUtils.cp(file, target)
Chris@1295 387 end
Chris@1295 388 rescue Exception => e
Chris@1295 389 raise "Could not copy #{file} to #{target}: " + e.message
Chris@1295 390 end
Chris@1295 391 end
Chris@1295 392 end
Chris@1295 393
Chris@1295 394 # Mirrors assets from one or all plugins to public/plugin_assets
Chris@1295 395 def self.mirror_assets(name=nil)
Chris@1295 396 if name.present?
Chris@1295 397 find(name).mirror_assets
Chris@1295 398 else
Chris@1295 399 all.each do |plugin|
Chris@1295 400 plugin.mirror_assets
Chris@1295 401 end
Chris@1295 402 end
Chris@1295 403 end
Chris@1295 404
Chris@1295 405 # The directory containing this plugin's migrations (<tt>plugin/db/migrate</tt>)
Chris@1295 406 def migration_directory
Chris@1295 407 File.join(Rails.root, 'plugins', id.to_s, 'db', 'migrate')
Chris@1295 408 end
Chris@1295 409
Chris@1295 410 # Returns the version number of the latest migration for this plugin. Returns
Chris@1295 411 # nil if this plugin has no migrations.
Chris@1295 412 def latest_migration
Chris@1295 413 migrations.last
Chris@1295 414 end
Chris@1295 415
Chris@1295 416 # Returns the version numbers of all migrations for this plugin.
Chris@1295 417 def migrations
Chris@1295 418 migrations = Dir[migration_directory+"/*.rb"]
Chris@1295 419 migrations.map { |p| File.basename(p).match(/0*(\d+)\_/)[1].to_i }.sort
Chris@1295 420 end
Chris@1295 421
Chris@1295 422 # Migrate this plugin to the given version
Chris@1295 423 def migrate(version = nil)
Chris@1295 424 puts "Migrating #{id} (#{name})..."
Chris@1295 425 Redmine::Plugin::Migrator.migrate_plugin(self, version)
Chris@1295 426 end
Chris@1295 427
Chris@1295 428 # Migrates all plugins or a single plugin to a given version
Chris@1295 429 # Exemples:
Chris@1295 430 # Plugin.migrate
Chris@1295 431 # Plugin.migrate('sample_plugin')
Chris@1295 432 # Plugin.migrate('sample_plugin', 1)
Chris@1295 433 #
Chris@1295 434 def self.migrate(name=nil, version=nil)
Chris@1295 435 if name.present?
Chris@1295 436 find(name).migrate(version)
Chris@1295 437 else
Chris@1295 438 all.each do |plugin|
Chris@1295 439 plugin.migrate
Chris@1295 440 end
Chris@1295 441 end
Chris@1295 442 end
Chris@1295 443
Chris@1295 444 class Migrator < ActiveRecord::Migrator
Chris@1295 445 # We need to be able to set the 'current' plugin being migrated.
Chris@1295 446 cattr_accessor :current_plugin
Chris@1295 447
Chris@1295 448 class << self
Chris@1295 449 # Runs the migrations from a plugin, up (or down) to the version given
Chris@1295 450 def migrate_plugin(plugin, version)
Chris@1295 451 self.current_plugin = plugin
Chris@1295 452 return if current_version(plugin) == version
Chris@1295 453 migrate(plugin.migration_directory, version)
Chris@1295 454 end
Chris@1295 455
Chris@1295 456 def current_version(plugin=current_plugin)
Chris@1295 457 # Delete migrations that don't match .. to_i will work because the number comes first
Chris@1295 458 ::ActiveRecord::Base.connection.select_values(
Chris@1295 459 "SELECT version FROM #{schema_migrations_table_name}"
Chris@1295 460 ).delete_if{ |v| v.match(/-#{plugin.id}/) == nil }.map(&:to_i).max || 0
Chris@1295 461 end
Chris@1295 462 end
Chris@1295 463
Chris@1295 464 def migrated
Chris@1295 465 sm_table = self.class.schema_migrations_table_name
Chris@1295 466 ::ActiveRecord::Base.connection.select_values(
Chris@1295 467 "SELECT version FROM #{sm_table}"
Chris@1295 468 ).delete_if{ |v| v.match(/-#{current_plugin.id}/) == nil }.map(&:to_i).sort
Chris@1295 469 end
Chris@1295 470
Chris@1295 471 def record_version_state_after_migrating(version)
Chris@1295 472 super(version.to_s + "-" + current_plugin.id.to_s)
Chris@1295 473 end
Chris@1295 474 end
Chris@1295 475 end
Chris@1295 476 end