class ZuoraConnect::ZuoraUser
def self.update_id_response(zuora_user_id, zuora_entity_id, zuora_current_identity, app_instance)
zuora_current_identity comes from session
zuora_user_id/zuora_entity_id both come from cookie or headers
def self.update_id_response(zuora_user_id, zuora_entity_id, zuora_current_identity, app_instance) zuora_user = find_or_create_by!(zuora_user_id: zuora_user_id) do |user| user.zuora_identity_response = { zuora_entity_id => zuora_current_identity } end if zuora_user.stale_identity? zuora_user.zuora_identity_response[zuora_entity_id] = zuora_current_identity zuora_user.save! end zuora_user # NOTE(hartley): this rescue is deprecated. We should not be migrating in production rescue ActiveRecord::StatementInvalid => e raise unless e.message.include?('PG::UndefinedTable') && e.message.include?('zuora_users') ZuoraConnect.logger.fatal('Error querying zuora_users table: attempting migration to recover') app_instance.apartment_switch(nil, true) retry end
def stale_identity?
NOTE(hartley): this value was extracted from original usage in helper,
def stale_identity? updated_at < Time.now - 1.day end