Revision 1302
Added by Jean-Philippe Lang over 17 years ago
trunk/lib/tasks/migrate_from_trac.rake | ||
---|---|---|
68 | 68 |
ROLE_MAPPING = {'admin' => manager_role, |
69 | 69 |
'developer' => developer_role |
70 | 70 |
} |
71 |
|
|
71 |
|
|
72 |
class ::Time |
|
73 |
class << self |
|
74 |
alias :real_now :now |
|
75 |
def now |
|
76 |
real_now - @fake_diff.to_i |
|
77 |
end |
|
78 |
def fake(time) |
|
79 |
@fake_diff = real_now - time |
|
80 |
res = yield |
|
81 |
@fake_diff = 0 |
|
82 |
res |
|
83 |
end |
|
84 |
end |
|
85 |
end |
|
86 |
|
|
72 | 87 |
class TracComponent < ActiveRecord::Base |
73 | 88 |
set_table_name :component |
74 | 89 |
end |
... | ... | |
141 | 156 |
end |
142 | 157 |
|
143 | 158 |
def time; Time.at(read_attribute(:time)) end |
159 |
def changetime; Time.at(read_attribute(:changetime)) end |
|
144 | 160 |
end |
145 | 161 |
|
146 | 162 |
class TracTicketChange < ActiveRecord::Base |
... | ... | |
167 | 183 |
# Hides readonly Trac field to prevent clash with AR readonly? method (Rails 2.0) |
168 | 184 |
super.select {|column| column.name.to_s != 'readonly'} |
169 | 185 |
end |
186 |
|
|
187 |
def time; Time.at(read_attribute(:time)) end |
|
170 | 188 |
end |
171 | 189 |
|
172 | 190 |
class TracPermission < ActiveRecord::Base |
... | ... | |
345 | 363 |
i.tracker = TRACKER_MAPPING[ticket.ticket_type] || DEFAULT_TRACKER |
346 | 364 |
i.custom_values << CustomValue.new(:custom_field => custom_field_map['resolution'], :value => ticket.resolution) unless ticket.resolution.blank? |
347 | 365 |
i.id = ticket.id unless Issue.exists?(ticket.id) |
348 |
next unless i.save
|
|
366 |
next unless Time.fake(ticket.changetime) { i.save }
|
|
349 | 367 |
TICKET_MAP[ticket.id] = i.id |
350 | 368 |
migrated_tickets += 1 |
351 | 369 |
|
352 | 370 |
# Owner |
353 | 371 |
unless ticket.owner.blank? |
354 | 372 |
i.assigned_to = find_or_create_user(ticket.owner, true) |
355 |
i.save
|
|
373 |
Time.fake(ticket.changetime) { i.save }
|
|
356 | 374 |
end |
357 | 375 |
|
358 | 376 |
# Comments and status/resolution changes |
... | ... | |
426 | 444 |
p.content.text = page.text |
427 | 445 |
p.content.author = find_or_create_user(page.author) unless page.author.blank? || page.author == 'trac' |
428 | 446 |
p.content.comments = page.comment |
429 |
p.new_record? ? p.save : p.content.save
|
|
447 |
Time.fake(page.time) { p.new_record? ? p.save : p.content.save }
|
|
430 | 448 |
|
431 | 449 |
next if p.content.new_record? |
432 | 450 |
migrated_wiki_edits += 1 |
... | ... | |
446 | 464 |
wiki.reload |
447 | 465 |
wiki.pages.each do |page| |
448 | 466 |
page.content.text = convert_wiki_text(page.content.text) |
449 |
page.content.save
|
|
467 |
Time.fake(page.content.updated_on) { page.content.save }
|
|
450 | 468 |
end |
451 | 469 |
end |
452 | 470 |
puts |
Also available in: Unified diff
Fixed: migrate_from_trac doesn't import timestamps of wiki and tickets (patch #882 by Andreas Neuhaus slightly edited).