-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmigrate_from_mantis.rake
736 lines (649 loc) · 27.6 KB
/
migrate_from_mantis.rake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
# encoding: UTF-8
# Redmine - project management software
# Copyright (C) 2006-2012 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
desc 'Mantis migration script'
require 'active_record'
require 'iconv'
require 'pp'
require 'debugger'
namespace :redmine do
task :migrate_from_mantis => :environment do
module MantisMigrate
# Modified
#DEFAULT_STATUS = IssueStatus.default
#assigned_status = IssueStatus.find_by_position(2)
#resolved_status = IssueStatus.find_by_position(3)
#feedback_status = IssueStatus.find_by_position(4)
#closed_status = IssueStatus.find :first, :conditions => { :is_closed => true }
#STATUS_MAPPING = {10 => DEFAULT_STATUS, # new
# 20 => feedback_status, # feedback
# 30 => DEFAULT_STATUS, # acknowledged
# 40 => DEFAULT_STATUS, # confirmed
# 50 => assigned_status, # assigned
# 80 => resolved_status, # resolved
# 90 => closed_status # closed
# }
DEFAULT_STATUS = IssueStatus.default
feedback_status = IssueStatus.find_by_position(2)
acknowledged_status = IssueStatus.find_by_position(3)
confirmed_status = IssueStatus.find_by_position(4)
developer_status = IssueStatus.find_by_position(5)
assigned_status = IssueStatus.find_by_position(6)
corrected_status = IssueStatus.find_by_position(7)
tested_status = IssueStatus.find_by_position(8)
validated_status = IssueStatus.find_by_position(9)
interrupted_status = IssueStatus.find_by_position(12)
aguardando_status = IssueStatus.find_by_position(13)
resolved_status = IssueStatus.find_by_position(10)
closed_status = IssueStatus.find_by_position(11)
STATUS_MAPPING = {10 => DEFAULT_STATUS, # new
20 => feedback_status, # feedback
30 => acknowledged_status, # acknowledged
40 => confirmed_status, # confirmed
45 => developer_status, # developer
50 => assigned_status, # assigned
60 => corrected_status, # corrected
61 => tested_status, # tested
62 => validated_status, # validated
63 => interrupted_status, # interrupted
64 => aguardando_status, # aguardando
80 => resolved_status, # resolved
90 => closed_status # closed
}
# Priority modified
#DEFAULT_PRIORITY = priorities[2]
#PRIORITY_MAPPING = {10 => priorities[1], # none
# 20 => priorities[1], # low
# 30 => priorities[2], # normal
# 40 => priorities[3], # high
# 50 => priorities[4], # urgent
# 60 => priorities[5] # immediate
priorities = IssuePriority.all
DEFAULT_PRIORITY = priorities[1]
PRIORITY_MAPPING = {10 => priorities[0], # none
20 => priorities[0], # low
30 => priorities[1], # normal
40 => priorities[2], # high
50 => priorities[3], # urgent
60 => priorities[4] # immediate
}
# Modified Tracker
#TRACKER_FUNCIONALIDADE = Tracker.find_by_position(1)
#TRACKER_BUG = Tracker.find_by_position(2)
corretiva_bug = Tracker.find_by_position(2)
especfunc_bug = Tracker.find_by_position(17)
funcionalidade_bug = Tracker.find_by_position(1)
servico_bug = Tracker.find_by_position(7)
adaptativa_bug = Tracker.find_by_position(3)
nc_bug = Tracker.find_by_position(6)
perfectiva_bug = Tracker.find_by_position(5)
preventiva_bug = Tracker.find_by_position(4)
estudo_bug = Tracker.find_by_position(8)
statusreport_bug = Tracker.find_by_position(9)
processo_bug = Tracker.find_by_position(14)
DEFAULT_TRACKER = Tracker.find_by_position(12)
TRACKER_MAPPING = {'Corretiva' => corretiva_bug, #corretiva
'Especificação Funcional' => especfunc_bug, #especificação funcional
'Nova Função' => funcionalidade_bug, #funcionalidade
'Serviço' => servico_bug, #serviço
'Adaptativa' => adaptativa_bug, #adaptativa
'Não-Conformidade' => nc_bug, #não conformidade
'Perfectiva' => perfectiva_bug, #perfectiva
'Preventiva' => preventiva_bug, #preventiva
'Estudo' => estudo_bug, #estudo
'Status Report' => statusreport_bug, #status report
'Processo' => processo_bug #processo
}
# Modified Role
#roles = Role.find(:all, :conditions => {:builtin => 0}, :order => 'position ASC')
#manager_role = roles[0]
#developer_role = roles[1]
#DEFAULT_ROLE = roles.last
#ROLE_MAPPING = {10 => DEFAULT_ROLE, # viewer
# 25 => DEFAULT_ROLE, # reporter
# 40 => DEFAULT_ROLE, # updater
# 55 => developer_role, # developer
# 70 => manager_role, # manager
# 90 => manager_role # administrator
# }
reporter_role = Role.find_by_position(6)
developer_role = Role.find_by_position(5)
analista_role = Role.find_by_position(4)
manager_role = Role.find_by_position(3)
administrator_role = Role.find_by_position(7)
DEFAULT_ROLE = Role.find_by_position(1)
ROLE_MAPPING = {10 => DEFAULT_ROLE, # viewer
25 => reporter_role, # reporter
40 => DEFAULT_ROLE, # updater
55 => developer_role, # developer
60 => analista_role, # analista
70 => manager_role, # manager
90 => administrator_role # administrator
}
CUSTOM_FIELD_TYPE_MAPPING = {0 => 'string', # String
1 => 'int', # Numeric
2 => 'int', # Float
3 => 'list', # Enumeration
4 => 'string', # Email
5 => 'bool', # Checkbox
6 => 'list', # List
7 => 'list', # Multiselection list
8 => 'date', # Date
}
RELATION_TYPE_MAPPING = {1 => IssueRelation::TYPE_RELATES, # related to
2 => IssueRelation::TYPE_RELATES, # parent of
3 => IssueRelation::TYPE_RELATES, # child of
0 => IssueRelation::TYPE_DUPLICATES, # duplicate of
4 => IssueRelation::TYPE_DUPLICATES # has duplicate
}
FIELD_NAME_MAPPING = {"Data Início Prevista" => 'attr', #attributes
"Data Término Prevista" => 'attr', #attributes
"project_id" => 'attr', #attributes
"status" => 'attr', #attributes
"category" => 'attr', #attributes
"handler_id" => 'attr', #attributes
"severity" => 'attr', #attributes
"fixed_in_version" => 'attr' #attributes
}
ATTRIBUTES_MAPPING = {"Data Início Prevista" => "due_date", #due date
"Data Término Prevista" => "start_date", #start date
"project_id" => "project_id", #project
"status" => "status_id", #status
"category" => "tracker_id", #tracker
"handler_id" => "assigned_to_id", #assingned
"severity" => "priority_id", #priority
"fixed_in_version" => "fixed_version_id" #fixed version
}
class MantisUser < ActiveRecord::Base
self.table_name = :m_user_t
def firstname
@firstname = realname.blank? ? username : realname.split.first[0..29]
@firstname
end
def lastname
@lastname = realname.blank? ? '-' : realname.split[1..-1].join(' ')[0..29]
@lastname = '-' if @lastname.blank?
@lastname
end
def email
if read_attribute(:email).match(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i) &&
!User.find_by_mail(read_attribute(:email))
@email = read_attribute(:email)
else
@email = "#{username}@foo.bar"
end
end
# Modified added .tr('_', '.')
def username
read_attribute(:username)[0..29].gsub(/[^a-zA-Z0-9_\-@\.]/, '-').tr('_', '.')
end
end
class MantisProject < ActiveRecord::Base
self.table_name = :m_project_t
has_many :versions, :class_name => "MantisVersion", :foreign_key => :project_id
#has_many :categories, :class_name => "MantisCategory", :foreign_key => :project_id
has_many :news, :class_name => "MantisNews", :foreign_key => :project_id
has_many :members, :class_name => "MantisProjectUser", :foreign_key => :project_id
# Modified read_attribute(:name).gsub(/[^a-z0-9\-]+/, '-').slice(0, Project::IDENTIFIER_MAX_LENGTH)
def identifier
read_attribute(:name).downcase.gsub(/[^a-z0-9\-]+/, '')
end
end
class MantisProjectHierarchy < ActiveRecord::Base
set_table_name :m_project_hierarchy_t
end
class MantisVersion < ActiveRecord::Base
self.table_name = :m_project_version_t
def version
read_attribute(:version)[0..29]
end
def description
read_attribute(:description)[0..254]
end
end
class MantisCategory < ActiveRecord::Base
set_table_name :m_category_t
#has_many :bugs, class_name => "MantisCategory", :foreign_key => :category_id
def name
read_attribute(:name).slice(0,30)
end
end
class MantisProjectUser < ActiveRecord::Base
self.table_name = :m_project_user_list_t
end
class MantisBug < ActiveRecord::Base
self.table_name = :m_bug_t
belongs_to :bug_text, :class_name => "MantisBugText", :foreign_key => :bug_text_id
belongs_to :category, :class_name => "MantisCategory", :foreign_key => :category_id
has_many :bug_notes, :class_name => "MantisBugNote", :foreign_key => :bug_id
has_many :bug_files, :class_name => "MantisBugFile", :foreign_key => :bug_id
has_many :bug_monitors, :class_name => "MantisBugMonitor", :foreign_key => :bug_id
has_many :bug_history, :class_name => "MantisBugHistory", :foreign_key => :bug_id
end
class MantisBugText < ActiveRecord::Base
self.table_name = :m_bug_text_t
# Adds Mantis steps_to_reproduce and additional_information fields
# to description if any
def full_description
full_description = description
full_description += "\n\n*Steps to reproduce:*\n\n#{steps_to_reproduce}" unless steps_to_reproduce.blank?
full_description += "\n\n*Additional information:*\n\n#{additional_information}" unless additional_information.blank?
full_description
end
end
class MantisBugNote < ActiveRecord::Base
self.table_name = :m_bugnote_t
belongs_to :bug, :class_name => "MantisBug", :foreign_key => :bug_id
belongs_to :bug_note_text, :class_name => "MantisBugNoteText", :foreign_key => :bugnote_text_id
end
class MantisBugNoteText < ActiveRecord::Base
self.table_name = :m_bugnote_text_t
end
class MantisBugHistory < ActiveRecord::Base
set_table_name :m_bug_history_t
set_inheritance_column :none
belongs_to :bug, :class_name => "MantisBug", :foreign_key => :bug_id
attr_accessible :name, :old_value, :new_value
end
class MantisBugFile < ActiveRecord::Base
self.table_name = :m_bug_file_t
def size
filesize
end
def original_filename
MantisMigrate.encode(filename)
end
def content_type
file_type
end
def read(*args)
if @read_finished
nil
else
@read_finished = true
content
end
end
end
class MantisBugRelationship < ActiveRecord::Base
self.table_name = :m_bug_relationship_t
end
class MantisBugMonitor < ActiveRecord::Base
self.table_name = :m_bug_monitor_t
end
class MantisNews < ActiveRecord::Base
self.table_name = :m_news_t
end
class MantisCustomField < ActiveRecord::Base
self.table_name = :m_custom_field_t
set_inheritance_column :none
has_many :values, :class_name => "MantisCustomFieldString", :foreign_key => :field_id
has_many :projects, :class_name => "MantisCustomFieldProject", :foreign_key => :field_id
def format
read_attribute :type
end
def name
read_attribute(:name)[0..29]
end
end
class MantisCustomFieldProject < ActiveRecord::Base
self.table_name = :m_custom_field_project_t
end
class MantisCustomFieldString < ActiveRecord::Base
self.table_name = :m_custom_field_string_t
end
def self.mantis_date_convert(time_stamp)
DateTime.strptime(time_stamp.to_s, "%s") unless time_stamp.to_s.empty?
end
def self.save_journal_detail(n, jd)
if jd.valid?
n.save!
jd.journal_id = n.id
jd.save
end
end
def self.migrate
# Users
print "Migrating users"
User.delete_all "login <> 'admin'"
users_map = {}
users_migrated = 0
MantisUser.find(:all).each do |user|
u = User.new :firstname => encode(user.firstname),
:lastname => encode(user.lastname),
:mail => user.email,
:last_login_on => user.last_visit
u.login = user.username
u.password = 'redmine12345'
u.language = 'pt-BR'
u.status = User::STATUS_LOCKED if user.enabled != 1
u.admin = true if user.access_level == 90
next unless u.save!
users_migrated += 1
users_map[user.id] = u.id
print '.'
STDOUT.flush
end
puts
# Projects
print "Migrating projects"
Project.destroy_all
projects_map = {}
versions_map = {}
#categories_map = {}
MantisProject.find(:all).each do |project|
p = Project.new :name => encode(project.name),
:description => encode(project.description)
p.identifier = project.identifier
p.is_public = 0
next unless p.save
projects_map[project.id] = p.id
p.enabled_module_names = ['issue_tracking', 'news', 'wiki']
#p.trackers << TRACKER_BUG unless p.trackers.include?(TRACKER_BUG)
#p.trackers << TRACKER_FEATURE unless p.trackers.include?(TRACKER_FEATURE)
p.save
print '.'
STDOUT.flush
# Project members
project.members.each do |member|
m = Member.new :user => User.find_by_id(users_map[member.user_id]),
:roles => [ROLE_MAPPING[member.access_level] || DEFAULT_ROLE]
m.project = p
m.save
end
# Project versions
project.versions.each do |version|
v = Version.new :name => encode(version.version),
:description => encode(version.description),
:effective_date => mantis_date_convert(version.date_order).to_date
v.project = p
v.save
versions_map[version.id] = v.id
end
# Project categories
#project.categories.each do |category|
# g = Tracker.new :name => TRACKER_MAPPING[category.name] || DEFAULT_TRACKER
# g = IssueCategory.new :name => category.name[0,30]
# g.project = p
# g.save
# categories_map[category.category] = g.id
# p categories_map
# puts "\n"
#end
end
puts
# Project Hierarchy
print "Making Project Hierarchy"
MantisProjectHierarchy.find(:all).each do |link|
next unless p = Project.find_by_id(projects_map[link.child_id])
p.set_parent!(projects_map[link.parent_id])
print '.'
end
puts
# Bugs
print "Migrating bugs"
Issue.destroy_all
issues_map = {}
journals_map = {}
#keep_bug_ids = (Issue.count == 1)
MantisBug.find_each(:batch_size => 200) do |bug|
begin
next unless projects_map[bug.project_id] && users_map[bug.reporter_id]
i = Issue.new :project_id => projects_map[bug.project_id],
:subject => encode(bug.summary),
:description => encode(bug.bug_text.full_description),
:priority => PRIORITY_MAPPING[bug.priority] || DEFAULT_PRIORITY,
:created_on => mantis_date_convert(bug.date_submitted),
:updated_on => mantis_date_convert(bug.last_updated),
:start_date => mantis_date_convert(bug.date_submitted)
#:tracker_id => TRACKER_MAPPING[bug.category.name] || DEFAULT_TRACKER
i.author = User.find_by_id(users_map[bug.reporter_id])
i.fixed_version = Version.find_by_project_id_and_name(i.project_id, bug.fixed_in_version) unless bug.fixed_in_version.blank?
i.status = STATUS_MAPPING[bug.status] || DEFAULT_STATUS
i.done_ratio = (i.status_id == 5 ? 100 : 0)
i.tracker = TRACKER_MAPPING[bug.category.name] || DEFAULT_TRACKER
#i.tracker = (bug.severity == 10 ? TRACKER_FEATURE : TRACKER_BUG)
i.is_private = (i.tracker == 5 ? 1 : 0)
i.id = bug.id # if keep_bug_ids
next unless i.save
issues_map[bug.id] = i.id
print '.'
STDOUT.flush
# Assignee
# Redmine checks that the assignee is a project member
if (bug.handler_id && users_map[bug.handler_id])
i.assigned_to = User.find_by_id(users_map[bug.handler_id])
i.save(:validate => false)
end
# Bug notes
#bug.bug_notes.each do |note|
#begin
#next unless users_map[note.reporter_id]
#n = Journal.new :notes => encode(note.bug_note_text.note),
#:created_on => mantis_date_convert(note.date_submitted)
#n.user = User.find_by_id(users_map[note.reporter_id])
#n.journalized = i
#n.private_notes = (note.view_state == 50 ? 1 : 0)
#n.save
#rescue
#print 'note error'
#print note.id
#end
#end
#Bug history
bug.bug_history.each do |history|
begin
next unless users_map[history.user_id]
n = Journal.new :created_on => mantis_date_convert(history.date_modified)
n.user = User.find_by_id(users_map[history.user_id])
n.journalized = i
if history.type == 0 and FIELD_NAME_MAPPING[history.field_name] and ATTRIBUTES_MAPPING[history.field_name]
n.notes = ""
jd = JournalDetail.new :prop_key => ATTRIBUTES_MAPPING[history.field_name],
:property => FIELD_NAME_MAPPING[history.field_name]
if history.field_name == "Data Início Prevista" or history.field_name == "Data Término Prevista"
jd.old_value = mantis_date_convert(history.old_value)
jd.value = mantis_date_convert(history.new_value)
save_journal_detail(n, jd)
elsif history.field_name == "status"
jd.old_value = STATUS_MAPPING[history.old_value.to_i]
jd.value = STATUS_MAPPING[history.new_value.to_i]
save_journal_detail(n, jd)
elsif history.field_name == "handler_id"
jd.old_value = (User.exists? users_map[history.old_value.to_i]) ? users_map[history.old_value.to_i].to_i : 1
jd.value = (User.exists? users_map[history.new_value.to_i]) ? users_map[history.new_value.to_i].to_i : 1
save_journal_detail(n, jd)
else
jd.old_value = history.old_value.gsub('(', '').gsub(')', '')
jd.value = history.new_value.gsub('(', '').gsub(')', '')
save_journal_detail(n, jd)
end
elsif history.type == 2
bug_note = MantisBugNote.find_by_id(history.old_value)
if bug_note
n.notes = encode(bug_note.bug_note_text.note)
n.private_notes = (bug_note.view_state == 50 ? 1 : 0)
n.save!
end
end
rescue Exception => e
debugger
print "history error"
print history.id
end
end
# Bug files
bug.bug_files.each do |file|
begin
a = Attachment.new :created_on => mantis_date_convert(file.date_added)
a.file = file
a.author = User.find :first
a.container = i
a.save
rescue
print 'file error'
print file.id
end
end
# Bug monitors
bug.bug_monitors.each do |monitor|
next unless users_map[monitor.user_id]
i.add_watcher(User.find_by_id(users_map[monitor.user_id]))
end
rescue
print "bug error"
print bug.id
print "\n"
end
end
# update issue id sequence if needed (postgresql)
Issue.connection.reset_pk_sequence!(Issue.table_name) if Issue.connection.respond_to?('reset_pk_sequence!')
puts
# Bug relationships
print "Migrating bug relations"
MantisBugRelationship.find(:all).each do |relation|
next unless issues_map[relation.source_bug_id] && issues_map[relation.destination_bug_id]
r = IssueRelation.new :relation_type => RELATION_TYPE_MAPPING[relation.relationship_type]
r.issue_from = Issue.find_by_id(issues_map[relation.source_bug_id])
r.issue_to = Issue.find_by_id(issues_map[relation.destination_bug_id])
pp r unless r.save
print '.'
STDOUT.flush
end
puts
# News
print "Migrating news"
News.destroy_all
MantisNews.find(:all, :conditions => 'project_id > 0').each do |news|
next unless projects_map[news.project_id]
n = News.new :project_id => projects_map[news.project_id],
:title => encode(news.headline[0..59]),
:description => encode(news.body),
:created_on => mantis_date_convert(news.date_posted)
n.author = User.find_by_id(users_map[news.poster_id])
n.save
print '.'
STDOUT.flush
end
puts
# Custom fields
print "Migrating custom fields"
IssueCustomField.destroy_all
MantisCustomField.find(:all).each do |field|
f = IssueCustomField.new :name => field.name[0..29],
:field_format => CUSTOM_FIELD_TYPE_MAPPING[field.format],
:min_length => field.length_min,
:max_length => field.length_max,
:regexp => field.valid_regexp,
:possible_values => field.possible_values.split('|'),
:is_required => field.require_report?
next if (field.name[0..29] == "Data Início Prevista" or field.name[0..29] == "Data Término Prevista")
next unless f.save
print '.'
STDOUT.flush
# Trackers association
f.trackers = Tracker.find :all
# Projects association
field.projects.each do |project|
f.projects << Project.find_by_id(projects_map[project.project_id]) if projects_map[project.project_id]
end
# Values
field.values.each do |value|
v = CustomValue.new :custom_field_id => f.id,
:value => value.value
if IssueCustomField.find(f.id).field_format == CUSTOM_FIELD_TYPE_MAPPING[8]
v.value = mantis_date_convert(v.value) unless v.value.empty?
end
v.customized = Issue.find_by_id(issues_map[value.bug_id]) if issues_map[value.bug_id]
v.save
end unless f.new_record?
end
puts
puts
puts "Users: #{users_migrated}/#{MantisUser.count}"
puts "Projects: #{Project.count}/#{MantisProject.count}"
puts "Memberships: #{Member.count}/#{MantisProjectUser.count}"
puts "Versions: #{Version.count}/#{MantisVersion.count}"
puts "Categories: #{IssueCategory.count}/#{MantisCategory.count}"
puts "Bugs: #{Issue.count}/#{MantisBug.count}"
puts "Bug notes: #{Journal.count}/#{MantisBugNote.count}"
puts "Bug files: #{Attachment.count}/#{MantisBugFile.count}"
puts "Bug relations: #{IssueRelation.count}/#{MantisBugRelationship.count}"
puts "Bug monitors: #{Watcher.count}/#{MantisBugMonitor.count}"
puts "News: #{News.count}/#{MantisNews.count}"
puts "Custom fields: #{IssueCustomField.count}/#{MantisCustomField.count}"
end
def self.encoding(charset)
@ic = Iconv.new('UTF-8', charset)
rescue Iconv::InvalidEncoding
return false
end
def self.establish_connection(params)
constants.each do |const|
klass = const_get(const)
next unless klass.respond_to? 'establish_connection'
klass.establish_connection params
end
end
def self.encode(text)
@ic.iconv text
rescue
text
end
end
puts
if Redmine::DefaultData::Loader.no_data?
puts "Redmine configuration need to be loaded before importing data."
puts "Please, run this first:"
puts
puts " rake redmine:load_default_data RAILS_ENV=\"#{ENV['RAILS_ENV']}\""
exit
end
#puts "WARNING: Your Redmine data will be deleted during this process."
#print "Are you sure you want to continue ? [y/N] "
#STDOUT.flush
#break unless STDIN.gets.match(/^y$/i)
# Default Mantis database settings
db_params = {:adapter => 'mysql2',
:database => 'mantis',
:host => 'localhost',
:username => 'root',
:password => '' }
#puts
#puts "Please enter settings for your Mantis database"
#[:adapter, :host, :database, :username, :password].each do |param|
#print "#{param} [#{db_params[param]}]: "
#value = STDIN.gets.chomp!
#db_params[param] = value unless value.blank?
#end
#while true
# print "encoding [UTF-8]: "
# STDOUT.flush
# #encoding = STDIN.gets.chomp!
# encoding = 'UTF-8' #if encoding.blank?
# break if MantisMigrate.encoding encoding
# puts "Invalid encoding!"
# end
#puts
# Make sure bugs can refer bugs in other projects
Setting.cross_project_issue_relations = 1 if Setting.respond_to? 'cross_project_issue_relations'
# Turn off email notifications
Setting.notified_events = []
MantisMigrate.establish_connection db_params
MantisMigrate.migrate
end
end