Story#108602614 - apply contacts history import improvements to domains

This commit is contained in:
Vladimir Krylov 2015-12-10 11:50:51 +02:00
parent b2dd26d1b9
commit 764a8fa0d3
2 changed files with 9 additions and 5 deletions

View file

@ -18,15 +18,15 @@ module Legacy
registered_at: x.object_registry.try(:crdate), registered_at: x.object_registry.try(:crdate),
valid_from: x.object_registry.try(:crdate), valid_from: x.object_registry.try(:crdate),
valid_to: x.exdate, valid_to: x.exdate,
auth_info: x.object.authinfopw.try(:strip), auth_info: x.object_history.authinfopw.try(:strip),
created_at: x.object_registry.try(:crdate), created_at: x.object_registry.try(:crdate),
updated_at: x.object.read_attribute(:update).nil? ? x.object_registry.try(:crdate) : x.object.read_attribute(:update), updated_at: x.object_history.read_attribute(:update).nil? ? x.object_registry.try(:crdate) : x.object_history.read_attribute(:update),
name_dirty: x.object_registry.name.try(:strip), name_dirty: x.object_registry.name.try(:strip),
name_puny: SimpleIDN.to_ascii(x.object_registry.name.try(:strip)), name_puny: SimpleIDN.to_ascii(x.object_registry.name.try(:strip)),
period: 1, period: 1,
period_unit: 'y', period_unit: 'y',
creator_str: x.object_registry.try(:registrar).try(:name), creator_str: x.object_registry.try(:registrar).try(:name),
updator_str: x.object.try(:registrar).try(:name) ? x.object.try(:registrar).try(:name) : x.object_registry.try(:registrar).try(:name), updator_str: x.object_history.try(:registrar).try(:name) ? x.object_history.try(:registrar).try(:name) : x.object_registry.try(:registrar).try(:name),
legacy_id: x.id, legacy_id: x.id,
legacy_registrar_id: x.object_history.try(:clid), legacy_registrar_id: x.object_history.try(:clid),
legacy_registrant_id: x.registrant, legacy_registrant_id: x.registrant,

View file

@ -74,14 +74,17 @@ namespace :import do
task history_domains: :environment do task history_domains: :environment do
Domain.transaction do Domain.transaction do
Legacy::DomainHistory.uniq.where(id: 294516).pluck(:id).each do |legacy_domain_id| Legacy::DomainHistory.uniq.where(id: 294516).pluck(:id).each do |legacy_domain_id|
next if Domain.find_by(legacy_id: legacy_domain_id).versions.where(event: :create).any? domain = Domain.find_by(legacy_id: legacy_domain_id)
version_domain = DomainVersion.where("object->>'legacy_id' = '#{legacy_domain_id}'").select(:item_id).first
domain ||= Domain.new(id: version_domain.item_id, legacy_id: legacy_domain_id) if version_domain
domain ||= Domain.new(id: ::Domain.next_id, legacy_id: legacy_domain_id)
next if domain.versions.where(event: :create).any?
# add here to skip domains whith create history # add here to skip domains whith create history
# 1. add domain changes # 1. add domain changes
# 2. add states # 2. add states
# compose hash of change time -> Object changes # compose hash of change time -> Object changes
last_changes = nil last_changes = nil
domain = Domain.find_by(legacy_id: legacy_domain_id)
history = Legacy::ObjectState.changes_dates_for(legacy_domain_id) history = Legacy::ObjectState.changes_dates_for(legacy_domain_id)
dom_his = Legacy::DomainHistory.changes_dates_for(legacy_domain_id) dom_his = Legacy::DomainHistory.changes_dates_for(legacy_domain_id)
last_domain_action = dom_his.sort.last[1].last # need to identify if we delete last_domain_action = dom_his.sort.last[1].last # need to identify if we delete
@ -102,6 +105,7 @@ namespace :import do
changes = {} changes = {}
responder = orig_history_klass[:klass].get_record_at(legacy_domain_id, orig_history_klass[:id]) responder = orig_history_klass[:klass].get_record_at(legacy_domain_id, orig_history_klass[:id])
new_attrs = responder.get_current_domain_object(time, orig_history_klass[:param]) new_attrs = responder.get_current_domain_object(time, orig_history_klass[:param])
new_attrs[:id] = domain.id
event = :update event = :update
event = :create if i == 0 event = :create if i == 0