Chris@0
|
1 # redMine - project management software
|
Chris@0
|
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
|
Chris@0
|
3 #
|
Chris@0
|
4 # This program is free software; you can redistribute it and/or
|
Chris@0
|
5 # modify it under the terms of the GNU General Public License
|
Chris@0
|
6 # as published by the Free Software Foundation; either version 2
|
Chris@0
|
7 # of the License, or (at your option) any later version.
|
Chris@0
|
8 #
|
Chris@0
|
9 # This program is distributed in the hope that it will be useful,
|
Chris@0
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
12 # GNU General Public License for more details.
|
Chris@0
|
13 #
|
Chris@0
|
14 # You should have received a copy of the GNU General Public License
|
Chris@0
|
15 # along with this program; if not, write to the Free Software
|
Chris@0
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@0
|
17
|
Chris@0
|
18 desc 'Mantis migration script'
|
Chris@0
|
19
|
Chris@0
|
20 require 'active_record'
|
Chris@0
|
21 require 'iconv'
|
Chris@0
|
22 require 'pp'
|
Chris@0
|
23
|
Chris@0
|
24 namespace :redmine do
|
Chris@0
|
25 task :migrate_from_mantis => :environment do
|
Chris@0
|
26
|
Chris@0
|
27 module MantisMigrate
|
Chris@0
|
28
|
Chris@0
|
29 DEFAULT_STATUS = IssueStatus.default
|
Chris@0
|
30 assigned_status = IssueStatus.find_by_position(2)
|
Chris@0
|
31 resolved_status = IssueStatus.find_by_position(3)
|
Chris@0
|
32 feedback_status = IssueStatus.find_by_position(4)
|
Chris@0
|
33 closed_status = IssueStatus.find :first, :conditions => { :is_closed => true }
|
Chris@0
|
34 STATUS_MAPPING = {10 => DEFAULT_STATUS, # new
|
Chris@0
|
35 20 => feedback_status, # feedback
|
Chris@0
|
36 30 => DEFAULT_STATUS, # acknowledged
|
Chris@0
|
37 40 => DEFAULT_STATUS, # confirmed
|
Chris@0
|
38 50 => assigned_status, # assigned
|
Chris@0
|
39 80 => resolved_status, # resolved
|
Chris@0
|
40 90 => closed_status # closed
|
Chris@0
|
41 }
|
Chris@0
|
42
|
Chris@0
|
43 priorities = IssuePriority.all
|
Chris@0
|
44 DEFAULT_PRIORITY = priorities[2]
|
Chris@0
|
45 PRIORITY_MAPPING = {10 => priorities[1], # none
|
Chris@0
|
46 20 => priorities[1], # low
|
Chris@0
|
47 30 => priorities[2], # normal
|
Chris@0
|
48 40 => priorities[3], # high
|
Chris@0
|
49 50 => priorities[4], # urgent
|
Chris@0
|
50 60 => priorities[5] # immediate
|
Chris@0
|
51 }
|
Chris@0
|
52
|
Chris@0
|
53 TRACKER_BUG = Tracker.find_by_position(1)
|
Chris@0
|
54 TRACKER_FEATURE = Tracker.find_by_position(2)
|
Chris@0
|
55
|
Chris@0
|
56 roles = Role.find(:all, :conditions => {:builtin => 0}, :order => 'position ASC')
|
Chris@0
|
57 manager_role = roles[0]
|
Chris@0
|
58 developer_role = roles[1]
|
Chris@0
|
59 DEFAULT_ROLE = roles.last
|
Chris@0
|
60 ROLE_MAPPING = {10 => DEFAULT_ROLE, # viewer
|
Chris@0
|
61 25 => DEFAULT_ROLE, # reporter
|
Chris@0
|
62 40 => DEFAULT_ROLE, # updater
|
Chris@0
|
63 55 => developer_role, # developer
|
Chris@0
|
64 70 => manager_role, # manager
|
Chris@0
|
65 90 => manager_role # administrator
|
Chris@0
|
66 }
|
Chris@0
|
67
|
Chris@0
|
68 CUSTOM_FIELD_TYPE_MAPPING = {0 => 'string', # String
|
Chris@0
|
69 1 => 'int', # Numeric
|
Chris@0
|
70 2 => 'int', # Float
|
Chris@0
|
71 3 => 'list', # Enumeration
|
Chris@0
|
72 4 => 'string', # Email
|
Chris@0
|
73 5 => 'bool', # Checkbox
|
Chris@0
|
74 6 => 'list', # List
|
Chris@0
|
75 7 => 'list', # Multiselection list
|
Chris@0
|
76 8 => 'date', # Date
|
Chris@0
|
77 }
|
Chris@0
|
78
|
Chris@0
|
79 RELATION_TYPE_MAPPING = {1 => IssueRelation::TYPE_RELATES, # related to
|
Chris@0
|
80 2 => IssueRelation::TYPE_RELATES, # parent of
|
Chris@0
|
81 3 => IssueRelation::TYPE_RELATES, # child of
|
Chris@0
|
82 0 => IssueRelation::TYPE_DUPLICATES, # duplicate of
|
Chris@0
|
83 4 => IssueRelation::TYPE_DUPLICATES # has duplicate
|
Chris@0
|
84 }
|
Chris@0
|
85
|
Chris@0
|
86 class MantisUser < ActiveRecord::Base
|
Chris@0
|
87 set_table_name :mantis_user_table
|
Chris@0
|
88
|
Chris@0
|
89 def firstname
|
Chris@0
|
90 @firstname = realname.blank? ? username : realname.split.first[0..29]
|
Chris@0
|
91 @firstname
|
Chris@0
|
92 end
|
Chris@0
|
93
|
Chris@0
|
94 def lastname
|
Chris@0
|
95 @lastname = realname.blank? ? '-' : realname.split[1..-1].join(' ')[0..29]
|
Chris@0
|
96 @lastname = '-' if @lastname.blank?
|
Chris@0
|
97 @lastname
|
Chris@0
|
98 end
|
Chris@0
|
99
|
Chris@0
|
100 def email
|
Chris@0
|
101 if read_attribute(:email).match(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i) &&
|
Chris@0
|
102 !User.find_by_mail(read_attribute(:email))
|
Chris@0
|
103 @email = read_attribute(:email)
|
Chris@0
|
104 else
|
Chris@0
|
105 @email = "#{username}@foo.bar"
|
Chris@0
|
106 end
|
Chris@0
|
107 end
|
Chris@0
|
108
|
Chris@0
|
109 def username
|
Chris@0
|
110 read_attribute(:username)[0..29].gsub(/[^a-zA-Z0-9_\-@\.]/, '-')
|
Chris@0
|
111 end
|
Chris@0
|
112 end
|
Chris@0
|
113
|
Chris@0
|
114 class MantisProject < ActiveRecord::Base
|
Chris@0
|
115 set_table_name :mantis_project_table
|
Chris@0
|
116 has_many :versions, :class_name => "MantisVersion", :foreign_key => :project_id
|
Chris@0
|
117 has_many :categories, :class_name => "MantisCategory", :foreign_key => :project_id
|
Chris@0
|
118 has_many :news, :class_name => "MantisNews", :foreign_key => :project_id
|
Chris@0
|
119 has_many :members, :class_name => "MantisProjectUser", :foreign_key => :project_id
|
Chris@0
|
120
|
Chris@0
|
121 def identifier
|
chris@37
|
122 read_attribute(:name).gsub(/[^a-z0-9\-]+/, '-').slice(0, Project::IDENTIFIER_MAX_LENGTH)
|
Chris@0
|
123 end
|
Chris@0
|
124 end
|
Chris@0
|
125
|
Chris@0
|
126 class MantisVersion < ActiveRecord::Base
|
Chris@0
|
127 set_table_name :mantis_project_version_table
|
Chris@0
|
128
|
Chris@0
|
129 def version
|
Chris@0
|
130 read_attribute(:version)[0..29]
|
Chris@0
|
131 end
|
Chris@0
|
132
|
Chris@0
|
133 def description
|
Chris@0
|
134 read_attribute(:description)[0..254]
|
Chris@0
|
135 end
|
Chris@0
|
136 end
|
Chris@0
|
137
|
Chris@0
|
138 class MantisCategory < ActiveRecord::Base
|
Chris@0
|
139 set_table_name :mantis_project_category_table
|
Chris@0
|
140 end
|
Chris@0
|
141
|
Chris@0
|
142 class MantisProjectUser < ActiveRecord::Base
|
Chris@0
|
143 set_table_name :mantis_project_user_list_table
|
Chris@0
|
144 end
|
Chris@0
|
145
|
Chris@0
|
146 class MantisBug < ActiveRecord::Base
|
Chris@0
|
147 set_table_name :mantis_bug_table
|
Chris@0
|
148 belongs_to :bug_text, :class_name => "MantisBugText", :foreign_key => :bug_text_id
|
Chris@0
|
149 has_many :bug_notes, :class_name => "MantisBugNote", :foreign_key => :bug_id
|
Chris@0
|
150 has_many :bug_files, :class_name => "MantisBugFile", :foreign_key => :bug_id
|
Chris@0
|
151 has_many :bug_monitors, :class_name => "MantisBugMonitor", :foreign_key => :bug_id
|
Chris@0
|
152 end
|
Chris@0
|
153
|
Chris@0
|
154 class MantisBugText < ActiveRecord::Base
|
Chris@0
|
155 set_table_name :mantis_bug_text_table
|
Chris@0
|
156
|
Chris@0
|
157 # Adds Mantis steps_to_reproduce and additional_information fields
|
Chris@0
|
158 # to description if any
|
Chris@0
|
159 def full_description
|
Chris@0
|
160 full_description = description
|
Chris@0
|
161 full_description += "\n\n*Steps to reproduce:*\n\n#{steps_to_reproduce}" unless steps_to_reproduce.blank?
|
Chris@0
|
162 full_description += "\n\n*Additional information:*\n\n#{additional_information}" unless additional_information.blank?
|
Chris@0
|
163 full_description
|
Chris@0
|
164 end
|
Chris@0
|
165 end
|
Chris@0
|
166
|
Chris@0
|
167 class MantisBugNote < ActiveRecord::Base
|
Chris@0
|
168 set_table_name :mantis_bugnote_table
|
Chris@0
|
169 belongs_to :bug, :class_name => "MantisBug", :foreign_key => :bug_id
|
Chris@0
|
170 belongs_to :bug_note_text, :class_name => "MantisBugNoteText", :foreign_key => :bugnote_text_id
|
Chris@0
|
171 end
|
Chris@0
|
172
|
Chris@0
|
173 class MantisBugNoteText < ActiveRecord::Base
|
Chris@0
|
174 set_table_name :mantis_bugnote_text_table
|
Chris@0
|
175 end
|
Chris@0
|
176
|
Chris@0
|
177 class MantisBugFile < ActiveRecord::Base
|
Chris@0
|
178 set_table_name :mantis_bug_file_table
|
Chris@0
|
179
|
Chris@0
|
180 def size
|
Chris@0
|
181 filesize
|
Chris@0
|
182 end
|
Chris@0
|
183
|
Chris@0
|
184 def original_filename
|
Chris@0
|
185 MantisMigrate.encode(filename)
|
Chris@0
|
186 end
|
Chris@0
|
187
|
Chris@0
|
188 def content_type
|
Chris@0
|
189 file_type
|
Chris@0
|
190 end
|
Chris@0
|
191
|
Chris@0
|
192 def read(*args)
|
Chris@0
|
193 if @read_finished
|
Chris@0
|
194 nil
|
Chris@0
|
195 else
|
Chris@0
|
196 @read_finished = true
|
Chris@0
|
197 content
|
Chris@0
|
198 end
|
Chris@0
|
199 end
|
Chris@0
|
200 end
|
Chris@0
|
201
|
Chris@0
|
202 class MantisBugRelationship < ActiveRecord::Base
|
Chris@0
|
203 set_table_name :mantis_bug_relationship_table
|
Chris@0
|
204 end
|
Chris@0
|
205
|
Chris@0
|
206 class MantisBugMonitor < ActiveRecord::Base
|
Chris@0
|
207 set_table_name :mantis_bug_monitor_table
|
Chris@0
|
208 end
|
Chris@0
|
209
|
Chris@0
|
210 class MantisNews < ActiveRecord::Base
|
Chris@0
|
211 set_table_name :mantis_news_table
|
Chris@0
|
212 end
|
Chris@0
|
213
|
Chris@0
|
214 class MantisCustomField < ActiveRecord::Base
|
Chris@0
|
215 set_table_name :mantis_custom_field_table
|
Chris@0
|
216 set_inheritance_column :none
|
Chris@0
|
217 has_many :values, :class_name => "MantisCustomFieldString", :foreign_key => :field_id
|
Chris@0
|
218 has_many :projects, :class_name => "MantisCustomFieldProject", :foreign_key => :field_id
|
Chris@0
|
219
|
Chris@0
|
220 def format
|
Chris@0
|
221 read_attribute :type
|
Chris@0
|
222 end
|
Chris@0
|
223
|
Chris@0
|
224 def name
|
Chris@119
|
225 read_attribute(:name)[0..29]
|
Chris@0
|
226 end
|
Chris@0
|
227 end
|
Chris@0
|
228
|
Chris@0
|
229 class MantisCustomFieldProject < ActiveRecord::Base
|
Chris@0
|
230 set_table_name :mantis_custom_field_project_table
|
Chris@0
|
231 end
|
Chris@0
|
232
|
Chris@0
|
233 class MantisCustomFieldString < ActiveRecord::Base
|
Chris@0
|
234 set_table_name :mantis_custom_field_string_table
|
Chris@0
|
235 end
|
Chris@0
|
236
|
Chris@0
|
237
|
Chris@0
|
238 def self.migrate
|
Chris@0
|
239
|
Chris@0
|
240 # Users
|
Chris@0
|
241 print "Migrating users"
|
Chris@0
|
242 User.delete_all "login <> 'admin'"
|
Chris@0
|
243 users_map = {}
|
Chris@0
|
244 users_migrated = 0
|
Chris@0
|
245 MantisUser.find(:all).each do |user|
|
Chris@0
|
246 u = User.new :firstname => encode(user.firstname),
|
Chris@0
|
247 :lastname => encode(user.lastname),
|
Chris@0
|
248 :mail => user.email,
|
Chris@0
|
249 :last_login_on => user.last_visit
|
Chris@0
|
250 u.login = user.username
|
Chris@0
|
251 u.password = 'mantis'
|
Chris@0
|
252 u.status = User::STATUS_LOCKED if user.enabled != 1
|
Chris@0
|
253 u.admin = true if user.access_level == 90
|
Chris@0
|
254 next unless u.save!
|
Chris@0
|
255 users_migrated += 1
|
Chris@0
|
256 users_map[user.id] = u.id
|
Chris@0
|
257 print '.'
|
Chris@0
|
258 end
|
Chris@0
|
259 puts
|
Chris@0
|
260
|
Chris@0
|
261 # Projects
|
Chris@0
|
262 print "Migrating projects"
|
Chris@0
|
263 Project.destroy_all
|
Chris@0
|
264 projects_map = {}
|
Chris@0
|
265 versions_map = {}
|
Chris@0
|
266 categories_map = {}
|
Chris@0
|
267 MantisProject.find(:all).each do |project|
|
Chris@0
|
268 p = Project.new :name => encode(project.name),
|
Chris@0
|
269 :description => encode(project.description)
|
Chris@0
|
270 p.identifier = project.identifier
|
Chris@0
|
271 next unless p.save
|
Chris@0
|
272 projects_map[project.id] = p.id
|
Chris@0
|
273 p.enabled_module_names = ['issue_tracking', 'news', 'wiki']
|
Chris@0
|
274 p.trackers << TRACKER_BUG
|
Chris@0
|
275 p.trackers << TRACKER_FEATURE
|
Chris@0
|
276 print '.'
|
Chris@0
|
277
|
Chris@0
|
278 # Project members
|
Chris@0
|
279 project.members.each do |member|
|
Chris@0
|
280 m = Member.new :user => User.find_by_id(users_map[member.user_id]),
|
Chris@0
|
281 :roles => [ROLE_MAPPING[member.access_level] || DEFAULT_ROLE]
|
Chris@0
|
282 m.project = p
|
Chris@0
|
283 m.save
|
Chris@0
|
284 end
|
Chris@0
|
285
|
Chris@0
|
286 # Project versions
|
Chris@0
|
287 project.versions.each do |version|
|
Chris@0
|
288 v = Version.new :name => encode(version.version),
|
Chris@0
|
289 :description => encode(version.description),
|
Chris@210
|
290 :effective_date => (version.date_order ? version.date_order.to_date : nil)
|
Chris@0
|
291 v.project = p
|
Chris@0
|
292 v.save
|
Chris@0
|
293 versions_map[version.id] = v.id
|
Chris@0
|
294 end
|
Chris@0
|
295
|
Chris@0
|
296 # Project categories
|
Chris@0
|
297 project.categories.each do |category|
|
Chris@0
|
298 g = IssueCategory.new :name => category.category[0,30]
|
Chris@0
|
299 g.project = p
|
Chris@0
|
300 g.save
|
Chris@0
|
301 categories_map[category.category] = g.id
|
Chris@0
|
302 end
|
Chris@0
|
303 end
|
Chris@0
|
304 puts
|
Chris@0
|
305
|
Chris@0
|
306 # Bugs
|
Chris@0
|
307 print "Migrating bugs"
|
Chris@0
|
308 Issue.destroy_all
|
Chris@0
|
309 issues_map = {}
|
Chris@0
|
310 keep_bug_ids = (Issue.count == 0)
|
Chris@0
|
311 MantisBug.find_each(:batch_size => 200) do |bug|
|
Chris@0
|
312 next unless projects_map[bug.project_id] && users_map[bug.reporter_id]
|
Chris@0
|
313 i = Issue.new :project_id => projects_map[bug.project_id],
|
Chris@0
|
314 :subject => encode(bug.summary),
|
Chris@0
|
315 :description => encode(bug.bug_text.full_description),
|
Chris@0
|
316 :priority => PRIORITY_MAPPING[bug.priority] || DEFAULT_PRIORITY,
|
Chris@0
|
317 :created_on => bug.date_submitted,
|
Chris@0
|
318 :updated_on => bug.last_updated
|
Chris@0
|
319 i.author = User.find_by_id(users_map[bug.reporter_id])
|
Chris@0
|
320 i.category = IssueCategory.find_by_project_id_and_name(i.project_id, bug.category[0,30]) unless bug.category.blank?
|
Chris@0
|
321 i.fixed_version = Version.find_by_project_id_and_name(i.project_id, bug.fixed_in_version) unless bug.fixed_in_version.blank?
|
Chris@0
|
322 i.status = STATUS_MAPPING[bug.status] || DEFAULT_STATUS
|
Chris@0
|
323 i.tracker = (bug.severity == 10 ? TRACKER_FEATURE : TRACKER_BUG)
|
Chris@0
|
324 i.id = bug.id if keep_bug_ids
|
Chris@0
|
325 next unless i.save
|
Chris@0
|
326 issues_map[bug.id] = i.id
|
Chris@0
|
327 print '.'
|
Chris@0
|
328 STDOUT.flush
|
Chris@0
|
329
|
Chris@0
|
330 # Assignee
|
Chris@0
|
331 # Redmine checks that the assignee is a project member
|
Chris@0
|
332 if (bug.handler_id && users_map[bug.handler_id])
|
Chris@0
|
333 i.assigned_to = User.find_by_id(users_map[bug.handler_id])
|
Chris@0
|
334 i.save_with_validation(false)
|
Chris@0
|
335 end
|
Chris@0
|
336
|
Chris@0
|
337 # Bug notes
|
Chris@0
|
338 bug.bug_notes.each do |note|
|
Chris@0
|
339 next unless users_map[note.reporter_id]
|
Chris@0
|
340 n = Journal.new :notes => encode(note.bug_note_text.note),
|
Chris@0
|
341 :created_on => note.date_submitted
|
Chris@0
|
342 n.user = User.find_by_id(users_map[note.reporter_id])
|
Chris@0
|
343 n.journalized = i
|
Chris@0
|
344 n.save
|
Chris@0
|
345 end
|
Chris@0
|
346
|
Chris@0
|
347 # Bug files
|
Chris@0
|
348 bug.bug_files.each do |file|
|
Chris@0
|
349 a = Attachment.new :created_on => file.date_added
|
Chris@0
|
350 a.file = file
|
Chris@0
|
351 a.author = User.find :first
|
Chris@0
|
352 a.container = i
|
Chris@0
|
353 a.save
|
Chris@0
|
354 end
|
Chris@0
|
355
|
Chris@0
|
356 # Bug monitors
|
Chris@0
|
357 bug.bug_monitors.each do |monitor|
|
Chris@0
|
358 next unless users_map[monitor.user_id]
|
Chris@0
|
359 i.add_watcher(User.find_by_id(users_map[monitor.user_id]))
|
Chris@0
|
360 end
|
Chris@0
|
361 end
|
Chris@0
|
362
|
Chris@0
|
363 # update issue id sequence if needed (postgresql)
|
Chris@0
|
364 Issue.connection.reset_pk_sequence!(Issue.table_name) if Issue.connection.respond_to?('reset_pk_sequence!')
|
Chris@0
|
365 puts
|
Chris@0
|
366
|
Chris@0
|
367 # Bug relationships
|
Chris@0
|
368 print "Migrating bug relations"
|
Chris@0
|
369 MantisBugRelationship.find(:all).each do |relation|
|
Chris@0
|
370 next unless issues_map[relation.source_bug_id] && issues_map[relation.destination_bug_id]
|
Chris@0
|
371 r = IssueRelation.new :relation_type => RELATION_TYPE_MAPPING[relation.relationship_type]
|
Chris@0
|
372 r.issue_from = Issue.find_by_id(issues_map[relation.source_bug_id])
|
Chris@0
|
373 r.issue_to = Issue.find_by_id(issues_map[relation.destination_bug_id])
|
Chris@0
|
374 pp r unless r.save
|
Chris@0
|
375 print '.'
|
Chris@0
|
376 STDOUT.flush
|
Chris@0
|
377 end
|
Chris@0
|
378 puts
|
Chris@0
|
379
|
Chris@0
|
380 # News
|
Chris@0
|
381 print "Migrating news"
|
Chris@0
|
382 News.destroy_all
|
Chris@0
|
383 MantisNews.find(:all, :conditions => 'project_id > 0').each do |news|
|
Chris@0
|
384 next unless projects_map[news.project_id]
|
Chris@0
|
385 n = News.new :project_id => projects_map[news.project_id],
|
Chris@0
|
386 :title => encode(news.headline[0..59]),
|
Chris@0
|
387 :description => encode(news.body),
|
Chris@0
|
388 :created_on => news.date_posted
|
Chris@0
|
389 n.author = User.find_by_id(users_map[news.poster_id])
|
Chris@0
|
390 n.save
|
Chris@0
|
391 print '.'
|
Chris@0
|
392 STDOUT.flush
|
Chris@0
|
393 end
|
Chris@0
|
394 puts
|
Chris@0
|
395
|
Chris@0
|
396 # Custom fields
|
Chris@0
|
397 print "Migrating custom fields"
|
Chris@0
|
398 IssueCustomField.destroy_all
|
Chris@0
|
399 MantisCustomField.find(:all).each do |field|
|
Chris@0
|
400 f = IssueCustomField.new :name => field.name[0..29],
|
Chris@0
|
401 :field_format => CUSTOM_FIELD_TYPE_MAPPING[field.format],
|
Chris@0
|
402 :min_length => field.length_min,
|
Chris@0
|
403 :max_length => field.length_max,
|
Chris@0
|
404 :regexp => field.valid_regexp,
|
Chris@0
|
405 :possible_values => field.possible_values.split('|'),
|
Chris@0
|
406 :is_required => field.require_report?
|
Chris@0
|
407 next unless f.save
|
Chris@0
|
408 print '.'
|
Chris@0
|
409 STDOUT.flush
|
Chris@0
|
410 # Trackers association
|
Chris@0
|
411 f.trackers = Tracker.find :all
|
Chris@0
|
412
|
Chris@0
|
413 # Projects association
|
Chris@0
|
414 field.projects.each do |project|
|
Chris@0
|
415 f.projects << Project.find_by_id(projects_map[project.project_id]) if projects_map[project.project_id]
|
Chris@0
|
416 end
|
Chris@0
|
417
|
Chris@0
|
418 # Values
|
Chris@0
|
419 field.values.each do |value|
|
Chris@0
|
420 v = CustomValue.new :custom_field_id => f.id,
|
Chris@0
|
421 :value => value.value
|
Chris@0
|
422 v.customized = Issue.find_by_id(issues_map[value.bug_id]) if issues_map[value.bug_id]
|
Chris@0
|
423 v.save
|
Chris@0
|
424 end unless f.new_record?
|
Chris@0
|
425 end
|
Chris@0
|
426 puts
|
Chris@0
|
427
|
Chris@0
|
428 puts
|
Chris@0
|
429 puts "Users: #{users_migrated}/#{MantisUser.count}"
|
Chris@0
|
430 puts "Projects: #{Project.count}/#{MantisProject.count}"
|
Chris@0
|
431 puts "Memberships: #{Member.count}/#{MantisProjectUser.count}"
|
Chris@0
|
432 puts "Versions: #{Version.count}/#{MantisVersion.count}"
|
Chris@0
|
433 puts "Categories: #{IssueCategory.count}/#{MantisCategory.count}"
|
Chris@0
|
434 puts "Bugs: #{Issue.count}/#{MantisBug.count}"
|
Chris@0
|
435 puts "Bug notes: #{Journal.count}/#{MantisBugNote.count}"
|
Chris@0
|
436 puts "Bug files: #{Attachment.count}/#{MantisBugFile.count}"
|
Chris@0
|
437 puts "Bug relations: #{IssueRelation.count}/#{MantisBugRelationship.count}"
|
Chris@0
|
438 puts "Bug monitors: #{Watcher.count}/#{MantisBugMonitor.count}"
|
Chris@0
|
439 puts "News: #{News.count}/#{MantisNews.count}"
|
Chris@0
|
440 puts "Custom fields: #{IssueCustomField.count}/#{MantisCustomField.count}"
|
Chris@0
|
441 end
|
Chris@0
|
442
|
Chris@0
|
443 def self.encoding(charset)
|
Chris@0
|
444 @ic = Iconv.new('UTF-8', charset)
|
Chris@0
|
445 rescue Iconv::InvalidEncoding
|
Chris@0
|
446 return false
|
Chris@0
|
447 end
|
Chris@0
|
448
|
Chris@0
|
449 def self.establish_connection(params)
|
Chris@0
|
450 constants.each do |const|
|
Chris@0
|
451 klass = const_get(const)
|
Chris@0
|
452 next unless klass.respond_to? 'establish_connection'
|
Chris@0
|
453 klass.establish_connection params
|
Chris@0
|
454 end
|
Chris@0
|
455 end
|
Chris@0
|
456
|
Chris@0
|
457 def self.encode(text)
|
Chris@0
|
458 @ic.iconv text
|
Chris@0
|
459 rescue
|
Chris@0
|
460 text
|
Chris@0
|
461 end
|
Chris@0
|
462 end
|
Chris@0
|
463
|
Chris@0
|
464 puts
|
Chris@0
|
465 if Redmine::DefaultData::Loader.no_data?
|
Chris@0
|
466 puts "Redmine configuration need to be loaded before importing data."
|
Chris@0
|
467 puts "Please, run this first:"
|
Chris@0
|
468 puts
|
Chris@0
|
469 puts " rake redmine:load_default_data RAILS_ENV=\"#{ENV['RAILS_ENV']}\""
|
Chris@0
|
470 exit
|
Chris@0
|
471 end
|
Chris@0
|
472
|
Chris@0
|
473 puts "WARNING: Your Redmine data will be deleted during this process."
|
Chris@0
|
474 print "Are you sure you want to continue ? [y/N] "
|
Chris@0
|
475 STDOUT.flush
|
Chris@0
|
476 break unless STDIN.gets.match(/^y$/i)
|
Chris@0
|
477
|
Chris@0
|
478 # Default Mantis database settings
|
Chris@0
|
479 db_params = {:adapter => 'mysql',
|
Chris@0
|
480 :database => 'bugtracker',
|
Chris@0
|
481 :host => 'localhost',
|
Chris@0
|
482 :username => 'root',
|
Chris@0
|
483 :password => '' }
|
Chris@0
|
484
|
Chris@0
|
485 puts
|
Chris@0
|
486 puts "Please enter settings for your Mantis database"
|
Chris@0
|
487 [:adapter, :host, :database, :username, :password].each do |param|
|
Chris@0
|
488 print "#{param} [#{db_params[param]}]: "
|
Chris@0
|
489 value = STDIN.gets.chomp!
|
Chris@0
|
490 db_params[param] = value unless value.blank?
|
Chris@0
|
491 end
|
Chris@0
|
492
|
Chris@0
|
493 while true
|
Chris@0
|
494 print "encoding [UTF-8]: "
|
Chris@0
|
495 STDOUT.flush
|
Chris@0
|
496 encoding = STDIN.gets.chomp!
|
Chris@0
|
497 encoding = 'UTF-8' if encoding.blank?
|
Chris@0
|
498 break if MantisMigrate.encoding encoding
|
Chris@0
|
499 puts "Invalid encoding!"
|
Chris@0
|
500 end
|
Chris@0
|
501 puts
|
Chris@0
|
502
|
Chris@0
|
503 # Make sure bugs can refer bugs in other projects
|
Chris@0
|
504 Setting.cross_project_issue_relations = 1 if Setting.respond_to? 'cross_project_issue_relations'
|
Chris@0
|
505
|
Chris@0
|
506 # Turn off email notifications
|
Chris@0
|
507 Setting.notified_events = []
|
Chris@0
|
508
|
Chris@0
|
509 MantisMigrate.establish_connection db_params
|
Chris@0
|
510 MantisMigrate.migrate
|
Chris@0
|
511 end
|
Chris@0
|
512 end
|