mirror of
https://github.com/internetee/registry.git
synced 2025-08-12 20:49:36 +02:00
Story#116761157 - update logic of destroy_orphans to include 6 months delay
This commit is contained in:
parent
f2c96ba145
commit
a7be49203c
3 changed files with 23 additions and 10 deletions
|
@ -35,7 +35,7 @@ module Repp
|
||||||
error! I18n.t('errors.messages.epp_authorization_error'), 401 unless domain.auth_info.eql? request.headers['Auth-Code']
|
error! I18n.t('errors.messages.epp_authorization_error'), 401 unless domain.auth_info.eql? request.headers['Auth-Code']
|
||||||
|
|
||||||
contact_repp_json = proc{|contact|
|
contact_repp_json = proc{|contact|
|
||||||
contact.attributes.slice("code", "name", "ident", "ident_type", "ident_country_code", "phone", "email", "street", "city", "zip","country_code", "statuses")
|
contact.as_json.slice("code", "name", "ident", "ident_type", "ident_country_code", "phone", "email", "street", "city", "zip","country_code", "statuses")
|
||||||
}
|
}
|
||||||
|
|
||||||
@response = {
|
@response = {
|
||||||
|
|
|
@ -39,7 +39,6 @@ class Contact < ActiveRecord::Base
|
||||||
validate :val_country_code
|
validate :val_country_code
|
||||||
|
|
||||||
after_initialize do
|
after_initialize do
|
||||||
self.statuses = [] if statuses.nil?
|
|
||||||
self.status_notes = {} if status_notes.nil?
|
self.status_notes = {} if status_notes.nil?
|
||||||
self.ident_updated_at = Time.zone.now if new_record? && ident_updated_at.blank?
|
self.ident_updated_at = Time.zone.now if new_record? && ident_updated_at.blank?
|
||||||
end
|
end
|
||||||
|
@ -173,20 +172,29 @@ class Contact < ActiveRecord::Base
|
||||||
')
|
')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# To leave only new ones we need to check
|
||||||
|
# if contact was at any time used in domain.
|
||||||
|
# This can be checked by domain history.
|
||||||
|
# This can be checked by saved relations in children attribute
|
||||||
def destroy_orphans
|
def destroy_orphans
|
||||||
STDOUT << "#{Time.zone.now.utc} - Destroying orphaned contacts\n" unless Rails.env.test?
|
STDOUT << "#{Time.zone.now.utc} - Destroying orphaned contacts\n" unless Rails.env.test?
|
||||||
|
|
||||||
orphans = find_orphans
|
counter = Counter.new
|
||||||
|
find_orphans.find_each do |contact|
|
||||||
unless Rails.env.test?
|
ver_scope = []
|
||||||
orphans.each do |m|
|
%w(admin_contacts tech_contacts registrant).each do |type|
|
||||||
STDOUT << "#{Time.zone.now.utc} Contact.destroy_orphans: ##{m.id} (#{m.name})\n"
|
ver_scope << "(children->'#{type}')::jsonb <@ json_build_array(#{contact.id})::jsonb"
|
||||||
end
|
end
|
||||||
|
next if DomainVersion.where("created_at > ?", Time.now - 6.months).where(ver_scope.join(" OR ")).any?
|
||||||
|
next if contact.domains_present?
|
||||||
|
|
||||||
|
# contact.destroy
|
||||||
|
counter.next
|
||||||
|
STDOUT << "#{Time.zone.now.utc} Contact.destroy_orphans: ##{contact.id} (#{contact.name})\n"
|
||||||
|
p "#{Time.zone.now.utc} Contact.destroy_orphans: ##{contact.id} (#{contact.name})\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
count = orphans.destroy_all.count
|
STDOUT << "#{Time.zone.now.utc} - Successfully destroyed #{counter} orphaned contacts\n" unless Rails.env.test?
|
||||||
|
|
||||||
STDOUT << "#{Time.zone.now.utc} - Successfully destroyed #{count} orphaned contacts\n" unless Rails.env.test?
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def privs
|
def privs
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class ChangeContactStatusesDefault < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
change_column_default :contacts, :statuses, []
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue