Chris@16: class ApplySettingChanges < ActiveRecord::Migration Chris@16: class Repository < ActiveRecord::Base Chris@16: def self.inheritance_column Chris@16: # disable single table inheritance Chris@16: nil Chris@16: end Chris@16: Chris@16: def scm_name Chris@16: self.type || 'Abstract' Chris@16: end Chris@16: Chris@16: serialize :checkout_settings, Hash Chris@16: end Chris@16: Chris@16: def self.up Chris@16: default_commands = { Chris@16: 'Bazaar' => 'bzr checkout', Chris@16: 'Cvs' => 'cvs checkout', Chris@16: 'Darcs' => 'darcs get', Chris@16: 'Git' => 'git clone', Chris@16: 'Mercurial' => 'hg clone', Chris@16: 'Subversion' => 'svn checkout' Chris@16: } Chris@16: Chris@16: ## First migrate the individual repositories Chris@16: Chris@16: Repository.all.each do |r| Chris@16: allow_subtree_checkout = ['Cvs', 'Subversion'].include? r.scm_name Chris@16: Chris@16: protocol = case r.checkout_settings['checkout_url_type'] Chris@16: when 'none', 'generated' Chris@16: nil Chris@16: when 'original', 'overwritten' Chris@16: HashWithIndifferentAccess.new({ "0" => HashWithIndifferentAccess.new({ Chris@16: :protocol => r.scm_name, Chris@16: :command => Setting.plugin_redmine_checkout["checkout_cmd_#{r.scm_name}"] || default_commands[r.scm_name], Chris@16: :regex => "", Chris@16: :regex_replacement => "", Chris@16: :fixed_url => (r.checkout_settings['checkout_url_type'] == 'original' ? (r.url || "") : r.checkout_settings["checkout_url"]), Chris@16: :access => 'permission', Chris@16: :append_path => (allow_subtree_checkout ? '1' : '0'), Chris@16: :is_default => '1'}) Chris@16: }) Chris@16: end Chris@16: Chris@16: r.checkout_settings = Hash.new({ Chris@16: 'checkout_protocols' => protocol, Chris@16: 'checkout_description' => "The data contained in this repository can be downloaded to your computer using one of several clients. Chris@16: Please see the documentation of your version control software client for more information. Chris@16: Chris@16: Please select the desired protocol below to get the URL.", Chris@16: 'checkout_display_login' => (r.checkout_settings['display_login'] == 'none' ? '' : r.checkout_settings['display_login']), Chris@16: 'checkout_overwrite' => (r.checkout_settings['checkout_url_overwrite'] == 'true') ? '1': '0', Chris@16: 'checkout_display_command' => (r.checkout_settings["render_type"].to_s == 'cmd') ? '1' : '0' Chris@16: }) Chris@16: r.save! Chris@16: end Chris@16: Chris@16: ## Then the global settings Chris@16: Chris@16: settings = HashWithIndifferentAccess.new({ Chris@16: 'display_login' => Setting.plugin_redmine_checkout['display_login'], Chris@16: 'use_zero_clipboard' => '1', Chris@16: Chris@16: 'display_checkout_info' => (Setting.plugin_redmine_checkout['checkout_url_type'] == 'none' ? '0' : '1'), Chris@16: 'description_Abstract' => <<-EOF Chris@16: The data contained in this repository can be downloaded to your computer using one of several clients. Chris@16: Please see the documentation of your version control software client for more information. Chris@16: Chris@16: Please select the desired protocol below to get the URL. Chris@16: EOF Chris@16: }) Chris@16: Chris@16: default_commands.keys.each do |scm| Chris@16: settings["description_#{scm}"] = '' Chris@16: settings["overwrite_description_#{scm}"] = '0' Chris@16: Chris@16: display_command = (Setting.plugin_redmine_checkout["render_type"].to_s == 'cmd') ? '1' : '0' Chris@16: settings["display_command_#{scm}"] = display_command Chris@16: Chris@16: case Setting.plugin_redmine_checkout['checkout_url_type'] Chris@16: when 'generated', 'none': Chris@16: regex = Setting.plugin_redmine_checkout["checkout_url_regex_#{scm}"] Chris@16: replacement = Setting.plugin_redmine_checkout["checkout_url_regex_replacement_#{scm}"] Chris@16: when 'original': Chris@16: regex = '' Chris@16: replacement = '' Chris@16: end Chris@16: Chris@16: settings["protocols_#{scm}"] = HashWithIndifferentAccess.new({ Chris@16: # access can be one of Chris@16: # read+write => this protocol always allows read/write access Chris@16: # read-only => this protocol always allows read access only Chris@16: # permission => Access depends on redmine permissions Chris@16: '0' => HashWithIndifferentAccess.new({ Chris@16: :protocol => scm, Chris@16: :command => Setting.plugin_redmine_checkout["checkout_cmd_#{scm}"] || default_commands[scm], Chris@16: :regex => regex, Chris@16: :regex_replacement => replacement, Chris@16: :fixed_url => '', Chris@16: :access => 'permission', Chris@16: :append_path => (['Cvs', 'Subversion'].include?(scm) ? '1' : '0'), Chris@16: :is_default => '1' Chris@16: }) Chris@16: }) Chris@16: end Chris@16: Setting.plugin_redmine_checkout = settings Chris@16: end Chris@16: Chris@16: def self.down Chris@16: raise ActiveRecord::IrreversibleMigration.new "Sorry, there is no down migration yet. If you really need one, please create an issue on http://dev.holgerjust.de/projects/redmine-checkout" Chris@16: end Chris@16: end