migrate_from_trac.rake.txt

Craig Rodrigues, 2013-08-01 09:52

Download (3.74 KB)

 
1
Index: migrate_from_trac.rake
2
===================================================================
3
--- migrate_from_trac.rake	(revision 12072)
4
+++ migrate_from_trac.rake	(working copy)
5
@@ -261,7 +261,13 @@
6
           u.password = 'trac'
7
           u.admin = true if TracPermission.find_by_username_and_action(username, 'admin')
8
           # finally, a default user is used if the new user is not valid
9
-          u = User.first unless u.save
10
+          unless u.save
11
+             u.errors.full_messages.each do |msg|
12
+               print "\nERROR: ",msg,"\n"
13
+             end
14
+             print "ERROR: Skipping user.\n"
15
+             u = User.first
16
+          end
17
         end
18
         # Make sure user is a member of the project
19
         if project_member && !u.member_of?(@target_project)
20
@@ -399,7 +405,13 @@
21
         STDOUT.flush
22
           c = IssueCategory.new :project => @target_project,
23
                                 :name => encode(component.name[0, limit_for(IssueCategory, 'name')])
24
-        next unless c.save
25
+        unless c.save
26
+          c.errors.full_messages.each do |msg|
27
+            print "\nERROR: ",msg,"\n"
28
+          end
29
+          print "Error: Skipping category.\n"
30
+          next
31
+        end
32
         issues_category_map[component.name] = c
33
         migrated_components += 1
34
         end
35
@@ -417,7 +429,12 @@
36
           p.content.text = milestone.description.to_s
37
           p.content.author = find_or_create_user('trac')
38
           p.content.comments = 'Milestone'
39
-          p.save
40
+          unless p.save
41
+            p.errors.full_messages.each do |msg|
42
+              print "\nERROR: ",msg,"\n"
43
+            end
44
+            print "ERROR: Error saving wiki page.\n"
45
+          end
46
 
47
           v = Version.new :project => @target_project,
48
                           :name => encode(milestone.name[0, limit_for(Version, 'name')]),
49
@@ -425,7 +442,13 @@
50
                           :wiki_page_title => milestone.name.to_s,
51
                           :effective_date => milestone.completed
52
 
53
-          next unless v.save
54
+          unless v.save
55
+            v.errors.full_messages.each do |msg|
56
+              print "\nERROR: ",msg,"\n"
57
+            end
58
+            print "ERROR: Skipping version.\n"
59
+            next
60
+          end
61
           version_map[milestone.name] = v
62
           migrated_milestones += 1
63
         end
64
@@ -480,7 +503,14 @@
65
           i.status = STATUS_MAPPING[ticket.status] || DEFAULT_STATUS
66
           i.tracker = TRACKER_MAPPING[ticket.ticket_type] || DEFAULT_TRACKER
67
           i.id = ticket.id unless Issue.exists?(ticket.id)
68
-          next unless Time.fake(ticket.changetime) { i.save }
69
+          unless i.save
70
+            i.errors.full_messages.each do |msg|
71
+              print "\nERROR: ",msg,"\n"
72
+            end
73
+            print "ERROR: Error saving issue.\n"
74
+            next
75
+          end
76
+
77
           TICKET_MAP[ticket.id] = i.id
78
           migrated_tickets += 1
79
 
80
@@ -487,7 +517,12 @@
81
           # Owner
82
             unless ticket.owner.blank?
83
               i.assigned_to = find_or_create_user(ticket.owner, true)
84
-              Time.fake(ticket.changetime) { i.save }
85
+              unless i.save
86
+                i.errors.full_messages.each do |msg|
87
+                  print "\nERROR: ",msg,"\n"
88
+                end
89
+                print "ERROR: Error saving issue.\n"
90
+              end
91
             end
92
 
93
           # Comments and status/resolution changes
94
@@ -589,6 +624,11 @@
95
             page.content.text = convert_wiki_text(page.content.text)
96
             Time.fake(page.content.updated_on) { page.content.save }
97
           end
98
+        else
99
+          wiki.errors.full_messages.each do |msg|
100
+            print "\nERROR: ",msg,"\n"
101
+          end
102
+          print "ERROR: Error saving wiki.\n"
103
         end
104
         puts
105