- Added migration to optimize OnTicket images using OptimizeOnticketImagesSeeder. - Updated OnTicketTenantSeeder to reference optimized image formats (AVIF). - Modified OnticketImmersiveHeroCarouselSeeder to use AVIF images for hero carousel. - Created OptimizeOnticketImagesSeeder to replace existing attachments with optimized images. - Adjusted TestEventsSeeder to utilize AVIF images for events. - Updated tests to verify the correct image formats and ensure optimized images are stored. - Added new image files in AVIF format for logos, backgrounds, and event images.
62 lines
2.0 KiB
PHP
62 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Domains\Core\Tenant\Models\Tenant;
|
|
use App\Domains\Core\Tenant\Services\WebsiteExtraService;
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Http\UploadedFile;
|
|
use RuntimeException;
|
|
|
|
class OnticketImmersiveHeroCarouselSeeder extends Seeder
|
|
{
|
|
private const IMAGE_DIRECTORY = 'images/tennants/onticket_otpimizado/onticket_tennant_hero_carousel';
|
|
|
|
private const IMAGES = [
|
|
'onticket_hero_carousel_1.avif',
|
|
'onticket_hero_carousel_2.avif',
|
|
'onticket_hero_carousel_3.avif',
|
|
'onticket_hero_carousel_4.avif',
|
|
'onticket_hero_carousel_5.avif',
|
|
'onticket_hero_carousel_6.avif',
|
|
'onticket_hero_carousel_7.avif',
|
|
'onticket_hero_carousel_8.avif',
|
|
];
|
|
|
|
public function __construct(private readonly WebsiteExtraService $websiteExtraService) {}
|
|
|
|
public function run(): void
|
|
{
|
|
$tenant = Tenant::query()->where('codigo', 'onticket')->first();
|
|
|
|
if ($tenant?->storefront_website_type_code !== 'onticket_multi_event') {
|
|
return;
|
|
}
|
|
|
|
if ($tenant->websiteExtras()->whereHas(
|
|
'websiteTypeExtra',
|
|
fn ($query) => $query->where('codigo', 'immersiveHeroCarousel')
|
|
)->exists()) {
|
|
return;
|
|
}
|
|
|
|
$images = array_map(function (string $filename): UploadedFile {
|
|
$path = public_path(self::IMAGE_DIRECTORY."/{$filename}");
|
|
|
|
if (! is_file($path)) {
|
|
throw new RuntimeException("Image not found at path: {$path}");
|
|
}
|
|
|
|
$mimeType = match (strtolower(pathinfo($filename, PATHINFO_EXTENSION))) {
|
|
'jpg', 'jpeg', 'jfif' => 'image/jpeg',
|
|
'avif' => 'image/avif',
|
|
default => 'image/png',
|
|
};
|
|
|
|
return new UploadedFile($path, $filename, $mimeType, null, true);
|
|
}, self::IMAGES);
|
|
|
|
$this->websiteExtraService->updateForTenant($tenant, 'immersiveHeroCarousel', $images);
|
|
}
|
|
}
|