discourse-cakeday/app/jobs/onceoff/fix_invalid_date_of_birth.rb

18 lines
426 B
Ruby

# frozen_string_literal: true
module Jobs
class FixInvalidDateOfBirth < ::Jobs::Onceoff
def execute_onceoff(args)
UserCustomField
.where(name: "date_of_birth")
.where("value != ''")
.find_each do |custom_field|
begin
Date.parse(custom_field.value)
rescue ArgumentError
custom_field.update!(value: "")
end
end
end
end
end