Skip to content

Release 12.0: Limited user phone fix

Dave Kaplan edited this page Jun 27, 2019 · 1 revision

We had an issue with the Phony gem where Phony.normalize was stripping some valid zeroes, because we're not specifying country codes (not using E164 Format) so it doesn't really work how we'd want it to. As a result, we had to fix some User phone numbers that had been incorrectly altered by normalize (stripped from 10 chars to 9):

users = User.limited.where('length(phone) = 9').to_a;
results = users.map do |user|
  potential_phone = "#{user.phone}"
  # insert a '0' in the 3rd position (index=2)
  potential_phone.insert(2, '0')
  # check if Phony would have removed that '0'
  if Phony.normalize(potential_phone) == user.phone
    user.update(phone: potential_phone)
    if (nu = user.network_user)
      # also update the user on the network
      nu.phone = potential_phone
      nu.save
      "fixed: #{potential_phone} #{user.email} #{user.name} -- updating INA"
    end
  else
    "no #{user.phone} vs. #{Phony.normalize(potential_phone)}"
  end
end
puts results
Clone this wiki locally