mirror of
https://github.com/internetee/registry.git
synced 2025-08-05 17:28:18 +02:00
Merge branch '104525318-history_import' into staging
This commit is contained in:
commit
9a5a000cc4
3 changed files with 62 additions and 2 deletions
|
@ -35,6 +35,8 @@ namespace :import do
|
|||
|
||||
desc 'Import contact history'
|
||||
task history_contacts: :environment do
|
||||
throw 'no config set ENV[legacy_legal_documents_dir]' unless ENV['legacy_legal_documents_dir']
|
||||
|
||||
old_ids = Legacy::ContactHistory.uniq.pluck(:id)
|
||||
old_size = old_ids.size
|
||||
parallel_import(old_ids) do |legacy_contact_id, process_idx|
|
||||
|
@ -88,6 +90,21 @@ namespace :import do
|
|||
obj_his = Legacy::ObjectHistory.find_by(historyid: responder.historyid)
|
||||
user = Legacy::Domain.new_api_user_cached(obj_his.upid || obj_his.clid)
|
||||
|
||||
|
||||
files = Legacy::File.for_history(responder.historyid).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: ::Contact.to_s,
|
||||
documentable_id: contact.id,
|
||||
document_type: leg_file.name.to_s.split(".").last,
|
||||
path: path,
|
||||
created_at: leg_file.crdate,
|
||||
updated_at: leg_file.crdate)
|
||||
end
|
||||
|
||||
hash = {
|
||||
item_type: Contact.to_s,
|
||||
item_id: contact.id,
|
||||
|
@ -95,7 +112,8 @@ namespace :import do
|
|||
whodunnit: user.try(:id),
|
||||
object: last_changes,
|
||||
object_changes: changes,
|
||||
created_at: time
|
||||
created_at: time,
|
||||
children: {legacy_documents: files.map(&:id)}
|
||||
}
|
||||
data << hash
|
||||
|
||||
|
@ -165,6 +183,20 @@ namespace :import do
|
|||
end
|
||||
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 = {
|
||||
item_type: domain.class,
|
||||
item_id: domain.id,
|
||||
|
@ -178,7 +210,8 @@ namespace :import do
|
|||
tech_contacts: responder.history_domain.get_tech_contact_new_ids,
|
||||
nameservers: responder.history_domain.import_nameservers_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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue