mirror of
https://github.com/internetee/registry.git
synced 2025-07-13 22:45:06 +02:00
Story#108521790 - update that code works with nameservers
This commit is contained in:
parent
f6d16f51e9
commit
01a82a2960
3 changed files with 31 additions and 22 deletions
|
@ -51,26 +51,33 @@ module Legacy
|
||||||
end
|
end
|
||||||
|
|
||||||
def user
|
def user
|
||||||
@user ||= Registrar.find_by(legacy_id: obj_his.upid || obj_his.clid).try(:api_users).try(:first)
|
@user ||= begin
|
||||||
|
obj_his = Legacy::ObjectHistory.find_by(historyid: historyid)
|
||||||
|
Registrar.find_by(legacy_id: obj_his.upid || obj_his.clid).try(:api_users).try(:first)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def history_domain
|
||||||
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# returns imported nameserver ids
|
# returns imported nameserver ids
|
||||||
def import_nameservers_history(new_domain, time)
|
def import_nameservers_history(new_domain, time)
|
||||||
#removing previous nameservers
|
# #removing previous nameservers
|
||||||
NameserverVersion.where("object->>legacy_domain_id").where(event: :create).where("created_at <= ?", time).each do |nv|
|
# NameserverVersion.where("object_changes->>'legacy_domain_id' = '[nil,#{id}]'").where(event: :create).where("created_at <= ?", time).each do |nv|
|
||||||
if NameserverVersion.where(item_type: nv.item_type, item_id: nv.item_id, event: :destroy).none?
|
# if NameserverVersion.where(item_type: nv.item_type, item_id: nv.item_id, event: :destroy).none?
|
||||||
NameserverVersion.create!(
|
# NameserverVersion.create!(
|
||||||
item_type: nv.item_type,
|
# item_type: nv.item_type,
|
||||||
item_id: nv.item_id,
|
# item_id: nv.item_id,
|
||||||
event: :destroy,
|
# event: :destroy,
|
||||||
whodunnit: user.try(:id),
|
# whodunnit: user.try(:id),
|
||||||
object: nv.object_changes.each_with_object({}){|(k,v),hash| hash[k] = v.last },
|
# object: nv.object_changes.each_with_object({}){|(k,v),hash| hash[k] = v.last },
|
||||||
object_changes: {},
|
# object_changes: {},
|
||||||
created_at: time
|
# created_at: time
|
||||||
)
|
# )
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
|
|
||||||
|
|
||||||
if (nssets = nsset_histories.at(time).to_a).any?
|
if (nssets = nsset_histories.at(time).to_a).any?
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
module Legacy
|
module Legacy
|
||||||
class ObjectState < Db
|
class ObjectState < Db
|
||||||
self.table_name = :object_state
|
self.table_name = :object_state
|
||||||
|
attr_accessor :history_domain
|
||||||
|
|
||||||
scope :valid, -> { where('valid_to IS NULL') }
|
scope :valid, -> { where('valid_to IS NULL') }
|
||||||
|
|
||||||
|
@ -82,6 +83,8 @@ module Legacy
|
||||||
|
|
||||||
def get_current_domain_object(time, param)
|
def get_current_domain_object(time, param)
|
||||||
d_his = Legacy::DomainHistory.get_record_at(object_id, historyid)
|
d_his = Legacy::DomainHistory.get_record_at(object_id, historyid)
|
||||||
|
@history_domain = d_his
|
||||||
|
|
||||||
hash = d_his.get_current_domain_object(time, param)
|
hash = d_his.get_current_domain_object(time, param)
|
||||||
hash[:statuses] = Legacy::ObjectState.states_for_domain_at(object_id, time + 1)
|
hash[:statuses] = Legacy::ObjectState.states_for_domain_at(object_id, time + 1)
|
||||||
|
|
||||||
|
|
|
@ -108,7 +108,6 @@ namespace :import do
|
||||||
new_attrs[:id] = domain.id
|
new_attrs[:id] = domain.id
|
||||||
new_attrs[:updated_at] = time
|
new_attrs[:updated_at] = time
|
||||||
p time
|
p time
|
||||||
p responder.import_nameservers_history(domain, time) if responder.respond_to?(:import_nameservers_history)
|
|
||||||
|
|
||||||
event = :update
|
event = :update
|
||||||
event = :create if i == 0
|
event = :create if i == 0
|
||||||
|
@ -121,22 +120,22 @@ namespace :import do
|
||||||
if (old_val = last_changes.to_h[k]) != v then changes[k] = [old_val, v] end
|
if (old_val = last_changes.to_h[k]) != v then changes[k] = [old_val, v] end
|
||||||
end
|
end
|
||||||
next if changes.blank? && event != :destroy
|
next if changes.blank? && event != :destroy
|
||||||
obj_his = Legacy::ObjectHistory.find_by(historyid: responder.historyid)
|
responder.import_nameservers_history(domain, time) if responder.respond_to?(:import_nameservers_history)
|
||||||
|
|
||||||
p DomainVersion.new(
|
DomainVersion.create!(
|
||||||
item_type: domain.class,
|
item_type: domain.class,
|
||||||
item_id: domain.id,
|
item_id: domain.id,
|
||||||
event: event,
|
event: event,
|
||||||
whodunnit: responder.user.try(:id),
|
whodunnit: responder.history_domain.user.try(:id),
|
||||||
object: last_changes,
|
object: last_changes,
|
||||||
object_changes: changes,
|
object_changes: changes,
|
||||||
created_at: time,
|
created_at: time,
|
||||||
children: {
|
children: {
|
||||||
admin_contacts: responder.get_admin_contact_new_ids,
|
admin_contacts: responder.history_domain.get_admin_contact_new_ids,
|
||||||
tech_contacts: responder.get_tech_contact_new_ids,
|
tech_contacts: responder.history_domain.get_tech_contact_new_ids,
|
||||||
nameservers: [],
|
nameservers: [],
|
||||||
dnskeys: [],
|
dnskeys: [],
|
||||||
registrant: [responder.new_registrant_id]
|
registrant: [responder.history_domain.new_registrant_id]
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue