Story#104525318 - Domains import can handle legal documents import

This commit is contained in:
Vladimir Krylov 2016-01-27 17:05:56 +02:00
parent 550e4cc7b9
commit c089e032b5
3 changed files with 31 additions and 3 deletions

View file

@ -14,6 +14,10 @@ module Legacy
has_many :domain_contact_map_histories, foreign_key: :historyid, primary_key: :historyid has_many :domain_contact_map_histories, foreign_key: :historyid, primary_key: :historyid
has_many :nsset_contact_map_histories, foreign_key: :historyid, primary_key: :historyid has_many :nsset_contact_map_histories, foreign_key: :historyid, primary_key: :historyid
after_initialize do
@other_history_ids ||= []
end
def get_current_domain_object(time, change_param) def get_current_domain_object(time, change_param)
x = self x = self
{ {
@ -63,6 +67,10 @@ module Legacy
self self
end end
def all_history_ids
([historyid] + @other_history_ids).uniq
end
# returns imported nameserver ids # returns imported nameserver ids
def import_nameservers_history(new_domain, time) def import_nameservers_history(new_domain, time)
@ -72,9 +80,12 @@ module Legacy
to_import = [] to_import = []
nsset_histories.at(time).to_a.each do |nsset| nsset_histories.at(time).to_a.each do |nsset|
@other_history_ids << nsset.historyid
nsset.host_histories.at(time).each do |host| nsset.host_histories.at(time).each do |host|
@other_history_ids << host.historyid
ips = {ipv4: [],ipv6: []} ips = {ipv4: [],ipv6: []}
host.host_ipaddr_map_histories.where.not(ipaddr: nil).at(time).each do |ip_map| host.host_ipaddr_map_histories.where.not(ipaddr: nil).at(time).each do |ip_map|
@other_history_ids << ip_map.historyid
ips[:ipv4] << ip_map.ipaddr.to_s.strip if ip_map.ipaddr.ipv4? ips[:ipv4] << ip_map.ipaddr.to_s.strip if ip_map.ipaddr.ipv4?
ips[:ipv6] << ip_map.ipaddr.to_s.strip if ip_map.ipaddr.ipv6? ips[:ipv6] << ip_map.ipaddr.to_s.strip if ip_map.ipaddr.ipv6?
end end
@ -178,6 +189,7 @@ module Legacy
self.class.dnssecs[id] ||= {} self.class.dnssecs[id] ||= {}
ids = [] ids = []
Legacy::DnskeyHistory.for_at(keyset, time).each do |dns| Legacy::DnskeyHistory.for_at(keyset, time).each do |dns|
@other_history_ids << dns.historyid
# checking if we have create history for dnskey (cache) # checking if we have create history for dnskey (cache)
if val = self.class.dnssecs[id][dns] if val = self.class.dnssecs[id][dns]
ids << val ids << val

View file

@ -3,11 +3,12 @@ module Legacy
self.table_name = :files self.table_name = :files
def self.for_history history_id def self.for_history history_id
history_ids = Array(history_id)
sql = %Q{select history.id, files.path, files.name, files.crdate sql = %Q{select history.id, files.path, files.name, files.crdate
from history from history
join action ON action.id=history.action join action ON action.id=history.action
join files on action.servertrid=files.servertrid join files on action.servertrid=files.servertrid
where history.id =#{history_id};} where history.id IN (#{history_ids.join(",")});}
find_by_sql(sql).to_a find_by_sql(sql).to_a
end end
end end

View file

@ -96,7 +96,7 @@ namespace :import do
path = "#{ENV['legal_documents_dir']}/#{leg_file.path}_#{leg_file.name}" path = "#{ENV['legal_documents_dir']}/#{leg_file.path}_#{leg_file.name}"
FileUtils.mkdir_p("#{ENV['legal_documents_dir']}/#{file_dir}", mode: 0775) FileUtils.mkdir_p("#{ENV['legal_documents_dir']}/#{file_dir}", mode: 0775)
FileUtils.mv("#{ENV['legacy_legal_documents_dir']}/#{leg_file.path}_#{leg_file.name}", path) FileUtils.mv("#{ENV['legacy_legal_documents_dir']}/#{leg_file.path}", path)
LegalDocument.create!(documentable_type: ::Contact.to_s, LegalDocument.create!(documentable_type: ::Contact.to_s,
documentable_id: contact.id, documentable_id: contact.id,
document_type: leg_file.name.to_s.split(".").last, document_type: leg_file.name.to_s.split(".").last,
@ -183,6 +183,20 @@ namespace :import do
end end
next if changes.blank? && event != :destroy next if changes.blank? && event != :destroy
files = Legacy::File.for_history(responder.history_domain.all_history_ids).map do |leg_file|
file_dir = leg_file.path.sub(/\/[0-9]+\z/, '')
path = "#{ENV['legal_documents_dir']}/#{leg_file.path}_#{leg_file.name}"
FileUtils.mkdir_p("#{ENV['legal_documents_dir']}/#{file_dir}", mode: 0775)
FileUtils.mv("#{ENV['legacy_legal_documents_dir']}/#{leg_file.path}", path)
LegalDocument.create!(documentable_type: domain.class,
documentable_id: domain.id,
document_type: leg_file.name.to_s.split(".").last,
path: path,
created_at: leg_file.crdate,
updated_at: leg_file.crdate)
end
hash = { hash = {
item_type: domain.class, item_type: domain.class,
item_id: domain.id, item_id: domain.id,
@ -196,7 +210,8 @@ namespace :import do
tech_contacts: responder.history_domain.get_tech_contact_new_ids, tech_contacts: responder.history_domain.get_tech_contact_new_ids,
nameservers: responder.history_domain.import_nameservers_history(domain, time), nameservers: responder.history_domain.import_nameservers_history(domain, time),
dnskeys: responder.history_domain.import_dnskeys_history(domain, time), dnskeys: responder.history_domain.import_dnskeys_history(domain, time),
registrant: [responder.history_domain.new_registrant_id] registrant: [responder.history_domain.new_registrant_id],
legacy_documents: files.map(&:id)
} }
} }
data << hash data << hash