MDL-60923 scheduled tasks: stale temp files in $CFG->backuptempdir too

This commit is contained in:
Matteo Scaramuccia 2018-04-03 21:58:21 +02:00
parent ef844148a9
commit 40d90f438a

View File

@ -38,13 +38,13 @@ class file_temp_cleanup_task extends scheduled_task {
}
/**
* Do the job.
* Throw exceptions on errors (the job will be retried).
* Do the job, given the target directory.
*
* @param string $tmpdir The directory hosting the candidate stale temp files.
*/
public function execute() {
protected function execute_on($tmpdir) {
global $CFG;
$tmpdir = $CFG->tempdir;
// Default to last weeks time.
$time = time() - ($CFG->tempdatafoldercleanup * 3600);
@ -96,4 +96,23 @@ class file_temp_cleanup_task extends scheduled_task {
}
}
/**
* Do the job.
* Throw exceptions on errors (the job will be retried).
*/
public function execute() {
global $CFG;
// The directories hosting the candidate stale temp files eventually are $CFG->tempdir and $CFG->backuptempdir.
// Do the job on each of the directories above.
// Let's start with $CFG->tempdir.
$this->execute_on($CFG->tempdir);
// Run on $CFG->backuptempdir too, if different from the default one, '$CFG->tempdir/backup'.
if (realpath(dirname($CFG->backuptempdir)) !== $CFG->tempdir) {
// The $CFG->backuptempdir setting is different from the default '$CFG->tempdir/backup'.
$this->execute_on($CFG->backuptempdir);
}
}
}