Files
shopit-back/database/seeders/TestEventsSeeder.php
ncoronel c90a393081 feat: Optimize image handling for OnTicket tenant
- 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.
2026-09-22 10:01:05 -03:00

111 lines
4.4 KiB
PHP

<?php
namespace Database\Seeders;
use App\Domains\Core\Tenant\Models\Tenant;
use App\Shared\Attachable\Services\AttachmentService;
use Illuminate\Database\Seeder;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\DB;
use RuntimeException;
class TestEventsSeeder extends Seeder
{
private const IMAGE_DIRECTORY = 'images/tennants/onticket_otpimizado/test-events';
public function __construct(private readonly AttachmentService $attachmentService) {}
public function run(): void
{
$tenant = Tenant::query()->where('codigo', 'onticket')->firstOrFail();
$events = [
[
'title' => '[Prueba] Noche de Música en Vivo',
'category' => 'Música',
'subtitle' => 'Una noche para cantar y bailar',
'description' => 'Evento de prueba para explorar la cartelera de OnTicket.',
'location' => 'Teatro Broadway, Rosario',
'image' => 'live-music.avif',
'weeks_from_now' => [2],
'time_start' => '21:00:00',
'time_end' => '23:30:00',
],
[
'title' => '[Prueba] Festival de Sabores',
'category' => 'Otros',
'subtitle' => 'Gastronomía y música para toda la familia',
'description' => 'Evento de prueba con dos jornadas disponibles.',
'location' => 'Parque de España, Rosario',
'image' => 'food-festival.avif',
'weeks_from_now' => [3, 3],
'day_offsets' => [0, 1],
'time_start' => '12:00:00',
'time_end' => '20:00:00',
],
[
'title' => '[Prueba] Stand Up en el Centro',
'category' => 'Teatro',
'subtitle' => 'Humor para compartir',
'description' => 'Evento de prueba para visualizar distintas propuestas.',
'location' => 'Centro Cultural La Comedia, Rosario',
'image' => 'stand-up.avif',
'weeks_from_now' => [4],
'time_start' => '20:30:00',
'time_end' => '22:00:00',
],
];
DB::transaction(function () use ($tenant, $events): void {
foreach ($events as $definition) {
$event = $tenant->events()->firstOrCreate(
['title' => $definition['title']],
[
'subtitle' => $definition['subtitle'],
'description' => $definition['description'],
'location' => $definition['location'],
'published_at' => now(),
'event_category_id' => $tenant->eventCategories()
->where('nombre', $definition['category'])->value('id'),
],
);
if ($event->event_category_id === null) {
$event->update(['event_category_id' => $tenant->eventCategories()
->where('nombre', $definition['category'])->value('id')]);
}
if ($event->attachment_id === null) {
$path = public_path(self::IMAGE_DIRECTORY.'/'.$definition['image']);
if (! is_file($path)) {
throw new RuntimeException("Image not found at path: {$path}");
}
$attachment = $this->attachmentService->store(
new UploadedFile($path, $definition['image'], 'image/avif', null, true),
'tenants/onticket/events',
);
$event->update(['attachment_id' => $attachment->id]);
}
if ($event->dates()->exists()) {
continue;
}
foreach ($definition['weeks_from_now'] as $index => $weeks) {
$date = now()->startOfDay()->addWeeks($weeks)
->addDays($definition['day_offsets'][$index] ?? 0);
$event->dates()->create([
'tenant_code' => $tenant->codigo,
'date' => $date->toDateString(),
'time_start' => $definition['time_start'],
'time_end' => $definition['time_end'],
]);
}
}
});
}
}