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/Commands/ResizeImagesCommand.php b/src/Commands/ResizeImagesCommand.php index 2145564..a258e5e 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,7 +41,14 @@ public function handle(ResizesImages $resizesImages): int $progress->start(); while ($batch->pendingJobs && ! $batch->finished() && ! $batch->cancelled()) { - $batch = $batch->fresh(); + /** @var mixed $refreshed */ + $refreshed = $batch->fresh(); + + if (! $refreshed instanceof Batch) { + break; + } + + $batch = $refreshed; $progress->setProgress($batch->processedJobs()); } 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;