Skip to content

Commit

Permalink
Merge branch 'MDL-67635-filesystem-cleanup' of https://github.com/bre…
Browse files Browse the repository at this point in the history
  • Loading branch information
sarjona committed Feb 11, 2020
2 parents c002fbf + 2d98ebb commit 799c395
Showing 1 changed file with 9 additions and 25 deletions.
34 changes: 9 additions & 25 deletions lib/filestorage/file_storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2208,35 +2208,19 @@ public function cron() {
$rs->close();
mtrace('done.');

// remove orphaned preview files (that is files in the core preview filearea without
// the existing original file)
mtrace('Deleting orphaned preview files... ', '');
// Remove orphaned files:
// * preview files in the core preview filearea without the existing original file.
// * document converted files in core documentconversion filearea without the existing original file.
mtrace('Deleting orphaned preview, and document conversion files... ', '');
cron_trace_time_and_memory();
$sql = "SELECT p.*
FROM {files} p
LEFT JOIN {files} o ON (p.filename = o.contenthash)
WHERE p.contextid = ? AND p.component = 'core' AND p.filearea = 'preview' AND p.itemid = 0
AND o.id IS NULL";
$syscontext = context_system::instance();
$rs = $DB->get_recordset_sql($sql, array($syscontext->id));
foreach ($rs as $orphan) {
$file = $this->get_file_instance($orphan);
if (!$file->is_directory()) {
$file->delete();
}
}
$rs->close();
mtrace('done.');

// Remove orphaned converted files (that is files in the core documentconversion filearea without
// the existing original file).
mtrace('Deleting orphaned document conversion files... ', '');
cron_trace_time_and_memory();
$sql = "SELECT p.*
FROM {files} p
LEFT JOIN {files} o ON (p.filename = o.contenthash)
WHERE p.contextid = ? AND p.component = 'core' AND p.filearea = 'documentconversion' AND p.itemid = 0
AND o.id IS NULL";
WHERE p.contextid = ?
AND p.component = 'core'
AND (p.filearea = 'preview' OR p.filearea = 'documentconversion')
AND p.itemid = 0
AND o.id IS NULL";
$syscontext = context_system::instance();
$rs = $DB->get_recordset_sql($sql, array($syscontext->id));
foreach ($rs as $orphan) {
Expand Down

0 comments on commit 799c395

Please sign in to comment.