diff --git a/lib/classes/task/file_temp_cleanup_task.php b/lib/classes/task/file_temp_cleanup_task.php index 0b0253ac3b2..7166872e660 100644 --- a/lib/classes/task/file_temp_cleanup_task.php +++ b/lib/classes/task/file_temp_cleanup_task.php @@ -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); + } + } }