option('only') !== 'og') { $this->error('Derzeit wird nur --only=og unterstützt.'); return self::FAILURE; } $query = PressReleaseImage::query() ->with(['pressRelease' => fn ($q) => $q->withoutGlobalScope(PortalScope::class)->with('company')]) ->orderBy('id'); if ($this->option('published')) { $query->whereHas('pressRelease', fn ($q) => $q->withoutGlobalScope(PortalScope::class)->where('status', 'published')); } if (! $this->option('force')) { $query->where(function ($q): void { $q->whereNull('variants')->orWhereNull('variants->og'); }); } $total = $query->count(); $limit = (int) $this->option('limit'); $execute = (bool) $this->option('execute'); $this->info(($execute ? 'Erzeuge' : 'Trockenlauf:').' OG-Varianten für '.($limit > 0 ? min($limit, $total) : $total).' von '.$total.' Bildern.'); if (! $execute) { return self::SUCCESS; } $done = 0; $skipped = 0; $query->chunkById(200, function ($images) use (&$done, &$skipped, $limit): bool { foreach ($images as $image) { if ($limit > 0 && $done >= $limit) { return false; } $caption = $image->pressRelease ? ImageCredit::for($image, $image->pressRelease->company)->line() : null; $path = $this->imageService->regenerateOgVariant( $image->disk, $image->variants, $image->path, $image->focus_x !== null && $image->focus_y !== null ? ['x' => $image->focus_x, 'y' => $image->focus_y] : null, (bool) $image->no_crop, $caption, ); if ($path === null) { $skipped++; continue; } $image->forceFill(['variants' => array_merge((array) $image->variants, ['og' => $path])])->saveQuietly(); $done++; } return true; }); $this->info("OG-Varianten erzeugt: {$done}, übersprungen (keine Quelle): {$skipped}."); return self::SUCCESS; } }