From 0eaf3ddaa0801c96dee2059c7aab3551c6ace470 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jer=C3=B4me=20Bakker?= Date: Fri, 20 Dec 2024 10:17:04 +0100 Subject: [PATCH] fix(cron): the event param 'dt' can no longer be modified by callbacks --- engine/classes/Elgg/Cron.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/engine/classes/Elgg/Cron.php b/engine/classes/Elgg/Cron.php index fd24267137..37fcbca6eb 100644 --- a/engine/classes/Elgg/Cron.php +++ b/engine/classes/Elgg/Cron.php @@ -60,7 +60,7 @@ public function run(array $intervals = null, bool $force = false): array { $allowed_intervals = $this->getConfiguredIntervals(); $scheduler = new Scheduler(); - $time = $this->getCurrentTime(); + $time = \DateTimeImmutable::createFromInterface($this->getCurrentTime()); foreach ($intervals as $interval) { if (!array_key_exists($interval, $allowed_intervals)) { @@ -88,19 +88,19 @@ public function run(array $intervals = null, bool $force = false): array { }); } - return $scheduler->run($time); + return $scheduler->run(\DateTime::createFromInterface($time)); } /** * Execute commands before cron interval is run * - * @param string $interval Interval name - * @param \Elgg\Logger\Cron $cron_logger Cron logger - * @param null|\DateTime $time Time of the cron initialization (default: current service time) + * @param string $interval Interval name + * @param \Elgg\Logger\Cron $cron_logger Cron logger + * @param null|\DateTimeInterface $time Time of the cron initialization (default: current service time) * * @return void */ - protected function before(string $interval, \Elgg\Logger\Cron $cron_logger, \DateTime $time = null): void { + protected function before(string $interval, \Elgg\Logger\Cron $cron_logger, \DateTimeInterface $time = null): void { if (!isset($time)) { $time = $this->getCurrentTime(); } @@ -123,14 +123,14 @@ protected function before(string $interval, \Elgg\Logger\Cron $cron_logger, \Dat /** * Execute handlers attached to a specific cron interval * - * @param string $interval Cron interval to execute - * @param \Elgg\Logger\Cron $cron_logger Cron logger - * @param string $filename Filename of the cron log - * @param null|\DateTime $time Time of cron initialization (default: current service time) + * @param string $interval Cron interval to execute + * @param \Elgg\Logger\Cron $cron_logger Cron logger + * @param string $filename Filename of the cron log + * @param null|\DateTimeInterface $time Time of cron initialization (default: current service time) * * @return string */ - protected function execute(string $interval, \Elgg\Logger\Cron $cron_logger, string $filename, \DateTime $time = null): string { + protected function execute(string $interval, \Elgg\Logger\Cron $cron_logger, string $filename, \DateTimeInterface $time = null): string { if (!isset($time)) { $time = $this->getCurrentTime(); } @@ -297,12 +297,12 @@ public function getConfiguredIntervals(bool $only_names = false): array { /** * Get a filename to log in * - * @param string $interval cron interval to log - * @param \DateTime|null $time start time of the cron + * @param string $interval cron interval to log + * @param \DateTimeInterface|null $time start time of the cron * * @return string */ - protected function getLogFilename(string $interval, \DateTime $time = null): string { + protected function getLogFilename(string $interval, \DateTimeInterface $time = null): string { if (!isset($time)) { $time = $this->getCurrentTime(); }