Add rcc command
continuous-integration/drone/push Build is passing Details

This commit is contained in:
philipp lang 2024-09-28 01:31:05 +02:00
parent eee6b86e15
commit 9f787646c4
3 changed files with 60 additions and 7 deletions

View File

@ -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) {

View File

@ -56,5 +56,4 @@ class CacheManager
return $this->tagGenerator->singleFile($path, $size);
}
}

View File

@ -0,0 +1,52 @@
<?php
namespace Aweos\Resizer\Console;
use Aweos\Resizer\Classes\CacheManager;
use Aweos\Resizer\Lib\StorageMediaPath;
use Illuminate\Console\Command;
use Storage;
use Symfony\Component\Console\Input\InputArgument;
class ResizeCacheClear extends Command
{
/**
* @var string The console command name.
*/
protected $name = 'rcc';
/**
* @var string The console command description.
*/
protected $description = 'Clears cache for a specific file';
/**
* Execute the console command.
* @return void
*/
public function handle()
{
$path = new StorageMediaPath($this->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 [];
}
}