@@ -1,409 +1,414 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | desc 'Mantis migration script' |
|
18 | desc 'Mantis migration script' | |
19 |
|
19 | |||
20 | require 'active_record' |
|
20 | require 'active_record' | |
21 | require 'iconv' |
|
21 | require 'iconv' | |
22 |
|
22 | |||
23 | task :migrate_from_mantis => :environment do |
|
23 | task :migrate_from_mantis => :environment do | |
24 |
|
24 | |||
25 | module MantisMigrate |
|
25 | module MantisMigrate | |
26 |
|
26 | |||
27 | default_status = IssueStatus.default |
|
27 | default_status = IssueStatus.default | |
28 | closed_status = IssueStatus.find :first, :conditions => { :is_closed => true } |
|
28 | assigned_status = IssueStatus.find_by_position(2) | |
29 | STATUS_MAPPING = {10 => default_status, # new |
|
29 | resolved_status = IssueStatus.find_by_position(3) | |
30 | 20 => default_status, # feedback |
|
30 | feedback_status = IssueStatus.find_by_position(4) | |
31 | 30 => default_status, # acknowledged |
|
31 | closed_status = IssueStatus.find :first, :conditions => { :is_closed => true } | |
32 |
|
|
32 | STATUS_MAPPING = {10 => default_status, # new | |
33 |
|
|
33 | 20 => feedback_status, # feedback | |
34 |
|
|
34 | 30 => default_status, # acknowledged | |
35 |
|
|
35 | 40 => default_status, # confirmed | |
|
36 | 50 => assigned_status, # assigned | |||
|
37 | 80 => resolved_status, # resolved | |||
|
38 | 90 => closed_status # closed | |||
36 | } |
|
39 | } | |
37 |
|
40 | |||
38 |
default_role = Role.find |
|
41 | default_role = Role.find_by_position(3) | |
39 | ROLE_MAPPING = {10 => default_role, # viewer |
|
42 | manager_role = Role.find_by_position(1) | |
40 | 25 => default_role, # reporter |
|
43 | developer_role = Role.find_by_position(2) | |
41 |
|
|
44 | ROLE_MAPPING = {10 => default_role, # viewer | |
42 |
|
|
45 | 25 => default_role, # reporter | |
43 |
|
|
46 | 40 => default_role, # updater | |
44 |
|
|
47 | 55 => developer_role, # developer | |
|
48 | 70 => manager_role, # manager | |||
|
49 | 90 => manager_role # administrator | |||
45 | } |
|
50 | } | |
46 |
|
51 | |||
47 | CUSTOM_FIELD_TYPE_MAPPING = {0 => 'string', # String |
|
52 | CUSTOM_FIELD_TYPE_MAPPING = {0 => 'string', # String | |
48 | 1 => 'int', # Numeric |
|
53 | 1 => 'int', # Numeric | |
49 | 2 => 'int', # Float |
|
54 | 2 => 'int', # Float | |
50 | 3 => 'list', # Enumeration |
|
55 | 3 => 'list', # Enumeration | |
51 | 4 => 'string', # Email |
|
56 | 4 => 'string', # Email | |
52 | 5 => 'bool', # Checkbox |
|
57 | 5 => 'bool', # Checkbox | |
53 | 6 => 'list', # List |
|
58 | 6 => 'list', # List | |
54 | 7 => 'list', # Multiselection list |
|
59 | 7 => 'list', # Multiselection list | |
55 | 8 => 'date', # Date |
|
60 | 8 => 'date', # Date | |
56 | } |
|
61 | } | |
57 |
|
62 | |||
58 | class MantisUser < ActiveRecord::Base |
|
63 | class MantisUser < ActiveRecord::Base | |
59 | set_table_name :mantis_user_table |
|
64 | set_table_name :mantis_user_table | |
60 |
|
65 | |||
61 | def firstname |
|
66 | def firstname | |
62 | realname.blank? ? username : realname.split.first |
|
67 | realname.blank? ? username : realname.split.first | |
63 | end |
|
68 | end | |
64 |
|
69 | |||
65 | def lastname |
|
70 | def lastname | |
66 | realname.blank? ? username : realname.split[1..-1].join(' ') |
|
71 | realname.blank? ? username : realname.split[1..-1].join(' ') | |
67 | end |
|
72 | end | |
68 |
|
73 | |||
69 | def email |
|
74 | def email | |
70 | if read_attribute(:email).match(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i) |
|
75 | if read_attribute(:email).match(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i) | |
71 | read_attribute(:email) |
|
76 | read_attribute(:email) | |
72 | else |
|
77 | else | |
73 | "#{username}@foo.bar" |
|
78 | "#{username}@foo.bar" | |
74 | end |
|
79 | end | |
75 | end |
|
80 | end | |
76 | end |
|
81 | end | |
77 |
|
82 | |||
78 | class MantisProject < ActiveRecord::Base |
|
83 | class MantisProject < ActiveRecord::Base | |
79 | set_table_name :mantis_project_table |
|
84 | set_table_name :mantis_project_table | |
80 | has_many :versions, :class_name => "MantisVersion", :foreign_key => :project_id |
|
85 | has_many :versions, :class_name => "MantisVersion", :foreign_key => :project_id | |
81 | has_many :categories, :class_name => "MantisCategory", :foreign_key => :project_id |
|
86 | has_many :categories, :class_name => "MantisCategory", :foreign_key => :project_id | |
82 | has_many :news, :class_name => "MantisNews", :foreign_key => :project_id |
|
87 | has_many :news, :class_name => "MantisNews", :foreign_key => :project_id | |
83 | has_many :members, :class_name => "MantisProjectUser", :foreign_key => :project_id |
|
88 | has_many :members, :class_name => "MantisProjectUser", :foreign_key => :project_id | |
84 |
|
89 | |||
85 | def name |
|
90 | def name | |
86 | read_attribute(:name)[0..29].gsub(/[^\w\s\'\-]/, '-') |
|
91 | read_attribute(:name)[0..29].gsub(/[^\w\s\'\-]/, '-') | |
87 | end |
|
92 | end | |
88 |
|
93 | |||
89 | def description |
|
94 | def description | |
90 | read_attribute(:description).blank? ? read_attribute(:name) : read_attribute(:description)[0..254] |
|
95 | read_attribute(:description).blank? ? read_attribute(:name) : read_attribute(:description)[0..254] | |
91 | end |
|
96 | end | |
92 |
|
97 | |||
93 | def identifier |
|
98 | def identifier | |
94 | read_attribute(:name).underscore[0..11].gsub(/[^a-z0-9\-]/, '-') |
|
99 | read_attribute(:name).underscore[0..11].gsub(/[^a-z0-9\-]/, '-') | |
95 | end |
|
100 | end | |
96 | end |
|
101 | end | |
97 |
|
102 | |||
98 | class MantisVersion < ActiveRecord::Base |
|
103 | class MantisVersion < ActiveRecord::Base | |
99 | set_table_name :mantis_project_version_table |
|
104 | set_table_name :mantis_project_version_table | |
100 |
|
105 | |||
101 | def version |
|
106 | def version | |
102 | read_attribute(:version)[0..29] |
|
107 | read_attribute(:version)[0..29] | |
103 | end |
|
108 | end | |
104 |
|
109 | |||
105 | def description |
|
110 | def description | |
106 | read_attribute(:description)[0..254] |
|
111 | read_attribute(:description)[0..254] | |
107 | end |
|
112 | end | |
108 | end |
|
113 | end | |
109 |
|
114 | |||
110 | class MantisCategory < ActiveRecord::Base |
|
115 | class MantisCategory < ActiveRecord::Base | |
111 | set_table_name :mantis_project_category_table |
|
116 | set_table_name :mantis_project_category_table | |
112 | end |
|
117 | end | |
113 |
|
118 | |||
114 | class MantisProjectUser < ActiveRecord::Base |
|
119 | class MantisProjectUser < ActiveRecord::Base | |
115 | set_table_name :mantis_project_user_list_table |
|
120 | set_table_name :mantis_project_user_list_table | |
116 | end |
|
121 | end | |
117 |
|
122 | |||
118 | class MantisBug < ActiveRecord::Base |
|
123 | class MantisBug < ActiveRecord::Base | |
119 | set_table_name :mantis_bug_table |
|
124 | set_table_name :mantis_bug_table | |
120 | belongs_to :bug_text, :class_name => "MantisBugText", :foreign_key => :bug_text_id |
|
125 | belongs_to :bug_text, :class_name => "MantisBugText", :foreign_key => :bug_text_id | |
121 | has_many :bug_notes, :class_name => "MantisBugNote", :foreign_key => :bug_id |
|
126 | has_many :bug_notes, :class_name => "MantisBugNote", :foreign_key => :bug_id | |
122 | has_many :bug_files, :class_name => "MantisBugFile", :foreign_key => :bug_id |
|
127 | has_many :bug_files, :class_name => "MantisBugFile", :foreign_key => :bug_id | |
123 | end |
|
128 | end | |
124 |
|
129 | |||
125 | class MantisBugText < ActiveRecord::Base |
|
130 | class MantisBugText < ActiveRecord::Base | |
126 | set_table_name :mantis_bug_text_table |
|
131 | set_table_name :mantis_bug_text_table | |
127 | end |
|
132 | end | |
128 |
|
133 | |||
129 | class MantisBugNote < ActiveRecord::Base |
|
134 | class MantisBugNote < ActiveRecord::Base | |
130 | set_table_name :mantis_bugnote_table |
|
135 | set_table_name :mantis_bugnote_table | |
131 | belongs_to :bug, :class_name => "MantisBug", :foreign_key => :bug_id |
|
136 | belongs_to :bug, :class_name => "MantisBug", :foreign_key => :bug_id | |
132 | belongs_to :bug_note_text, :class_name => "MantisBugNoteText", :foreign_key => :bugnote_text_id |
|
137 | belongs_to :bug_note_text, :class_name => "MantisBugNoteText", :foreign_key => :bugnote_text_id | |
133 | end |
|
138 | end | |
134 |
|
139 | |||
135 | class MantisBugNoteText < ActiveRecord::Base |
|
140 | class MantisBugNoteText < ActiveRecord::Base | |
136 | set_table_name :mantis_bugnote_text_table |
|
141 | set_table_name :mantis_bugnote_text_table | |
137 | end |
|
142 | end | |
138 |
|
143 | |||
139 | class MantisBugFile < ActiveRecord::Base |
|
144 | class MantisBugFile < ActiveRecord::Base | |
140 | set_table_name :mantis_bug_file_table |
|
145 | set_table_name :mantis_bug_file_table | |
141 |
|
146 | |||
142 | def size |
|
147 | def size | |
143 | filesize |
|
148 | filesize | |
144 | end |
|
149 | end | |
145 |
|
150 | |||
146 | def original_filename |
|
151 | def original_filename | |
147 | filename |
|
152 | filename | |
148 | end |
|
153 | end | |
149 |
|
154 | |||
150 | def content_type |
|
155 | def content_type | |
151 | file_type |
|
156 | file_type | |
152 | end |
|
157 | end | |
153 |
|
158 | |||
154 | def read |
|
159 | def read | |
155 | content |
|
160 | content | |
156 | end |
|
161 | end | |
157 | end |
|
162 | end | |
158 |
|
163 | |||
159 | class MantisNews < ActiveRecord::Base |
|
164 | class MantisNews < ActiveRecord::Base | |
160 | set_table_name :mantis_news_table |
|
165 | set_table_name :mantis_news_table | |
161 | end |
|
166 | end | |
162 |
|
167 | |||
163 | class MantisCustomField < ActiveRecord::Base |
|
168 | class MantisCustomField < ActiveRecord::Base | |
164 | set_table_name :mantis_custom_field_table |
|
169 | set_table_name :mantis_custom_field_table | |
165 | set_inheritance_column :none |
|
170 | set_inheritance_column :none | |
166 | has_many :values, :class_name => "MantisCustomFieldString", :foreign_key => :field_id |
|
171 | has_many :values, :class_name => "MantisCustomFieldString", :foreign_key => :field_id | |
167 | has_many :projects, :class_name => "MantisCustomFieldProject", :foreign_key => :field_id |
|
172 | has_many :projects, :class_name => "MantisCustomFieldProject", :foreign_key => :field_id | |
168 |
|
173 | |||
169 | def format |
|
174 | def format | |
170 | read_attribute :type |
|
175 | read_attribute :type | |
171 | end |
|
176 | end | |
172 |
|
177 | |||
173 | def name |
|
178 | def name | |
174 | read_attribute(:name)[0..29].gsub(/[^\w\s\'\-]/, '-') |
|
179 | read_attribute(:name)[0..29].gsub(/[^\w\s\'\-]/, '-') | |
175 | end |
|
180 | end | |
176 | end |
|
181 | end | |
177 |
|
182 | |||
178 | class MantisCustomFieldProject < ActiveRecord::Base |
|
183 | class MantisCustomFieldProject < ActiveRecord::Base | |
179 | set_table_name :mantis_custom_field_project_table |
|
184 | set_table_name :mantis_custom_field_project_table | |
180 | end |
|
185 | end | |
181 |
|
186 | |||
182 | class MantisCustomFieldString < ActiveRecord::Base |
|
187 | class MantisCustomFieldString < ActiveRecord::Base | |
183 | set_table_name :mantis_custom_field_string_table |
|
188 | set_table_name :mantis_custom_field_string_table | |
184 | end |
|
189 | end | |
185 |
|
190 | |||
186 |
|
191 | |||
187 | def self.migrate |
|
192 | def self.migrate | |
188 |
|
193 | |||
189 | # Users |
|
194 | # Users | |
190 | print "Migrating users" |
|
195 | print "Migrating users" | |
191 | User.delete_all "login <> 'admin'" |
|
196 | User.delete_all "login <> 'admin'" | |
192 | users_map = {} |
|
197 | users_map = {} | |
193 | users_migrated = 0 |
|
198 | users_migrated = 0 | |
194 | MantisUser.find(:all).each do |user| |
|
199 | MantisUser.find(:all).each do |user| | |
195 | u = User.new :firstname => encode(user.firstname), |
|
200 | u = User.new :firstname => encode(user.firstname), | |
196 | :lastname => encode(user.lastname), |
|
201 | :lastname => encode(user.lastname), | |
197 | :mail => user.email, |
|
202 | :mail => user.email, | |
198 | :last_login_on => user.last_visit |
|
203 | :last_login_on => user.last_visit | |
199 | u.login = user.username |
|
204 | u.login = user.username | |
200 | u.password = 'mantis' |
|
205 | u.password = 'mantis' | |
201 | u.status = User::STATUS_LOCKED if user.enabled != 1 |
|
206 | u.status = User::STATUS_LOCKED if user.enabled != 1 | |
202 | u.admin = true if user.access_level == 90 |
|
207 | u.admin = true if user.access_level == 90 | |
203 | next unless u.save |
|
208 | next unless u.save | |
204 | users_migrated += 1 |
|
209 | users_migrated += 1 | |
205 | users_map[user.id] = u.id |
|
210 | users_map[user.id] = u.id | |
206 | print '.' |
|
211 | print '.' | |
207 | end |
|
212 | end | |
208 | puts |
|
213 | puts | |
209 |
|
214 | |||
210 | # Projects |
|
215 | # Projects | |
211 | print "Migrating projects" |
|
216 | print "Migrating projects" | |
212 | Project.destroy_all |
|
217 | Project.destroy_all | |
213 | projects_map = {} |
|
218 | projects_map = {} | |
214 | versions_map = {} |
|
219 | versions_map = {} | |
215 | categories_map = {} |
|
220 | categories_map = {} | |
216 | MantisProject.find(:all).each do |project| |
|
221 | MantisProject.find(:all).each do |project| | |
217 | p = Project.new :name => encode(project.name), |
|
222 | p = Project.new :name => encode(project.name), | |
218 | :description => encode(project.description) |
|
223 | :description => encode(project.description) | |
219 | p.identifier = project.identifier |
|
224 | p.identifier = project.identifier | |
220 | next unless p.save |
|
225 | next unless p.save | |
221 | projects_map[project.id] = p.id |
|
226 | projects_map[project.id] = p.id | |
222 | print '.' |
|
227 | print '.' | |
223 |
|
228 | |||
224 | # Project members |
|
229 | # Project members | |
225 | project.members.each do |member| |
|
230 | project.members.each do |member| | |
226 | m = Member.new :user => User.find(users_map[member.user_id]), |
|
231 | m = Member.new :user => User.find(users_map[member.user_id]), | |
227 | :role => ROLE_MAPPING[member.access_level] || default_role |
|
232 | :role => ROLE_MAPPING[member.access_level] || default_role | |
228 | m.project = p |
|
233 | m.project = p | |
229 | m.save |
|
234 | m.save | |
230 | end |
|
235 | end | |
231 |
|
236 | |||
232 | # Project versions |
|
237 | # Project versions | |
233 | project.versions.each do |version| |
|
238 | project.versions.each do |version| | |
234 | v = Version.new :name => encode(version.version), |
|
239 | v = Version.new :name => encode(version.version), | |
235 | :description => encode(version.description), |
|
240 | :description => encode(version.description), | |
236 | :effective_date => version.date_order.to_date |
|
241 | :effective_date => version.date_order.to_date | |
237 | v.project = p |
|
242 | v.project = p | |
238 | v.save |
|
243 | v.save | |
239 | versions_map[version.id] = v.id |
|
244 | versions_map[version.id] = v.id | |
240 | end |
|
245 | end | |
241 |
|
246 | |||
242 | # Project categories |
|
247 | # Project categories | |
243 | project.categories.each do |category| |
|
248 | project.categories.each do |category| | |
244 | g = IssueCategory.new :name => category.category |
|
249 | g = IssueCategory.new :name => category.category | |
245 | g.project = p |
|
250 | g.project = p | |
246 | g.save |
|
251 | g.save | |
247 | categories_map[category.category] = g.id |
|
252 | categories_map[category.category] = g.id | |
248 | end |
|
253 | end | |
249 | end |
|
254 | end | |
250 | puts |
|
255 | puts | |
251 |
|
256 | |||
252 | # Bugs |
|
257 | # Bugs | |
253 | print "Migrating bugs" |
|
258 | print "Migrating bugs" | |
254 | Issue.destroy_all |
|
259 | Issue.destroy_all | |
255 | issues_map = {} |
|
260 | issues_map = {} | |
256 | MantisBug.find(:all).each do |bug| |
|
261 | MantisBug.find(:all).each do |bug| | |
257 | next unless projects_map[bug.project_id] |
|
262 | next unless projects_map[bug.project_id] | |
258 | i = Issue.new :project_id => projects_map[bug.project_id], |
|
263 | i = Issue.new :project_id => projects_map[bug.project_id], | |
259 | :subject => encode(bug.summary), |
|
264 | :subject => encode(bug.summary), | |
260 | :description => encode(bug.bug_text.description), |
|
265 | :description => encode(bug.bug_text.description), | |
261 | # TODO |
|
266 | # TODO | |
262 | :priority => Enumeration.get_values('IPRI').first, |
|
267 | :priority => Enumeration.get_values('IPRI').first, | |
263 | :created_on => bug.date_submitted, |
|
268 | :created_on => bug.date_submitted, | |
264 | :updated_on => bug.last_updated |
|
269 | :updated_on => bug.last_updated | |
265 | i.author = User.find(users_map[bug.reporter_id] || :first) |
|
270 | i.author = User.find(users_map[bug.reporter_id] || :first) | |
266 | i.assigned_to = User.find(users_map[bug.handler_id]) if bug.handler_id && users_map[bug.handler_id] |
|
271 | i.assigned_to = User.find(users_map[bug.handler_id]) if bug.handler_id && users_map[bug.handler_id] | |
267 | i.category = IssueCategory.find_by_project_id_and_name(i.project_id, bug.category) unless bug.category.blank? |
|
272 | i.category = IssueCategory.find_by_project_id_and_name(i.project_id, bug.category) unless bug.category.blank? | |
268 | i.fixed_version = Version.find_by_project_id_and_name(i.project_id, bug.fixed_in_version) unless bug.fixed_in_version.blank? |
|
273 | i.fixed_version = Version.find_by_project_id_and_name(i.project_id, bug.fixed_in_version) unless bug.fixed_in_version.blank? | |
269 | i.status = STATUS_MAPPING[bug.status] || default_status |
|
274 | i.status = STATUS_MAPPING[bug.status] || default_status | |
270 | # TODO |
|
275 | # TODO | |
271 | i.tracker = Tracker.find(:first) |
|
276 | i.tracker = Tracker.find(:first) | |
272 | next unless i.save |
|
277 | next unless i.save | |
273 | issues_map[bug.id] = i.id |
|
278 | issues_map[bug.id] = i.id | |
274 | print '.' |
|
279 | print '.' | |
275 |
|
280 | |||
276 | # Bug notes |
|
281 | # Bug notes | |
277 | bug.bug_notes.each do |note| |
|
282 | bug.bug_notes.each do |note| | |
278 | n = Journal.new :notes => encode(note.bug_note_text.note), |
|
283 | n = Journal.new :notes => encode(note.bug_note_text.note), | |
279 | :created_on => note.date_submitted |
|
284 | :created_on => note.date_submitted | |
280 | n.user = User.find(users_map[note.reporter_id] || :first) |
|
285 | n.user = User.find(users_map[note.reporter_id] || :first) | |
281 | n.journalized = i |
|
286 | n.journalized = i | |
282 | n.save |
|
287 | n.save | |
283 | end |
|
288 | end | |
284 |
|
289 | |||
285 | # Bug files |
|
290 | # Bug files | |
286 | bug.bug_files.each do |file| |
|
291 | bug.bug_files.each do |file| | |
287 | a = Attachment.new :created_on => file.date_added |
|
292 | a = Attachment.new :created_on => file.date_added | |
288 | a.file = file |
|
293 | a.file = file | |
289 | a.author = User.find :first |
|
294 | a.author = User.find :first | |
290 | a.container = i |
|
295 | a.container = i | |
291 | a.save |
|
296 | a.save | |
292 | end |
|
297 | end | |
293 | end |
|
298 | end | |
294 | puts |
|
299 | puts | |
295 |
|
300 | |||
296 | # News |
|
301 | # News | |
297 | print "Migrating news" |
|
302 | print "Migrating news" | |
298 | News.destroy_all |
|
303 | News.destroy_all | |
299 | MantisNews.find(:all, :conditions => 'project_id > 0').each do |news| |
|
304 | MantisNews.find(:all, :conditions => 'project_id > 0').each do |news| | |
300 | next unless projects_map[news.project_id] |
|
305 | next unless projects_map[news.project_id] | |
301 | n = News.new :project_id => projects_map[news.project_id], |
|
306 | n = News.new :project_id => projects_map[news.project_id], | |
302 | :title => encode(news.headline[0..59]), |
|
307 | :title => encode(news.headline[0..59]), | |
303 | :description => encode(news.body), |
|
308 | :description => encode(news.body), | |
304 | :created_on => news.date_posted |
|
309 | :created_on => news.date_posted | |
305 | n.author = User.find(users_map[news.poster_id] || :first) |
|
310 | n.author = User.find(users_map[news.poster_id] || :first) | |
306 | n.save |
|
311 | n.save | |
307 | print '.' |
|
312 | print '.' | |
308 | end |
|
313 | end | |
309 | puts |
|
314 | puts | |
310 |
|
315 | |||
311 | # Custom fields |
|
316 | # Custom fields | |
312 | print "Migrating custom fields" |
|
317 | print "Migrating custom fields" | |
313 | IssueCustomField.destroy_all |
|
318 | IssueCustomField.destroy_all | |
314 | MantisCustomField.find(:all).each do |field| |
|
319 | MantisCustomField.find(:all).each do |field| | |
315 | f = IssueCustomField.new :name => field.name[0..29], |
|
320 | f = IssueCustomField.new :name => field.name[0..29], | |
316 | :field_format => CUSTOM_FIELD_TYPE_MAPPING[field.format], |
|
321 | :field_format => CUSTOM_FIELD_TYPE_MAPPING[field.format], | |
317 | :min_length => field.length_min, |
|
322 | :min_length => field.length_min, | |
318 | :max_length => field.length_max, |
|
323 | :max_length => field.length_max, | |
319 | :regexp => field.valid_regexp, |
|
324 | :regexp => field.valid_regexp, | |
320 | :possible_values => field.possible_values.split('|'), |
|
325 | :possible_values => field.possible_values.split('|'), | |
321 | :is_required => (field.require_report > 0) |
|
326 | :is_required => (field.require_report > 0) | |
322 | next unless f.save |
|
327 | next unless f.save | |
323 | print '.' |
|
328 | print '.' | |
324 |
|
329 | |||
325 | # Trackers association |
|
330 | # Trackers association | |
326 | f.trackers = Tracker.find :all |
|
331 | f.trackers = Tracker.find :all | |
327 |
|
332 | |||
328 | # Projects association |
|
333 | # Projects association | |
329 | field.projects.each do |project| |
|
334 | field.projects.each do |project| | |
330 | f.projects << Project.find_by_id(projects_map[project.project_id]) if projects_map[project.project_id] |
|
335 | f.projects << Project.find_by_id(projects_map[project.project_id]) if projects_map[project.project_id] | |
331 | end |
|
336 | end | |
332 |
|
337 | |||
333 | # Values |
|
338 | # Values | |
334 | field.values.each do |value| |
|
339 | field.values.each do |value| | |
335 | v = CustomValue.new :custom_field_id => f.id, |
|
340 | v = CustomValue.new :custom_field_id => f.id, | |
336 | :value => value.value |
|
341 | :value => value.value | |
337 | v.customized = Issue.find_by_id(issues_map[value.bug_id]) if issues_map[value.bug_id] |
|
342 | v.customized = Issue.find_by_id(issues_map[value.bug_id]) if issues_map[value.bug_id] | |
338 | v.save |
|
343 | v.save | |
339 | end unless f.new_record? |
|
344 | end unless f.new_record? | |
340 | end |
|
345 | end | |
341 | puts |
|
346 | puts | |
342 |
|
347 | |||
343 | puts |
|
348 | puts | |
344 | puts "Users: #{users_migrated}/#{MantisUser.count}" |
|
349 | puts "Users: #{users_migrated}/#{MantisUser.count}" | |
345 | puts "Projects: #{Project.count}/#{MantisProject.count}" |
|
350 | puts "Projects: #{Project.count}/#{MantisProject.count}" | |
346 | puts "Memberships: #{Member.count}/#{MantisProjectUser.count}" |
|
351 | puts "Memberships: #{Member.count}/#{MantisProjectUser.count}" | |
347 | puts "Versions: #{Version.count}/#{MantisVersion.count}" |
|
352 | puts "Versions: #{Version.count}/#{MantisVersion.count}" | |
348 | puts "Categories: #{IssueCategory.count}/#{MantisCategory.count}" |
|
353 | puts "Categories: #{IssueCategory.count}/#{MantisCategory.count}" | |
349 | puts "Bugs: #{Issue.count}/#{MantisBug.count}" |
|
354 | puts "Bugs: #{Issue.count}/#{MantisBug.count}" | |
350 | puts "Bug notes: #{Journal.count}/#{MantisBugNote.count}" |
|
355 | puts "Bug notes: #{Journal.count}/#{MantisBugNote.count}" | |
351 | puts "Bug files: #{Attachment.count}/#{MantisBugFile.count}" |
|
356 | puts "Bug files: #{Attachment.count}/#{MantisBugFile.count}" | |
352 | puts "News: #{News.count}/#{MantisNews.count}" |
|
357 | puts "News: #{News.count}/#{MantisNews.count}" | |
353 | puts "Custom fields: #{IssueCustomField.count}/#{MantisCustomField.count}" |
|
358 | puts "Custom fields: #{IssueCustomField.count}/#{MantisCustomField.count}" | |
354 | end |
|
359 | end | |
355 |
|
360 | |||
356 | def self.encoding(charset) |
|
361 | def self.encoding(charset) | |
357 | @ic = Iconv.new('UTF-8', charset) |
|
362 | @ic = Iconv.new('UTF-8', charset) | |
358 | rescue Iconv::InvalidEncoding |
|
363 | rescue Iconv::InvalidEncoding | |
359 | return false |
|
364 | return false | |
360 | end |
|
365 | end | |
361 |
|
366 | |||
362 | def self.establish_connection(params) |
|
367 | def self.establish_connection(params) | |
363 | constants.each do |const| |
|
368 | constants.each do |const| | |
364 | klass = const_get(const) |
|
369 | klass = const_get(const) | |
365 | next unless klass.respond_to? 'establish_connection' |
|
370 | next unless klass.respond_to? 'establish_connection' | |
366 | klass.establish_connection params |
|
371 | klass.establish_connection params | |
367 | end |
|
372 | end | |
368 | end |
|
373 | end | |
369 |
|
374 | |||
370 | private |
|
375 | private | |
371 | def self.encode(text) |
|
376 | def self.encode(text) | |
372 | @ic.iconv text |
|
377 | @ic.iconv text | |
373 | rescue |
|
378 | rescue | |
374 | text |
|
379 | text | |
375 | end |
|
380 | end | |
376 | end |
|
381 | end | |
377 |
|
382 | |||
378 | puts |
|
383 | puts | |
379 | puts "WARNING: Your Redmine data will be deleted during this process." |
|
384 | puts "WARNING: Your Redmine data will be deleted during this process." | |
380 | print "Are you sure you want to continue ? [y/N] " |
|
385 | print "Are you sure you want to continue ? [y/N] " | |
381 | break unless STDIN.gets.match(/^y$/i) |
|
386 | break unless STDIN.gets.match(/^y$/i) | |
382 |
|
387 | |||
383 | # default Mantis database settings |
|
388 | # default Mantis database settings | |
384 | db_params = {:adapter => 'mysql', |
|
389 | db_params = {:adapter => 'mysql', | |
385 | :database => 'bugtracker', |
|
390 | :database => 'bugtracker', | |
386 | :host => 'localhost', |
|
391 | :host => 'localhost', | |
387 | :username => 'root', |
|
392 | :username => 'root', | |
388 | :password => '' } |
|
393 | :password => '' } | |
389 |
|
394 | |||
390 | puts |
|
395 | puts | |
391 | puts "Please enter settings for your Mantis database" |
|
396 | puts "Please enter settings for your Mantis database" | |
392 | [:adapter, :host, :database, :username, :password].each do |param| |
|
397 | [:adapter, :host, :database, :username, :password].each do |param| | |
393 | print "#{param} [#{db_params[param]}]: " |
|
398 | print "#{param} [#{db_params[param]}]: " | |
394 | value = STDIN.gets.chomp! |
|
399 | value = STDIN.gets.chomp! | |
395 | db_params[param] = value unless value.blank? |
|
400 | db_params[param] = value unless value.blank? | |
396 | end |
|
401 | end | |
397 |
|
402 | |||
398 | while true |
|
403 | while true | |
399 | print "encoding [ISO-8859-1]: " |
|
404 | print "encoding [ISO-8859-1]: " | |
400 | encoding = STDIN.gets.chomp! |
|
405 | encoding = STDIN.gets.chomp! | |
401 | encoding = 'ISO-8859-1' if encoding.blank? |
|
406 | encoding = 'ISO-8859-1' if encoding.blank? | |
402 | break if MantisMigrate.encoding encoding |
|
407 | break if MantisMigrate.encoding encoding | |
403 | puts "Invalid encoding!" |
|
408 | puts "Invalid encoding!" | |
404 | end |
|
409 | end | |
405 | puts |
|
410 | puts | |
406 |
|
411 | |||
407 | MantisMigrate.establish_connection db_params |
|
412 | MantisMigrate.establish_connection db_params | |
408 | MantisMigrate.migrate |
|
413 | MantisMigrate.migrate | |
409 | end |
|
414 | end |
General Comments 0
You need to be logged in to leave comments.
Login now