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