71 |
71 |
|
72 |
72 |
class ::Time
|
73 |
73 |
class << self
|
74 |
|
alias :real_now :now
|
75 |
|
def now
|
76 |
|
real_now - @fake_diff.to_i
|
|
74 |
def at2(time)
|
|
75 |
# In Trac ticket #6466, timestamps
|
|
76 |
# were changed from seconds since the epoch
|
|
77 |
# to microseconds since the epoch. The
|
|
78 |
# Trac database version was bumped to 23 for this.
|
|
79 |
if TracMigrate.database_version > 22
|
|
80 |
Time.at(time / 1000000)
|
|
81 |
else
|
|
82 |
Time.at(time)
|
|
83 |
end
|
77 |
84 |
end
|
78 |
|
def fake(time)
|
79 |
|
@fake_diff = real_now - time
|
80 |
|
res = yield
|
81 |
|
@fake_diff = 0
|
82 |
|
res
|
83 |
|
end
|
84 |
85 |
end
|
85 |
86 |
end
|
86 |
87 |
|
|
88 |
class TracSystem < ActiveRecord::Base
|
|
89 |
self.table_name = :system
|
|
90 |
end
|
|
91 |
|
87 |
92 |
class TracComponent < ActiveRecord::Base
|
88 |
93 |
self.table_name = :component
|
89 |
94 |
end
|
... | ... | |
93 |
98 |
# If this attribute is set a milestone has a defined target timepoint
|
94 |
99 |
def due
|
95 |
100 |
if read_attribute(:due) && read_attribute(:due) > 0
|
96 |
|
Time.at(read_attribute(:due)).to_date
|
|
101 |
Time.at2(read_attribute(:due)).to_date
|
97 |
102 |
else
|
98 |
103 |
nil
|
99 |
104 |
end
|
... | ... | |
101 |
106 |
# This is the real timepoint at which the milestone has finished.
|
102 |
107 |
def completed
|
103 |
108 |
if read_attribute(:completed) && read_attribute(:completed) > 0
|
104 |
|
Time.at(read_attribute(:completed)).to_date
|
|
109 |
Time.at2(read_attribute(:completed)).to_date
|
105 |
110 |
else
|
106 |
111 |
nil
|
107 |
112 |
end
|
... | ... | |
121 |
126 |
self.table_name = :attachment
|
122 |
127 |
set_inheritance_column :none
|
123 |
128 |
|
124 |
|
def time; Time.at(read_attribute(:time)) end
|
|
129 |
def time
|
|
130 |
Time.at2(read_attribute(:time))
|
|
131 |
end
|
125 |
132 |
|
126 |
133 |
def original_filename
|
127 |
134 |
filename
|
... | ... | |
186 |
193 |
read_attribute(:description).blank? ? summary : read_attribute(:description)
|
187 |
194 |
end
|
188 |
195 |
|
189 |
|
def time; Time.at(read_attribute(:time)) end
|
190 |
|
def changetime; Time.at(read_attribute(:changetime)) end
|
|
196 |
def time
|
|
197 |
Time.at2(read_attribute(:time))
|
|
198 |
end
|
|
199 |
|
|
200 |
def changetime
|
|
201 |
Time.at2(read_attribute(:changetime))
|
|
202 |
end
|
191 |
203 |
end
|
192 |
204 |
|
193 |
205 |
class TracTicketChange < ActiveRecord::Base
|
... | ... | |
198 |
210 |
super.select {|column| column.name.to_s != 'field'}
|
199 |
211 |
end
|
200 |
212 |
|
201 |
|
def time; Time.at(read_attribute(:time)) end
|
|
213 |
def time
|
|
214 |
Time.at2(read_attribute(:time))
|
|
215 |
end
|
202 |
216 |
end
|
203 |
217 |
|
204 |
218 |
TRAC_WIKI_PAGES = %w(InterMapTxt InterTrac InterWiki RecentChanges SandBox TracAccessibility TracAdmin TracBackup TracBrowser TracCgi TracChangeset \
|
... | ... | |
222 |
236 |
TracMigrate::TracAttachment.all(:conditions => ["type = 'wiki' AND id = ?", self.id.to_s])
|
223 |
237 |
end
|
224 |
238 |
|
225 |
|
def time; Time.at(read_attribute(:time)) end
|
|
239 |
def time
|
|
240 |
Time.at2(read_attribute(:time))
|
|
241 |
end
|
226 |
242 |
end
|
227 |
243 |
|
228 |
244 |
class TracPermission < ActiveRecord::Base
|
... | ... | |
376 |
392 |
|
377 |
393 |
# Quick database test
|
378 |
394 |
TracComponent.count
|
379 |
|
|
|
395 |
lookup_database_version
|
|
396 |
print "Trac database version is: ", database_version, "\n"
|
380 |
397 |
migrated_components = 0
|
381 |
398 |
migrated_milestones = 0
|
382 |
399 |
migrated_tickets = 0
|
... | ... | |
480 |
497 |
i.status = STATUS_MAPPING[ticket.status] || DEFAULT_STATUS
|
481 |
498 |
i.tracker = TRACKER_MAPPING[ticket.ticket_type] || DEFAULT_TRACKER
|
482 |
499 |
i.id = ticket.id unless Issue.exists?(ticket.id)
|
483 |
|
next unless Time.fake(ticket.changetime) { i.save }
|
|
500 |
next unless i.save
|
484 |
501 |
TICKET_MAP[ticket.id] = i.id
|
485 |
502 |
migrated_tickets += 1
|
486 |
503 |
|
487 |
504 |
# Owner
|
488 |
505 |
unless ticket.owner.blank?
|
489 |
506 |
i.assigned_to = find_or_create_user(ticket.owner, true)
|
490 |
|
Time.fake(ticket.changetime) { i.save }
|
|
507 |
i.save
|
491 |
508 |
end
|
492 |
509 |
|
493 |
510 |
# Comments and status/resolution changes
|
... | ... | |
564 |
581 |
p.content.text = page.text
|
565 |
582 |
p.content.author = find_or_create_user(page.author) unless page.author.blank? || page.author == 'trac'
|
566 |
583 |
p.content.comments = page.comment
|
567 |
|
Time.fake(page.time) { p.new_record? ? p.save : p.content.save }
|
|
584 |
p.new_record? ? p.save : p.content.save
|
568 |
585 |
|
569 |
586 |
next if p.content.new_record?
|
570 |
587 |
migrated_wiki_edits += 1
|
... | ... | |
587 |
604 |
wiki.reload
|
588 |
605 |
wiki.pages.each do |page|
|
589 |
606 |
page.content.text = convert_wiki_text(page.content.text)
|
590 |
|
Time.fake(page.content.updated_on) { page.content.save }
|
|
607 |
page.content.save
|
591 |
608 |
end
|
592 |
609 |
end
|
593 |
610 |
puts
|
... | ... | |
610 |
627 |
@charset = charset
|
611 |
628 |
end
|
612 |
629 |
|
|
630 |
def self.lookup_database_version
|
|
631 |
f = TracSystem.find_by_name("database_version")
|
|
632 |
@@database_version = f.value.to_i
|
|
633 |
end
|
|
634 |
|
|
635 |
def self.database_version
|
|
636 |
@@database_version
|
|
637 |
end
|
|
638 |
|
613 |
639 |
def self.set_trac_directory(path)
|
614 |
640 |
@@trac_directory = path
|
615 |
641 |
raise "This directory doesn't exist!" unless File.directory?(path)
|