oc-resizer-plugin/console/ResizePurge.php

68 lines
1.5 KiB
PHP
Raw Normal View History

2019-09-17 23:14:29 +02:00
<?php namespace Aweos\Resizer\Console;
use Storage;
use Illuminate\Console\Command;
use System\Classes\MediaLibrary;
use Aweos\Resizer\Models\Setting;
use October\Rain\Database\Attach\Resizer;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class ResizePurge extends Command
{
/**
* @var string The console command name.
*/
protected $name = 'resize:purge';
/**
* @var string The console command description.
*/
protected $description = 'Drops all resized images';
/**
* Execute the console command.
* @return void
*/
public function handle()
{
$folders = Setting::get('folders');
$sizes = Setting::get('srcx');
foreach($folders as $folder) {
$f = '/'.rtrim(ltrim($folder['folder'], '/'), '/');
$this->start($f, $sizes);
}
}
public function start($f, $sizes) {
$l = MediaLibrary::instance();
$folders = array_filter(\Storage::allDirectories('media/'.$f), function($item) use ($f) {
return pathinfo($item, PATHINFO_FILENAME) == 'c';
});
foreach ($folders as $folder) {
\Storage::deleteDirectory($folder);
}
}
/**
* Get the console command arguments.
* @return array
*/
protected function getArguments()
{
return [];
}
/**
* Get the console command options.
* @return array
*/
protected function getOptions()
{
return [];
}
}