115 lines
4.6 KiB
PHP
115 lines
4.6 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Domains\Core\Client\Models\Client;
|
|
use App\Domains\Core\Tenant\Models\AdminWebsiteType;
|
|
use App\Domains\Core\Tenant\Models\Tenant;
|
|
use App\Domains\Core\Tenant\Services\TenantProvisioningService;
|
|
use App\Domains\Core\Tenant\Services\WebsiteExtraService;
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Http\UploadedFile;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use RuntimeException;
|
|
|
|
class OnTicketTenantSeeder extends Seeder
|
|
{
|
|
public function __construct(
|
|
private readonly TenantProvisioningService $tenantProvisioningService,
|
|
private readonly WebsiteExtraService $websiteExtraService,
|
|
private readonly OnticketImmersiveHeroCarouselSeeder $carouselSeeder,
|
|
) {}
|
|
|
|
public function run(): void
|
|
{
|
|
$client = Client::query()->firstOrCreate(
|
|
['code' => 'onticket'],
|
|
['name' => 'OnTicket'],
|
|
);
|
|
$type = AdminWebsiteType::query()->where('codigo', 'onticket')->firstOrFail();
|
|
$tenant = Tenant::query()->where('codigo', 'onticket')->first();
|
|
|
|
if ($tenant === null) {
|
|
$tenant = $this->tenantProvisioningService->create([
|
|
'client_id' => $client->id,
|
|
'codigo' => 'onticket',
|
|
'nombre' => $type->nombre,
|
|
'dominio' => $type->dominio,
|
|
'site_title' => $type->site_title,
|
|
'primary_color' => $type->primary_color,
|
|
'secondary_color' => $type->secondary_color,
|
|
'danger_color' => $type->danger_color,
|
|
'success_color' => $type->success_color,
|
|
'header_bg_color' => $type->surface_color,
|
|
'footer_bg_color' => $type->primary_color,
|
|
'display_categories' => true,
|
|
'display_seach_bar' => true,
|
|
'admin_website_type_code' => $type->codigo,
|
|
'storefront_website_type_code' => 'onticket_multi_event',
|
|
'header_logo' => $this->uploadedImage('onticket_logo.png'),
|
|
'footer_logo' => $this->uploadedImage('onticket_footer_logo.png'),
|
|
'favicon' => $this->uploadedImage('onticket_favicon.svg'),
|
|
'header_bg_image' => $this->uploadedImage('onticket_header_background.png'),
|
|
]);
|
|
} else {
|
|
$tenant->update([
|
|
'client_id' => $client->id,
|
|
'storefront_website_type_code' => 'onticket_multi_event',
|
|
'display_categories' => true,
|
|
'display_seach_bar' => true,
|
|
]);
|
|
|
|
$missingImages = [];
|
|
foreach ([
|
|
'header_logo' => ['relation' => 'headerLogo', 'filename' => 'onticket_logo.png'],
|
|
'footer_logo' => ['relation' => 'footerLogo', 'filename' => 'onticket_footer_logo.png'],
|
|
'favicon' => ['relation' => 'favicon', 'filename' => 'onticket_favicon.svg'],
|
|
'header_bg_image' => ['relation' => 'headerBackgroundImage', 'filename' => 'onticket_header_background.png'],
|
|
] as $field => $image) {
|
|
$attachment = $tenant->{$image['relation']};
|
|
|
|
if ($attachment === null || ! Storage::disk('s3')->exists($attachment->path)) {
|
|
$missingImages[$field] = $this->uploadedImage($image['filename']);
|
|
}
|
|
}
|
|
|
|
if ($missingImages !== []) {
|
|
$tenant = $this->tenantProvisioningService->update($tenant, $missingImages);
|
|
}
|
|
}
|
|
|
|
foreach (['Música', 'Teatro', 'Deportes', 'Infantiles', 'Otros'] as $name) {
|
|
$tenant->eventCategories()->firstOrCreate(['nombre' => $name]);
|
|
}
|
|
|
|
if (! $tenant->websiteExtras()->whereHas(
|
|
'websiteTypeExtra',
|
|
fn ($query) => $query->where('codigo', 'immersiveHero')
|
|
)->exists()) {
|
|
$this->websiteExtraService->updateForTenant($tenant, 'immersiveHero', [
|
|
'eyebrow' => 'Encendé tu',
|
|
'title' => 'experiencia',
|
|
'description' => 'Reservá tu entrada y formá parte',
|
|
]);
|
|
}
|
|
|
|
$this->carouselSeeder->run();
|
|
}
|
|
|
|
private function uploadedImage(string $filename): UploadedFile
|
|
{
|
|
$path = public_path("images/tennants/onticket/{$filename}");
|
|
|
|
if (! is_file($path)) {
|
|
throw new RuntimeException("Image not found at path: {$path}");
|
|
}
|
|
|
|
$mimeType = match (strtolower(pathinfo($filename, PATHINFO_EXTENSION))) {
|
|
'svg' => 'image/svg+xml',
|
|
default => 'image/png',
|
|
};
|
|
|
|
return new UploadedFile($path, $filename, $mimeType, null, true);
|
|
}
|
|
}
|