comparison plugins/redmine_checkout/db/migrate/20100609153630_apply_setting_changes.rb @ 1117:b4b72f1eb644 redmine-2.2-integration

Moved all the plugins from the vendor folder to the application root folder.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Tue, 08 Jan 2013 12:32:05 +0000
parents vendor/plugins/redmine_checkout/db/migrate/20100609153630_apply_setting_changes.rb@020926a36823
children
comparison
equal deleted inserted replaced
1116:bb32da3bea34 1117:b4b72f1eb644
1 class ApplySettingChanges < ActiveRecord::Migration
2 class Repository < ActiveRecord::Base
3 def self.inheritance_column
4 # disable single table inheritance
5 nil
6 end
7
8 def scm_name
9 self.type || 'Abstract'
10 end
11
12 serialize :checkout_settings, Hash
13 end
14
15 def self.up
16 default_commands = {
17 'Bazaar' => 'bzr checkout',
18 'Cvs' => 'cvs checkout',
19 'Darcs' => 'darcs get',
20 'Git' => 'git clone',
21 'Mercurial' => 'hg clone',
22 'Subversion' => 'svn checkout'
23 }
24
25 ## First migrate the individual repositories
26
27 Repository.all.each do |r|
28 allow_subtree_checkout = ['Cvs', 'Subversion'].include? r.scm_name
29
30 protocol = case r.checkout_settings['checkout_url_type']
31 when 'none', 'generated'
32 nil
33 when 'original', 'overwritten'
34 HashWithIndifferentAccess.new({ "0" => HashWithIndifferentAccess.new({
35 :protocol => r.scm_name,
36 :command => Setting.plugin_redmine_checkout["checkout_cmd_#{r.scm_name}"] || default_commands[r.scm_name],
37 :regex => "",
38 :regex_replacement => "",
39 :fixed_url => (r.checkout_settings['checkout_url_type'] == 'original' ? (r.url || "") : r.checkout_settings["checkout_url"]),
40 :access => 'permission',
41 :append_path => (allow_subtree_checkout ? '1' : '0'),
42 :is_default => '1'})
43 })
44 end
45
46 r.checkout_settings = Hash.new({
47 'checkout_protocols' => protocol,
48 'checkout_description' => "The data contained in this repository can be downloaded to your computer using one of several clients.
49 Please see the documentation of your version control software client for more information.
50
51 Please select the desired protocol below to get the URL.",
52 'checkout_display_login' => (r.checkout_settings['display_login'] == 'none' ? '' : r.checkout_settings['display_login']),
53 'checkout_overwrite' => (r.checkout_settings['checkout_url_overwrite'] == 'true') ? '1': '0',
54 'checkout_display_command' => (r.checkout_settings["render_type"].to_s == 'cmd') ? '1' : '0'
55 })
56 r.save!
57 end
58
59 ## Then the global settings
60
61 settings = HashWithIndifferentAccess.new({
62 'display_login' => Setting.plugin_redmine_checkout['display_login'],
63 'use_zero_clipboard' => '1',
64
65 'display_checkout_info' => (Setting.plugin_redmine_checkout['checkout_url_type'] == 'none' ? '0' : '1'),
66 'description_Abstract' => <<-EOF
67 The data contained in this repository can be downloaded to your computer using one of several clients.
68 Please see the documentation of your version control software client for more information.
69
70 Please select the desired protocol below to get the URL.
71 EOF
72 })
73
74 default_commands.keys.each do |scm|
75 settings["description_#{scm}"] = ''
76 settings["overwrite_description_#{scm}"] = '0'
77
78 display_command = (Setting.plugin_redmine_checkout["render_type"].to_s == 'cmd') ? '1' : '0'
79 settings["display_command_#{scm}"] = display_command
80
81 case Setting.plugin_redmine_checkout['checkout_url_type']
82 when 'generated', 'none':
83 regex = Setting.plugin_redmine_checkout["checkout_url_regex_#{scm}"]
84 replacement = Setting.plugin_redmine_checkout["checkout_url_regex_replacement_#{scm}"]
85 when 'original':
86 regex = ''
87 replacement = ''
88 end
89
90 settings["protocols_#{scm}"] = HashWithIndifferentAccess.new({
91 # access can be one of
92 # read+write => this protocol always allows read/write access
93 # read-only => this protocol always allows read access only
94 # permission => Access depends on redmine permissions
95 '0' => HashWithIndifferentAccess.new({
96 :protocol => scm,
97 :command => Setting.plugin_redmine_checkout["checkout_cmd_#{scm}"] || default_commands[scm],
98 :regex => regex,
99 :regex_replacement => replacement,
100 :fixed_url => '',
101 :access => 'permission',
102 :append_path => (['Cvs', 'Subversion'].include?(scm) ? '1' : '0'),
103 :is_default => '1'
104 })
105 })
106 end
107 Setting.plugin_redmine_checkout = settings
108 end
109
110 def self.down
111 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"
112 end
113 end