Prepare history import

This commit is contained in:
Vladimir Krylov 2015-11-17 12:17:26 +02:00
parent 1e94909c41
commit e11c1b5d20
4 changed files with 32 additions and 0 deletions

View file

@ -774,6 +774,30 @@ namespace :import do
puts "-----> Imported zones in #{(Time.zone.now.to_f - start).round(2)} seconds"
end
desc 'Import history'
task history: :environment do
Domain.where.not(legacy_id: nil).find_each do |domain|
next if domain.versions.where(action: :create).any?
history = Legacy::DomainHistory.where(id: domain.legacy_id).order("valid_from ASC").to_a
history.each_with_index do |his, i|
event = :update
event = :create if i == 0
event = :destroy if i + 1 == history.size && his.history.valid_to.present?
{
item_type: domain.class,
item_id: domain.id,
event: event,
whodunnit: Registrar.find_by(legacy_id: his.object_history.upid || his.object_history.clid),
object: {},
object_changes: {"id" => [nil, 1111] },
created_at: his.object_history.try(:update),
}
end
end
end
end
def parse_zone_ns_data(domain, zone)