<description language="de">Löscht verwaiste Dateianhänge</description>
<expression>0 2 * * *</expression>
</cronjob>
+ <cronjob name="com.woltlab.wcf.fileCleanUp">
+ <classname>wcf\system\cronjob\FileCleanUpCronjob</classname>
+ <description>Deletes orphaned files</description>
+ <description language="de">Löscht verwaiste Dateien</description>
+ <expression>0 3 * * *</expression>
+ </cronjob>
<cronjob name="com.woltlab.wcf.backgroundQueueCleanUp">
<classname>wcf\system\cronjob\BackgroundQueueCleanUpCronjob</classname>
<description>Requeues stuck queue items</description>
--- /dev/null
+<?php
+
+namespace wcf\system\cronjob;
+
+use wcf\data\cronjob\Cronjob;
+use wcf\data\file\FileEditor;
+use wcf\system\WCF;
+
+/**
+ * Deletes orphaned files.
+ *
+ * @author Alexander Ebert
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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);
+ }
+}