Skip to content

Commit

Permalink
Delete orphaned files
Browse files Browse the repository at this point in the history
  • Loading branch information
dtdesign committed May 11, 2024
1 parent 41848cd commit fdb689f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
6 changes: 6 additions & 0 deletions com.woltlab.wcf/cronjob.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
<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>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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);
}
}

0 comments on commit fdb689f

Please sign in to comment.