From 6fab1529301ce1232d17cd1a528d1fbc6cdec9f3 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Wed, 6 Jun 2018 23:49:28 +1000 Subject: [PATCH] Only check if time is valid if time has changed --- controllers/admin.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/controllers/admin.rb b/controllers/admin.rb index 1dffc330..eb30ee30 100644 --- a/controllers/admin.rb +++ b/controllers/admin.rb @@ -17,6 +17,8 @@ class CustomWizard::AdminController < ::ApplicationController existing = PluginStore.get('custom_wizard', wizard['id']) || {} + new_time = false + error = nil if wizard["id"].blank? @@ -30,8 +32,13 @@ class CustomWizard::AdminController < ::ApplicationController error = 'after_time_need_time' else after_time_scheduled = Time.parse(wizard["after_time_scheduled"]).utc + + new_time = existing['after_time_scheduled'] ? + after_time_scheduled != Time.parse(existing['after_time_scheduled']).utc : + true + begin - if after_time_scheduled < Time.now.utc + if new_time && after_time_scheduled < Time.now.utc error = 'after_time_invalid' end rescue ArgumentError @@ -88,10 +95,6 @@ class CustomWizard::AdminController < ::ApplicationController s['description'] = PrettyText.cook(s['raw_description']) if s['raw_description'] end - new_time = existing['after_time_scheduled'] ? - after_time_scheduled != Time.parse(existing['after_time_scheduled']).utc : - true - if wizard['after_time'] && new_time Jobs.cancel_scheduled_job(:set_after_time_wizard, wizard_id: wizard['id']) Jobs.enqueue_at(after_time_scheduled, :set_after_time_wizard, wizard_id: wizard['id'])