mirror of
https://github.com/discourse/discourse.git
synced 2025-02-09 12:54:56 +00:00
Prior to this fix, any change to an automation would reset `pending_automations`, now we only do it if any value related to recurrence (start_date, interval, frequency, execute_at...) has been changed. It means that any trigger creating `pending_automations` now needs to manage them in the `on_update` callback.
20 lines
672 B
Ruby
20 lines
672 B
Ruby
# frozen_string_literal: true
|
|
|
|
DiscourseAutomation::Triggerable.add(DiscourseAutomation::Triggers::POINT_IN_TIME) do
|
|
field :execute_at, component: :date_time, required: true
|
|
|
|
on_update do |automation, fields, previous_fields|
|
|
execute_at = fields.dig("execute_at", "value")
|
|
previous_execute_at = previous_fields&.dig("execute_at", "value")
|
|
|
|
if execute_at != previous_execute_at
|
|
automation.pending_automations.destroy_all
|
|
|
|
# prevents creating a new pending automation on save when date is expired
|
|
if execute_at && execute_at > Time.zone.now
|
|
automation.pending_automations.create!(execute_at: execute_at)
|
|
end
|
|
end
|
|
end
|
|
end
|