Skip to content
This repository was archived by the owner on Nov 3, 2023. It is now read-only.

Commit 49679df

Browse files
binfalseleofeyer
authored andcommitted
Always refresh the cron.txt file (see #8838)
Description ----------- `cron.txt` contains the timestamp of the last cron run. The file is **only** updated with the current timestamp once cron is actually executed. However, with Docker use cases you may throw away a container any time and start from a clean Contao instance (eg in case of updates, migrations etc), only mounting/linking persistent stuff into the container. Therefore, the next cron run may only be in a few hours (database still knows `lastrun`), and the `cron.txt` is not created... Thus, every browser request will always entail an ugly `404`, until the next cron run... This patch will always write the `cron.txt` containing: * the current timestamp, if cron is really executed * the timestamp from the database, otherwise Writing the `cron.txt` even if it already exists shouldn't be a big deal..? See also Docker image at: https://hub.docker.com/r/binfalse/contao/ Commits ------- 754d366 always refresh cron.txt eacb91d moved the `updateCronTxt` call behind `unlockTables` b76ef9c Add the issue reference in the comment
1 parent 9d7f3d5 commit 49679df

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

system/modules/core/controllers/FrontendCron.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -135,20 +135,25 @@ protected function hasToWait()
135135
// Add the cron entry
136136
if ($objCron->numRows < 1)
137137
{
138-
$this->updateCronTxt($time);
139138
$this->Database->query("INSERT INTO tl_cron (name, value) VALUES ('lastrun', $time)");
140139
$return = false;
141140
}
142141

143142
// Check the last execution time
144143
elseif ($objCron->value <= ($time - $this->getCronTimeout()))
145144
{
146-
$this->updateCronTxt($time);
147145
$this->Database->query("UPDATE tl_cron SET value=$time WHERE name='lastrun'");
148146
$return = false;
149147
}
150148

149+
// Make sure the cron.txt file contains the correct time (see #8838)
150+
else
151+
{
152+
$time = $objCron->value;
153+
}
154+
151155
$this->Database->unlockTables();
156+
$this->updateCronTxt($time);
152157

153158
return $return;
154159
}

0 commit comments

Comments
 (0)