Skip to content

Commit

Permalink
Add winter:util purge resized console command (#1186)
Browse files Browse the repository at this point in the history
Console command to purge all entries in resized storage folder.
  • Loading branch information
mjauvin committed Aug 19, 2024
1 parent a03fe11 commit 732ca41
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions modules/system/console/WinterUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
*
* Currently supported commands:
*
* - purge resized: Deletes all files in the resized directory.
* - purge thumbs: Deletes all thumbnail files in the uploads directory.
* - purge uploads: Deletes files in the uploads directory that do not exist in the "system_files" table.
* - git pull: Perform "git pull" on all plugins and themes.
* - compile assets: Compile registered Language, LESS and JS files.
* - compile js: Compile registered JS files only.
Expand Down Expand Up @@ -253,6 +255,28 @@ protected function utilCompileLang()
}
}

protected function utilPurgeResized()
{
if (!$this->confirmToProceed('This will PERMANENTLY DELETE all files in the resized directory.')) {
return;
}

$resizedDisk = Config::get('cms.storage.resized.disk', 'local');
$resizedFolder = Config::get('cms.storage.resized.folder', 'resized');

$totalCount = count(Storage::disk($resizedDisk)->allFiles($resizedFolder));

foreach (Storage::disk($resizedDisk)->directories($resizedFolder, false) as $directory) {
Storage::disk($resizedDisk)->deleteDirectory($directory);
}

if ($totalCount > 0) {
$this->comment(sprintf('Successfully deleted %d file(s)', $totalCount));
} else {
$this->comment('No files found to purge.');
}
}

protected function utilPurgeThumbs()
{
if (!$this->confirmToProceed('This will PERMANENTLY DELETE all thumbs in the uploads directory.')) {
Expand Down

0 comments on commit 732ca41

Please sign in to comment.