Defect #24570 » migrate_from_trac.rake.patch
| migrate_from_trac.rake (working copy) | ||
|---|---|---|
|
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
|
||
| ... | ... | |
|
# 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
|
||
| ... | ... | |
|
# 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
|
||
| ... | ... | |
|
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
|
||
| ... | ... | |
|
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
|
||
| ... | ... | |
|
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 \
|
||
| ... | ... | |
|
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
|
||
| ... | ... | |
|
# 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
|
||
| ... | ... | |
|
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
|
||
|
# 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
|
||
| ... | ... | |
|
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
|
||
| ... | ... | |
|
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
|
||
| ... | ... | |
|
@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)
|
||
- « Previous
- 1
- 2
- Next »