Skip to content

Commit

Permalink
Use deleteFoldersByIds()
Browse files Browse the repository at this point in the history
brandonkelly committed Jan 4, 2025
1 parent 6b93f17 commit feb3f22
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/services/Gc.php
Original file line number Diff line number Diff line change
@@ -346,8 +346,8 @@ public function removeEmptyTempFolders(): void
{
$this->_stdout(' > removing empty temp folders ... ');

$emptyFolders = (new Query())
->select(['folders.id', 'folders.path'])
$emptyFolderIds = (new Query())
->select(['folders.id'])
->from(['folders' => Table::VOLUMEFOLDERS])
->leftJoin(['assets' => Table::ASSETS], '[[assets.folderId]] = [[folders.id]]')
->where([
@@ -356,17 +356,12 @@ public function removeEmptyTempFolders(): void
])
->andWhere(['not', ['folders.parentId' => null]])
->andWhere(['not', ['folders.path' => null]])
->pairs();

$fs = Craft::createObject(Temp::class);
->column();

foreach ($emptyFolders as $emptyFolderPath) {
if ($fs->directoryExists($emptyFolderPath)) {
$fs->deleteDirectory($emptyFolderPath);
}
if (!empty($emptyFolderIds)) {
Craft::$app->getAssets()->deleteFoldersByIds($emptyFolderIds);
}

VolumeFolder::deleteAll(['id' => array_keys($emptyFolders)]);
$this->_stdout("done\n", Console::FG_GREEN);
}

0 comments on commit feb3f22

Please sign in to comment.