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