From db3e39f0cbefd90967f73110def4d41ed52eee74 Mon Sep 17 00:00:00 2001 From: Raffael Herrmann Date: Tue, 24 Oct 2023 11:25:44 +0200 Subject: [PATCH] Added detection of external triggers of the scheduler (#3726) Added extension to the isCrontabSetup method to detect external triggers of the scheduler, so that in the admin interface the error message is hidden when the scheduler is called by an external trigger. --- system/src/Grav/Common/Scheduler/Scheduler.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Scheduler/Scheduler.php b/system/src/Grav/Common/Scheduler/Scheduler.php index f4cf4549cd..85b903b953 100644 --- a/system/src/Grav/Common/Scheduler/Scheduler.php +++ b/system/src/Grav/Common/Scheduler/Scheduler.php @@ -214,6 +214,9 @@ public function run(DateTime $runTime = null, $force = false) // Store states $this->saveJobStates(); + + // Store run date + file_put_contents("logs/lastcron.run", (new DateTime("now"))->format("Y-m-d H:i:s"), LOCK_EX); } /** @@ -291,7 +294,7 @@ public function getSchedulerCommand($php = null) } /** - * Helper to determine if cron job is setup + * Helper to determine if cron-like job is setup * 0 - Crontab Not found * 1 - Crontab Found * 2 - Error @@ -300,6 +303,13 @@ public function getSchedulerCommand($php = null) */ public function isCrontabSetup() { + // Check for external triggers + $last_run = @file_get_contents("logs/lastcron.run"); + if (time() - strtotime($last_run) < 120){ + return 1; + } + + // No external triggers found, so do legacy cron checks $process = new Process(['crontab', '-l']); $process->run();