Skip to content

Commit

Permalink
fix(cron): the event param 'dt' can no longer be modified by callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
jeabakker committed Dec 20, 2024
1 parent c226b84 commit 0eaf3dd
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions engine/classes/Elgg/Cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 0eaf3dd

Please sign in to comment.