Co-authored-by: manoel freitas <manoel.josefneto@gmail.com> Co-committed-by: manoel freitas <manoel.josefneto@gmail.com>
98 lines
3.0 KiB
PHP
98 lines
3.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\PortfolioCase;
|
|
use App\Models\PortfolioImage;
|
|
use App\Models\Service;
|
|
use App\Models\SiteSetting;
|
|
use App\Models\Testimonial;
|
|
use App\Support\PublicImageUploadRules;
|
|
use App\Support\ResponsiveImage;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
final class MediaGenerateVariantsCommand extends Command
|
|
{
|
|
protected $signature = 'media:generate-variants';
|
|
|
|
protected $description = 'Generate responsive image variants for existing public media';
|
|
|
|
public function handle(): int
|
|
{
|
|
$disk = PublicImageUploadRules::disk();
|
|
$paths = $this->collectPaths();
|
|
$generated = 0;
|
|
$skipped = 0;
|
|
|
|
foreach ($paths as $path) {
|
|
if (! Storage::disk($disk)->exists($path)) {
|
|
ResponsiveImage::forgetMetadata($path, $disk);
|
|
$this->warn("Missing file: {$path}");
|
|
$skipped++;
|
|
|
|
continue;
|
|
}
|
|
|
|
ResponsiveImage::generate($path, $disk);
|
|
$generated++;
|
|
$this->line("Generated variants for {$path}");
|
|
}
|
|
|
|
$this->info("Done. Generated: {$generated}. Skipped: {$skipped}.");
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
|
|
/**
|
|
* @return list<string>
|
|
*/
|
|
private function collectPaths(): array
|
|
{
|
|
$paths = [];
|
|
|
|
$settings = SiteSetting::query()->first();
|
|
if ($settings && filled($settings->default_og_image_path)) {
|
|
$paths[] = (string) $settings->default_og_image_path;
|
|
}
|
|
if ($settings && filled($settings->hero_image_path)) {
|
|
$paths[] = (string) $settings->hero_image_path;
|
|
}
|
|
if ($settings && filled($settings->about_image_path)) {
|
|
$paths[] = (string) $settings->about_image_path;
|
|
}
|
|
if ($settings && filled($settings->founder_image_path)) {
|
|
$paths[] = (string) $settings->founder_image_path;
|
|
}
|
|
if ($settings && filled($settings->hero_image_path)) {
|
|
$paths[] = (string) $settings->hero_image_path;
|
|
}
|
|
if ($settings && filled($settings->services_hero_image_path)) {
|
|
$paths[] = (string) $settings->services_hero_image_path;
|
|
}
|
|
if ($settings && filled($settings->portfolio_hero_image_path)) {
|
|
$paths[] = (string) $settings->portfolio_hero_image_path;
|
|
}
|
|
|
|
foreach (Service::query()->whereNotNull('cover_image_path')->pluck('cover_image_path') as $path) {
|
|
$paths[] = (string) $path;
|
|
}
|
|
|
|
foreach (PortfolioCase::query()->whereNotNull('cover_image_path')->pluck('cover_image_path') as $path) {
|
|
$paths[] = (string) $path;
|
|
}
|
|
|
|
foreach (PortfolioImage::query()->whereNotNull('path')->pluck('path') as $path) {
|
|
$paths[] = (string) $path;
|
|
}
|
|
|
|
foreach (Testimonial::query()->whereNotNull('photo_path')->pluck('photo_path') as $path) {
|
|
$paths[] = (string) $path;
|
|
}
|
|
|
|
return array_values(array_unique($paths));
|
|
}
|
|
}
|