feat(tenant): implement TenantProvisioningService and OnTicketTenantSeeder for tenant management
This commit is contained in:
101
database/seeders/OnTicketTenantSeeder.php
Normal file
101
database/seeders/OnTicketTenantSeeder.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?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 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,
|
||||
]);
|
||||
|
||||
if ($tenant->header_bg_image_id === null) {
|
||||
$tenant = $this->tenantProvisioningService->update($tenant, [
|
||||
'header_bg_image' => $this->uploadedImage('onticket_header_background.png'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user