Index: migrate_from_trac.rake =================================================================== --- migrate_from_trac.rake (revision 12066) +++ migrate_from_trac.rake (working copy) @@ -71,19 +71,24 @@ class ::Time class << self - alias :real_now :now - def now - real_now - @fake_diff.to_i + def at2(time) + # In Trac ticket #6466, timestamps + # were changed from seconds since the epoch + # to microseconds since the epoch. The + # Trac database version was bumped to 23 for this. + if TracMigrate.database_version > 22 + Time.at(time / 1000000) + else + Time.at(time) + end end - def fake(time) - @fake_diff = real_now - time - res = yield - @fake_diff = 0 - res - end end end + class TracSystem < ActiveRecord::Base + self.table_name = :system + end + class TracComponent < ActiveRecord::Base self.table_name = :component end @@ -93,7 +98,7 @@ # If this attribute is set a milestone has a defined target timepoint def due if read_attribute(:due) && read_attribute(:due) > 0 - Time.at(read_attribute(:due)).to_date + Time.at2(read_attribute(:due)).to_date else nil end @@ -101,7 +106,7 @@ # This is the real timepoint at which the milestone has finished. def completed if read_attribute(:completed) && read_attribute(:completed) > 0 - Time.at(read_attribute(:completed)).to_date + Time.at2(read_attribute(:completed)).to_date else nil end @@ -121,7 +126,9 @@ self.table_name = :attachment set_inheritance_column :none - def time; Time.at(read_attribute(:time)) end + def time + Time.at2(read_attribute(:time)) + end def original_filename filename @@ -186,8 +193,13 @@ read_attribute(:description).blank? ? summary : read_attribute(:description) end - def time; Time.at(read_attribute(:time)) end - def changetime; Time.at(read_attribute(:changetime)) end + def time + Time.at2(read_attribute(:time)) + end + + def changetime + Time.at2(read_attribute(:changetime)) + end end class TracTicketChange < ActiveRecord::Base @@ -198,7 +210,9 @@ super.select {|column| column.name.to_s != 'field'} end - def time; Time.at(read_attribute(:time)) end + def time + Time.at2(read_attribute(:time)) + end end TRAC_WIKI_PAGES = %w(InterMapTxt InterTrac InterWiki RecentChanges SandBox TracAccessibility TracAdmin TracBackup TracBrowser TracCgi TracChangeset \ @@ -222,7 +236,9 @@ TracMigrate::TracAttachment.all(:conditions => ["type = 'wiki' AND id = ?", self.id.to_s]) end - def time; Time.at(read_attribute(:time)) end + def time + Time.at2(read_attribute(:time)) + end end class TracPermission < ActiveRecord::Base @@ -376,7 +392,8 @@ # Quick database test TracComponent.count - + lookup_database_version + print "Trac database version is: ", database_version, "\n" migrated_components = 0 migrated_milestones = 0 migrated_tickets = 0 @@ -480,7 +497,7 @@ i.status = STATUS_MAPPING[ticket.status] || DEFAULT_STATUS i.tracker = TRACKER_MAPPING[ticket.ticket_type] || DEFAULT_TRACKER i.id = ticket.id unless Issue.exists?(ticket.id) - next unless Time.fake(ticket.changetime) { i.save } + next unless i.save TICKET_MAP[ticket.id] = i.id migrated_tickets += 1 @@ -487,7 +504,7 @@ # Owner unless ticket.owner.blank? i.assigned_to = find_or_create_user(ticket.owner, true) - Time.fake(ticket.changetime) { i.save } + i.save end # Comments and status/resolution changes @@ -564,7 +581,7 @@ p.content.text = page.text p.content.author = find_or_create_user(page.author) unless page.author.blank? || page.author == 'trac' p.content.comments = page.comment - Time.fake(page.time) { p.new_record? ? p.save : p.content.save } + p.new_record? ? p.save : p.content.save next if p.content.new_record? migrated_wiki_edits += 1 @@ -587,7 +604,7 @@ wiki.reload wiki.pages.each do |page| page.content.text = convert_wiki_text(page.content.text) - Time.fake(page.content.updated_on) { page.content.save } + page.content.save end end puts @@ -610,6 +627,15 @@ @charset = charset end + def self.lookup_database_version + f = TracSystem.find_by_name("database_version") + @@database_version = f.value.to_i + end + + def self.database_version + @@database_version + end + def self.set_trac_directory(path) @@trac_directory = path raise "This directory doesn't exist!" unless File.directory?(path)