From 38a187b93ebe1069f105ccd7570b7bb6ab38fc50 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Thu, 11 Feb 2016 22:19:56 +0100 Subject: [PATCH] Delete orphan files maintenance script When deleting a profile it'll delete its notices and the coupling to file entries, but not the file entries themselves (and thus not the files). So if one to delete a person uploading offending images, then the images are left behind and can be hotlinked. This will remove it. --- scripts/delete_orphan_files.php | 66 +++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 scripts/delete_orphan_files.php diff --git a/scripts/delete_orphan_files.php b/scripts/delete_orphan_files.php new file mode 100755 index 0000000000..ad575187bd --- /dev/null +++ b/scripts/delete_orphan_files.php @@ -0,0 +1,66 @@ +#!/usr/bin/env php +. + */ + +define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); + +$shortoptions = 'y'; +$longoptions = array('yes'); + +$helptext = <<query($sql) !== false) { + print " Deleting {$file->N} entries: "; + while ($file->fetch()) { + try { + $file->getPath(); + $file->delete(); + print 'x'; + } catch (Exception $e) { + // either FileNotFound exception or ClientException + $file->delete(); + print '.'; + } + } +} +print "\nDONE.\n";