From 1da6e8199205013352b8b88ec296b8142def2a07 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sat, 11 May 2024 13:56:22 +0200 Subject: [PATCH] Delete orphaned files --- com.woltlab.wcf/cronjob.xml | 6 +++ .../cronjob/FileCleanUpCronjob.class.php | 37 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 wcfsetup/install/files/lib/system/cronjob/FileCleanUpCronjob.class.php diff --git a/com.woltlab.wcf/cronjob.xml b/com.woltlab.wcf/cronjob.xml index f60b2607fbb..e1c76816e11 100644 --- a/com.woltlab.wcf/cronjob.xml +++ b/com.woltlab.wcf/cronjob.xml @@ -35,6 +35,12 @@ Löscht verwaiste Dateianhänge 0 2 * * * + + wcf\system\cronjob\FileCleanUpCronjob + Deletes orphaned files + Löscht verwaiste Dateien + 0 3 * * * + wcf\system\cronjob\BackgroundQueueCleanUpCronjob Requeues stuck queue items diff --git a/wcfsetup/install/files/lib/system/cronjob/FileCleanUpCronjob.class.php b/wcfsetup/install/files/lib/system/cronjob/FileCleanUpCronjob.class.php new file mode 100644 index 00000000000..3df780e0dfb --- /dev/null +++ b/wcfsetup/install/files/lib/system/cronjob/FileCleanUpCronjob.class.php @@ -0,0 +1,37 @@ + + * @since 6.1 + */ +class FileCleanUpCronjob extends AbstractCronjob +{ + #[\Override] + public function execute(Cronjob $cronjob) + { + parent::execute($cronjob); + + $sql = "SELECT fileID + FROM wcf1_file + WHERE objectTypeID IS NULL"; + $statement = WCF::getDB()->prepare($sql, 1_000); + $statement->execute(); + $fileIDs = $statement->fetchAll(\PDO::FETCH_COLUMN); + + if ($fileIDs === []) { + return; + } + + FileEditor::deleteAll($fileIDs); + } +}