annotate .svn/pristine/98/98a2bf9c72fba53da4bdf6ea4fa801aa4b2e0633.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

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