2023-01-12 17:42:02 +01:00
|
|
|
class Migrations::BatchUpdateDatetimeValuesJob < ApplicationJob
|
|
|
|
def perform(ids)
|
2024-02-05 11:20:55 +01:00
|
|
|
Champs::DatetimeChamp.where(id: ids).find_each do |datetime_champ|
|
2023-01-12 17:42:02 +01:00
|
|
|
current_value_in_time = Time.zone.parse(datetime_champ.value)
|
|
|
|
|
|
|
|
if current_value_in_time.present?
|
|
|
|
datetime_champ.update_columns(value: current_value_in_time.iso8601)
|
|
|
|
else
|
|
|
|
update_value_to_nil_if_possible(datetime_champ)
|
|
|
|
end
|
|
|
|
|
|
|
|
rescue TypeError
|
|
|
|
update_value_to_nil_if_possible(datetime_champ)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def update_value_to_nil_if_possible(datetime_champ)
|
|
|
|
return if datetime_champ.value.nil?
|
|
|
|
|
|
|
|
datetime_champ.update_columns(value: nil) unless datetime_champ.required?
|
|
|
|
end
|
|
|
|
end
|