From 9f787646c4e549b74aa57e31278c43a51d063881 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Sat, 28 Sep 2024 01:31:05 +0200 Subject: [PATCH] Add rcc command --- Plugin.php | 12 +++++---- classes/CacheManager.php | 3 +-- console/ResizeCacheClear.php | 52 ++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 console/ResizeCacheClear.php diff --git a/Plugin.php b/Plugin.php index a4b3a7c..5cdf5fe 100644 --- a/Plugin.php +++ b/Plugin.php @@ -4,6 +4,7 @@ namespace Aweos\Resizer; use Aweos\Resizer\Classes\CacheManager; use Aweos\Resizer\Classes\ImageResizer; +use Aweos\Resizer\Console\ResizeCacheClear; use Aweos\Resizer\Console\ResizeMake; use Aweos\Resizer\Console\ResizePurge; use Aweos\Resizer\Jobs\DeleteJob; @@ -47,6 +48,7 @@ class Plugin extends PluginBase { $this->registerConsoleCommand('resizer.resizemake', ResizeMake::class); $this->registerConsoleCommand('resizer.resizepurge', ResizePurge::class); + $this->registerConsoleCommand('resizer.resize-cache-clear', ResizeCacheClear::class); } /** @@ -58,7 +60,7 @@ class Plugin extends PluginBase { app()->bind(ImageResizer::class, function () { $disk = (new File())->getDisk(); - $dir = (new File(['is_public' => true]))->getStorageDirectory().'c/'; + $dir = (new File(['is_public' => true]))->getStorageDirectory() . 'c/'; $media = MediaLibrary::instance(); return new ImageResizer($disk, $dir, $media); @@ -67,11 +69,11 @@ class Plugin extends PluginBase app()->bind('resize', fn () => app(CacheManager::class)); Event::listen('media.folder.create', function ($widget, string $folder) { - $folder = '/'.trim($folder, '/'); + $folder = '/' . trim($folder, '/'); $pathinfo = pathinfo($folder); if ('/' === $pathinfo['dirname']) { - $sluggedFolder = '/'.StorageMediaPath::sluggifyString(trim($folder, '/')); + $sluggedFolder = '/' . StorageMediaPath::sluggifyString(trim($folder, '/')); if ($sluggedFolder !== $folder) { if (MediaLibrary::instance()->folderExists($sluggedFolder)) { MediaLibrary::instance()->deleteFolder($folder); @@ -80,7 +82,7 @@ class Plugin extends PluginBase MediaLibrary::instance()->moveFolder($folder, $sluggedFolder); } } else { - $sluggedFolder = $pathinfo['dirname'].'/'.StorageMediaPath::sluggifyString($pathinfo['filename']); + $sluggedFolder = $pathinfo['dirname'] . '/' . StorageMediaPath::sluggifyString($pathinfo['filename']); if ($sluggedFolder !== $folder) { if (MediaLibrary::instance()->folderExists($sluggedFolder)) { MediaLibrary::instance()->deleteFolder($folder); @@ -104,7 +106,7 @@ class Plugin extends PluginBase }); Event::listen('media.file.move', function ($widget, $old, $new) { if ((new StorageMediaPath($new))->shouldProcess() || (new StorageMediaPath($old))->shouldProcess()) { - Queue::push(MoveJob::class, [$old, $new.'/'.pathinfo($old, PATHINFO_FILENAME)], Setting::get('queue')); + Queue::push(MoveJob::class, [$old, $new . '/' . pathinfo($old, PATHINFO_FILENAME)], Setting::get('queue')); } }); Event::listen('media.file.rename', function ($widget, $old, $new) { diff --git a/classes/CacheManager.php b/classes/CacheManager.php index 8c5c542..d5f88bd 100644 --- a/classes/CacheManager.php +++ b/classes/CacheManager.php @@ -12,7 +12,7 @@ class CacheManager public TagGenerator $tagGenerator; private string $tagAll = 'resizer'; - public function __construct(TagGenerator $tagGenerator) + public function __construct(TagGenerator $tagGenerator) { $this->tagGenerator = $tagGenerator; } @@ -56,5 +56,4 @@ class CacheManager return $this->tagGenerator->singleFile($path, $size); } - } diff --git a/console/ResizeCacheClear.php b/console/ResizeCacheClear.php new file mode 100644 index 0000000..68520b3 --- /dev/null +++ b/console/ResizeCacheClear.php @@ -0,0 +1,52 @@ +argument('path')); + app(CacheManager::class)->delete($path); + } + + /** + * Get the console command arguments. + * @return array + */ + protected function getArguments() + { + return [ + ['path', InputArgument::REQUIRED, 'The path on the storage'], + ]; + } + + /** + * Get the console command options. + * @return array + */ + protected function getOptions() + { + return []; + } +}