fix: validate cron expression in Scheduled Task update

This commit is contained in:
Efthymis Sarmpanis 2025-01-27 22:50:54 +02:00
parent fddaf9134d
commit 01b9cbdfea

View file

@ -77,6 +77,10 @@ public function syncData(bool $toModel = false)
{ {
if ($toModel) { if ($toModel) {
$this->validate(); $this->validate();
$isValid = validate_cron_expression($this->frequency);
if (! $isValid) {
throw new \Exception('Invalid Cron / Human expression.');
}
$this->task->enabled = $this->isEnabled; $this->task->enabled = $this->isEnabled;
$this->task->name = str($this->name)->trim()->value(); $this->task->name = str($this->name)->trim()->value();
$this->task->command = str($this->command)->trim()->value(); $this->task->command = str($this->command)->trim()->value();
@ -109,7 +113,7 @@ public function submit()
$this->syncData(true); $this->syncData(true);
$this->dispatch('success', 'Scheduled task updated.'); $this->dispatch('success', 'Scheduled task updated.');
} catch (\Exception $e) { } catch (\Exception $e) {
return handleError($e); return handleError($e, $this);
} }
} }