From 3caed12785623cfe4756aa879c3f13d214dff3e9 Mon Sep 17 00:00:00 2001 From: Kevin Meijer Date: Fri, 29 May 2026 13:49:41 +0200 Subject: [PATCH 1/5] Added base package --- composer.json | 1 + src/ServiceProvider.php | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 02da9c4..3a6da86 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,7 @@ "php": "^8.4|^8.5", "ext-fileinfo": "*", "intervention/image": "^3.0", + "justbetter/statamic-base": "^1.0", "statamic/cms": "^6.0", "laravel/framework": "^12.0 | ^13.0", "league/glide": "^3.0" diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 83b38dd..90be3bf 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -68,10 +68,14 @@ public function boot(): void $this->bootPublishables() ->bootEvents() ->bootCommands() - ->bootNav() ->handleTranslations(); } + public function bootAddon(): void + { + $this->bootNav(); + } + public function bootEvents(): static { Event::listen([AssetUploaded::class, AssetReuploaded::class], AssetUploadedListener::class); @@ -103,10 +107,19 @@ protected function bootPublishables(): static protected function bootNav(): static { Nav::extend(function (Navigation $nav): void { - $nav->create('Image Optimize') - ->section('Tools') + $justBetter = $nav->find('Tools', 'JustBetter'); + + if (! $justBetter) { + return; + } + + $imageOptimize = $nav->item('Image Optimize') ->route('statamic-image-optimize.index') ->icon('insert-image'); + + $children = $justBetter->resolveChildren()->children() ?? collect(); + + $justBetter->children($children->push($imageOptimize)->all()); }); return $this; From fab133a67ef4fa7e06b83bcc74a5e8c9cef70e44 Mon Sep 17 00:00:00 2001 From: Kevin Meijer Date: Mon, 1 Jun 2026 16:46:04 +0200 Subject: [PATCH 2/5] Fixed phpstan error --- src/Commands/ResizeImagesCommand.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Commands/ResizeImagesCommand.php b/src/Commands/ResizeImagesCommand.php index 2145564..ce9ffba 100644 --- a/src/Commands/ResizeImagesCommand.php +++ b/src/Commands/ResizeImagesCommand.php @@ -41,6 +41,11 @@ public function handle(ResizesImages $resizesImages): int while ($batch->pendingJobs && ! $batch->finished() && ! $batch->cancelled()) { $batch = $batch->fresh(); + + if ($batch === null) { + break; + } + $progress->setProgress($batch->processedJobs()); } From 9843290bea4589d2dac4422d05fb9f0b8f86674d Mon Sep 17 00:00:00 2001 From: Kevin Meijer Date: Mon, 1 Jun 2026 16:52:50 +0200 Subject: [PATCH 3/5] Fixed phpstan error --- src/Commands/ResizeImagesCommand.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Commands/ResizeImagesCommand.php b/src/Commands/ResizeImagesCommand.php index ce9ffba..dcdf121 100644 --- a/src/Commands/ResizeImagesCommand.php +++ b/src/Commands/ResizeImagesCommand.php @@ -2,6 +2,7 @@ namespace JustBetter\ImageOptimize\Commands; +use Illuminate\Bus\Batch; use Illuminate\Console\Command; use Illuminate\Support\Facades\DB; use JustBetter\ImageOptimize\Contracts\ResizesImages; @@ -40,12 +41,13 @@ public function handle(ResizesImages $resizesImages): int $progress->start(); while ($batch->pendingJobs && ! $batch->finished() && ! $batch->cancelled()) { - $batch = $batch->fresh(); + $refreshed = $batch->fresh(); - if ($batch === null) { + if (! $refreshed instanceof Batch) { break; } + $batch = $refreshed; $progress->setProgress($batch->processedJobs()); } From 1c2107a48f17aee4e7286f2bcce133023dc66dbd Mon Sep 17 00:00:00 2001 From: Kevin Meijer Date: Mon, 1 Jun 2026 16:56:28 +0200 Subject: [PATCH 4/5] Fixed phpstan error --- src/Commands/ResizeImagesCommand.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Commands/ResizeImagesCommand.php b/src/Commands/ResizeImagesCommand.php index dcdf121..ad03390 100644 --- a/src/Commands/ResizeImagesCommand.php +++ b/src/Commands/ResizeImagesCommand.php @@ -41,9 +41,9 @@ public function handle(ResizesImages $resizesImages): int $progress->start(); while ($batch->pendingJobs && ! $batch->finished() && ! $batch->cancelled()) { - $refreshed = $batch->fresh(); + $refreshed = $this->freshBatch($batch); - if (! $refreshed instanceof Batch) { + if ($refreshed === null) { break; } @@ -62,4 +62,9 @@ public function handle(ResizesImages $resizesImages): int return static::SUCCESS; } + + private function freshBatch(Batch $batch): ?Batch + { + return $batch->fresh(); + } } From b1eca3a839d751c10b3b894715e6fcf9707b71f5 Mon Sep 17 00:00:00 2001 From: Kevin Meijer Date: Mon, 1 Jun 2026 17:02:08 +0200 Subject: [PATCH 5/5] Fixed phpstan error --- src/Commands/ResizeImagesCommand.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Commands/ResizeImagesCommand.php b/src/Commands/ResizeImagesCommand.php index ad03390..a258e5e 100644 --- a/src/Commands/ResizeImagesCommand.php +++ b/src/Commands/ResizeImagesCommand.php @@ -41,9 +41,10 @@ public function handle(ResizesImages $resizesImages): int $progress->start(); while ($batch->pendingJobs && ! $batch->finished() && ! $batch->cancelled()) { - $refreshed = $this->freshBatch($batch); + /** @var mixed $refreshed */ + $refreshed = $batch->fresh(); - if ($refreshed === null) { + if (! $refreshed instanceof Batch) { break; } @@ -62,9 +63,4 @@ public function handle(ResizesImages $resizesImages): int return static::SUCCESS; } - - private function freshBatch(Batch $batch): ?Batch - { - return $batch->fresh(); - } }