mirror of
https://github.com/internetee/registry.git
synced 2025-07-01 08:43:37 +02:00
Merge pull request #111 from internetee/story/114871365-address-cc-upcase
Story/114871365 address cc upcase
This commit is contained in:
commit
6ee076c9a4
2 changed files with 49 additions and 9 deletions
|
@ -32,6 +32,7 @@ class Contact < ActiveRecord::Base
|
||||||
validate :val_ident_valid_format?
|
validate :val_ident_valid_format?
|
||||||
validate :uniq_statuses?
|
validate :uniq_statuses?
|
||||||
validate :validate_html
|
validate :validate_html
|
||||||
|
validate :val_country_code
|
||||||
|
|
||||||
after_initialize do
|
after_initialize do
|
||||||
self.statuses = [] if statuses.nil?
|
self.statuses = [] if statuses.nil?
|
||||||
|
@ -39,7 +40,7 @@ class Contact < ActiveRecord::Base
|
||||||
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
|
||||||
|
|
||||||
before_validation :set_ident_country_code
|
before_validation :to_upcase_country_code
|
||||||
before_validation :prefix_code
|
before_validation :prefix_code
|
||||||
before_create :generate_auth_info
|
before_create :generate_auth_info
|
||||||
|
|
||||||
|
@ -352,14 +353,14 @@ class Contact < ActiveRecord::Base
|
||||||
destroy
|
destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_ident_country_code
|
def to_upcase_country_code
|
||||||
return true unless ident_country_code_changed? && ident_country_code.present?
|
self.ident_country_code = ident_country_code.upcase if ident_country_code
|
||||||
code = Country.new(ident_country_code)
|
self.country_code = country_code.upcase if country_code
|
||||||
if code
|
end
|
||||||
self.ident_country_code = code.alpha2
|
|
||||||
else
|
def val_country_code
|
||||||
errors.add(:ident, :invalid_country_code)
|
errors.add(:ident, :invalid_country_code) unless Country.new(ident_country_code)
|
||||||
end
|
errors.add(:ident, :invalid_country_code) unless Country.new(country_code)
|
||||||
end
|
end
|
||||||
|
|
||||||
def related_domain_descriptions
|
def related_domain_descriptions
|
||||||
|
|
|
@ -32,5 +32,44 @@ namespace :convert do
|
||||||
d.save!
|
d.save!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
desc 'Contact Address Country Code Upcase'
|
||||||
|
task country_code_upcase: :environment do
|
||||||
|
count = 0
|
||||||
|
Contact.find_each do |c|
|
||||||
|
if c.country_code.present? && c.country_code != c.country_code.upcase
|
||||||
|
c.country_code = c.country_code.upcase
|
||||||
|
c.update_columns(country_code: c.country_code.upcase)
|
||||||
|
|
||||||
|
count +=1
|
||||||
|
puts "#{count} contacts has been changed" if count % 1000 == 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
puts "Contacts change has been finished. Starting ContactVersions"
|
||||||
|
|
||||||
|
count = 0
|
||||||
|
ContactVersion.find_each do |c|
|
||||||
|
if (if_object = (c.object && c.object["country_code"].present? && c.object["country_code"] != c.object["country_code"].upcase)) ||
|
||||||
|
(if_changes = (c.object_changes && c.object_changes["country_code"].present? && c.object_changes["country_code"] != c.object_changes["country_code"].map{|e|e.try(:upcase)}))
|
||||||
|
|
||||||
|
if if_object
|
||||||
|
h = c.object
|
||||||
|
h["country_code"] = h["country_code"].try(:upcase)
|
||||||
|
c.object = h
|
||||||
|
end
|
||||||
|
|
||||||
|
if if_changes
|
||||||
|
h = c.object_changes
|
||||||
|
h["country_code"] = h["country_code"].map{|e|e.try(:upcase)}
|
||||||
|
c.object_changes = h
|
||||||
|
end
|
||||||
|
c.update_columns(object: c.object, object_changes: c.object_changes)
|
||||||
|
|
||||||
|
count +=1
|
||||||
|
puts "#{count} contact histories has been changed" if count % 1000 == 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue