Project

General

Profile

Patch #14567 ยป migrate_from_trac.rake.patch.txt

Craig Rodrigues, 2013-07-29 16:41

 
1
Index: migrate_from_trac.rake
2
===================================================================
3
--- migrate_from_trac.rake	(revision 12066)
4
+++ migrate_from_trac.rake	(working copy)
5
@@ -71,19 +71,24 @@
6
 
7
       class ::Time
8
         class << self
9
-          alias :real_now :now
10
-          def now
11
-            real_now - @fake_diff.to_i
12
+          def at2(time)
13
+            # In Trac ticket #6466, timestamps
14
+            # were changed from seconds since the epoch
15
+            # to microseconds since the epoch.  The
16
+            # Trac database version was bumped to 23 for this.
17
+            if TracMigrate.database_version > 22
18
+               Time.at(time / 1000000)
19
+            else
20
+               Time.at(time)
21
+            end
22
           end
23
-          def fake(time)
24
-            @fake_diff = real_now - time
25
-            res = yield
26
-            @fake_diff = 0
27
-           res
28
-          end
29
         end
30
       end
31
 
32
+      class TracSystem < ActiveRecord::Base
33
+        self.table_name = :system
34
+      end
35
+
36
       class TracComponent < ActiveRecord::Base
37
         self.table_name = :component
38
       end
39
@@ -93,7 +98,7 @@
40
         # If this attribute is set a milestone has a defined target timepoint
41
         def due
42
           if read_attribute(:due) && read_attribute(:due) > 0
43
-            Time.at(read_attribute(:due)).to_date
44
+            Time.at2(read_attribute(:due)).to_date
45
           else
46
             nil
47
           end
48
@@ -101,7 +106,7 @@
49
         # This is the real timepoint at which the milestone has finished.
50
         def completed
51
           if read_attribute(:completed) && read_attribute(:completed) > 0
52
-            Time.at(read_attribute(:completed)).to_date
53
+            Time.at2(read_attribute(:completed)).to_date
54
           else
55
             nil
56
           end
57
@@ -121,7 +126,9 @@
58
         self.table_name = :attachment
59
         set_inheritance_column :none
60
 
61
-        def time; Time.at(read_attribute(:time)) end
62
+        def time
63
+          Time.at2(read_attribute(:time))
64
+        end
65
 
66
         def original_filename
67
           filename
68
@@ -186,8 +193,13 @@
69
           read_attribute(:description).blank? ? summary : read_attribute(:description)
70
         end
71
 
72
-        def time; Time.at(read_attribute(:time)) end
73
-        def changetime; Time.at(read_attribute(:changetime)) end
74
+        def time
75
+            Time.at2(read_attribute(:time))
76
+        end
77
+
78
+        def changetime
79
+            Time.at2(read_attribute(:changetime))
80
+        end
81
       end
82
 
83
       class TracTicketChange < ActiveRecord::Base
84
@@ -198,7 +210,9 @@
85
           super.select {|column| column.name.to_s != 'field'}
86
         end
87
 
88
-        def time; Time.at(read_attribute(:time)) end
89
+        def time
90
+            Time.at2(read_attribute(:time))
91
+        end
92
       end
93
 
94
       TRAC_WIKI_PAGES = %w(InterMapTxt InterTrac InterWiki RecentChanges SandBox TracAccessibility TracAdmin TracBackup TracBrowser TracCgi TracChangeset \
95
@@ -222,7 +236,9 @@
96
           TracMigrate::TracAttachment.all(:conditions => ["type = 'wiki' AND id = ?", self.id.to_s])
97
         end
98
 
99
-        def time; Time.at(read_attribute(:time)) end
100
+        def time
101
+          Time.at2(read_attribute(:time))
102
+        end
103
       end
104
 
105
       class TracPermission < ActiveRecord::Base
106
@@ -376,7 +392,8 @@
107
 
108
         # Quick database test
109
         TracComponent.count
110
-
111
+        lookup_database_version
112
+        print "Trac database version is: ", database_version, "\n" 
113
         migrated_components = 0
114
         migrated_milestones = 0
115
         migrated_tickets = 0
116
@@ -480,7 +497,7 @@
117
           i.status = STATUS_MAPPING[ticket.status] || DEFAULT_STATUS
118
           i.tracker = TRACKER_MAPPING[ticket.ticket_type] || DEFAULT_TRACKER
119
           i.id = ticket.id unless Issue.exists?(ticket.id)
120
-          next unless Time.fake(ticket.changetime) { i.save }
121
+          next unless i.save
122
           TICKET_MAP[ticket.id] = i.id
123
           migrated_tickets += 1
124
 
125
@@ -487,7 +504,7 @@
126
           # Owner
127
             unless ticket.owner.blank?
128
               i.assigned_to = find_or_create_user(ticket.owner, true)
129
-              Time.fake(ticket.changetime) { i.save }
130
+              i.save
131
             end
132
 
133
           # Comments and status/resolution changes
134
@@ -564,7 +581,7 @@
135
             p.content.text = page.text
136
             p.content.author = find_or_create_user(page.author) unless page.author.blank? || page.author == 'trac'
137
             p.content.comments = page.comment
138
-            Time.fake(page.time) { p.new_record? ? p.save : p.content.save }
139
+            p.new_record? ? p.save : p.content.save
140
 
141
             next if p.content.new_record?
142
             migrated_wiki_edits += 1
143
@@ -587,7 +604,7 @@
144
           wiki.reload
145
           wiki.pages.each do |page|
146
             page.content.text = convert_wiki_text(page.content.text)
147
-            Time.fake(page.content.updated_on) { page.content.save }
148
+            page.content.save
149
           end
150
         end
151
         puts
152
@@ -610,6 +627,15 @@
153
         @charset = charset
154
       end
155
 
156
+      def self.lookup_database_version
157
+        f = TracSystem.find_by_name("database_version")
158
+        @@database_version = f.value.to_i
159
+      end
160
+
161
+      def self.database_version
162
+        @@database_version
163
+      end
164
+
165
       def self.set_trac_directory(path)
166
         @@trac_directory = path
167
         raise "This directory doesn't exist!" unless File.directory?(path)
    (1-1/1)