refactor(tenant): remove legacy presentation configuration and related carousel images
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::dropIfExists('tenant_main_carousel_images');
|
||||
|
||||
Schema::table('tenants', function (Blueprint $table): void {
|
||||
$table->dropColumn('hero_bg_image_id');
|
||||
$table->dropColumn(['hero_config', 'event_config']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('tenants', function (Blueprint $table): void {
|
||||
$table->json('hero_config')->nullable();
|
||||
$table->json('event_config')->nullable();
|
||||
$table->unsignedBigInteger('hero_bg_image_id')
|
||||
->virtualAs('hero_config->>"$.background_image_id"')
|
||||
->nullable();
|
||||
});
|
||||
|
||||
Schema::create('tenant_main_carousel_images', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('tenant_id')
|
||||
->constrained('tenants')
|
||||
->cascadeOnDelete();
|
||||
$table->foreignId('attachment_id')
|
||||
->constrained('attachments')
|
||||
->cascadeOnDelete();
|
||||
$table->unsignedInteger('orden')->default(0);
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['tenant_id', 'attachment_id']);
|
||||
$table->index(['tenant_id', 'orden']);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -7,18 +7,11 @@ use App\Domains\Tenant\Models\Tenant;
|
||||
use App\Domains\Tenant\Services\TenantService;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use RuntimeException;
|
||||
use Throwable;
|
||||
|
||||
class TenantSeeder extends Seeder
|
||||
{
|
||||
private const SONDER_MAIN_CAROUSEL_IMAGES = [
|
||||
'01-urban-team.png',
|
||||
'02-running-shoes.png',
|
||||
'03-streetwear.png',
|
||||
'04-football-training.png',
|
||||
'05-activewear-essentials.png',
|
||||
'06-city-runners.png',
|
||||
];
|
||||
|
||||
private const SOCIAL_MEDIA = [
|
||||
[
|
||||
'code' => 'instagram',
|
||||
@@ -44,88 +37,13 @@ class TenantSeeder extends Seeder
|
||||
|
||||
public function __construct(protected TenantService $tenantService) {}
|
||||
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// Check if tenant 'sonder' already exists and delete it to prevent duplicates
|
||||
$existing = Tenant::query()->where('codigo', 'sonder')->first();
|
||||
if ($existing) {
|
||||
$attachmentService = app(AttachmentService::class);
|
||||
if ($existing->headerLogo) {
|
||||
try {
|
||||
$attachmentService->delete($existing->headerLogo);
|
||||
} catch (\Throwable $e) {
|
||||
// Ignore exception on cleanup
|
||||
}
|
||||
}
|
||||
if ($existing->footerLogo && $existing->footer_logo_id !== $existing->header_logo_id) {
|
||||
try {
|
||||
$attachmentService->delete($existing->footerLogo);
|
||||
} catch (\Throwable $e) {
|
||||
// Ignore exception on cleanup
|
||||
}
|
||||
}
|
||||
foreach ($existing->mainCarouselImages as $mainCarouselImage) {
|
||||
try {
|
||||
$attachmentService->delete($mainCarouselImage);
|
||||
} catch (\Throwable $e) {
|
||||
// Ignore exception on cleanup
|
||||
}
|
||||
}
|
||||
$existing->delete();
|
||||
}
|
||||
$this->deleteTenant('sonder');
|
||||
|
||||
// Check if domain 'localhost' is already in use by another tenant and delete it
|
||||
$existingDomain = Tenant::query()->where('dominio', 'localhost')->first();
|
||||
if ($existingDomain) {
|
||||
$existingDomain->delete();
|
||||
}
|
||||
|
||||
$headerImagePath = public_path('images/sonder_header.png');
|
||||
$footerImagePath = public_path('images/sonder_footer.png');
|
||||
|
||||
if (! file_exists($headerImagePath)) {
|
||||
throw new \RuntimeException("Image not found at path: {$headerImagePath}");
|
||||
}
|
||||
|
||||
if (! file_exists($footerImagePath)) {
|
||||
throw new \RuntimeException("Image not found at path: {$footerImagePath}");
|
||||
}
|
||||
|
||||
$headerLogo = new UploadedFile(
|
||||
$headerImagePath,
|
||||
'sonder_header.png',
|
||||
'image/png',
|
||||
null,
|
||||
true
|
||||
);
|
||||
|
||||
$footerLogo = new UploadedFile(
|
||||
$footerImagePath,
|
||||
'sonder_footer.png',
|
||||
'image/png',
|
||||
null,
|
||||
true
|
||||
);
|
||||
|
||||
$mainCarouselImages = [];
|
||||
foreach (self::SONDER_MAIN_CAROUSEL_IMAGES as $filename) {
|
||||
$imagePath = public_path("images/sonder-main-carousel/{$filename}");
|
||||
|
||||
if (! file_exists($imagePath)) {
|
||||
throw new \RuntimeException("Image not found at path: {$imagePath}");
|
||||
}
|
||||
|
||||
$mainCarouselImages[] = new UploadedFile(
|
||||
$imagePath,
|
||||
$filename,
|
||||
'image/png',
|
||||
null,
|
||||
true
|
||||
);
|
||||
}
|
||||
Tenant::query()
|
||||
->where('dominio', 'localhost')
|
||||
->delete();
|
||||
|
||||
$this->tenantService->create([
|
||||
'codigo' => 'sonder',
|
||||
@@ -137,82 +55,17 @@ class TenantSeeder extends Seeder
|
||||
'success_color' => '#198754',
|
||||
'header_bg_color' => '#ffffff',
|
||||
'footer_bg_color' => '#313131',
|
||||
'header_logo' => $headerLogo,
|
||||
'footer_logo' => $footerLogo,
|
||||
'main_carousel_images' => $mainCarouselImages,
|
||||
'header_logo' => $this->uploadedImage('images/sonder_header.png', 'sonder_header.png'),
|
||||
'footer_logo' => $this->uploadedImage('images/sonder_footer.png', 'sonder_footer.png'),
|
||||
'social_media' => self::SOCIAL_MEDIA,
|
||||
]);
|
||||
|
||||
// Check if tenant 'fiesta_futbol_infantil' already exists
|
||||
$existingFiesta = Tenant::query()->where('codigo', 'fiesta_futbol_infantil')->first();
|
||||
if ($existingFiesta) {
|
||||
$attachmentService = app(AttachmentService::class);
|
||||
if ($existingFiesta->headerLogo) {
|
||||
try {
|
||||
$attachmentService->delete($existingFiesta->headerLogo);
|
||||
} catch (\Throwable $e) {
|
||||
}
|
||||
}
|
||||
if ($existingFiesta->footerLogo && $existingFiesta->footer_logo_id !== $existingFiesta->header_logo_id) {
|
||||
try {
|
||||
$attachmentService->delete($existingFiesta->footerLogo);
|
||||
} catch (\Throwable $e) {
|
||||
}
|
||||
}
|
||||
if ($existingFiesta->heroBgImage) {
|
||||
try {
|
||||
$attachmentService->delete($existingFiesta->heroBgImage);
|
||||
} catch (\Throwable $e) {
|
||||
}
|
||||
}
|
||||
$existingFiesta->delete();
|
||||
}
|
||||
$this->deleteTenant('fiesta_futbol_infantil');
|
||||
|
||||
$fiestaDomain = 'fiesta-futbol-infantil.localhost';
|
||||
$existingFiestaDomain = Tenant::query()->where('dominio', $fiestaDomain)->first();
|
||||
if ($existingFiestaDomain) {
|
||||
$existingFiestaDomain->delete();
|
||||
}
|
||||
|
||||
$fiestaHeaderImagePath = public_path('images/futbol_infantil_header.png');
|
||||
$fiestaFooterImagePath = public_path('images/futbol_infantil_footer.png');
|
||||
$fiestaHeroBgImagePath = public_path('images/futbol_infantil_hero.jpg');
|
||||
|
||||
if (! file_exists($fiestaHeaderImagePath)) {
|
||||
throw new \RuntimeException("Image not found at path: {$fiestaHeaderImagePath}");
|
||||
}
|
||||
|
||||
if (! file_exists($fiestaFooterImagePath)) {
|
||||
throw new \RuntimeException("Image not found at path: {$fiestaFooterImagePath}");
|
||||
}
|
||||
|
||||
if (! file_exists($fiestaHeroBgImagePath)) {
|
||||
throw new \RuntimeException("Image not found at path: {$fiestaHeroBgImagePath}");
|
||||
}
|
||||
|
||||
$fiestaHeaderLogo = new UploadedFile(
|
||||
$fiestaHeaderImagePath,
|
||||
'futbol_infantil_header.png',
|
||||
'image/png',
|
||||
null,
|
||||
true
|
||||
);
|
||||
|
||||
$fiestaFooterLogo = new UploadedFile(
|
||||
$fiestaFooterImagePath,
|
||||
'futbol_infantil_footer.png',
|
||||
'image/png',
|
||||
null,
|
||||
true
|
||||
);
|
||||
|
||||
$fiestaHeroBgImage = new UploadedFile(
|
||||
$fiestaHeroBgImagePath,
|
||||
'futbol_infantil_hero.jpg',
|
||||
'image/jpeg',
|
||||
null,
|
||||
true
|
||||
);
|
||||
Tenant::query()
|
||||
->where('dominio', $fiestaDomain)
|
||||
->delete();
|
||||
|
||||
$this->tenantService->create([
|
||||
'codigo' => 'fiesta_futbol_infantil',
|
||||
@@ -224,21 +77,63 @@ class TenantSeeder extends Seeder
|
||||
'success_color' => '#198754',
|
||||
'header_bg_color' => '#ffffff',
|
||||
'footer_bg_color' => '#015327',
|
||||
'header_logo' => $fiestaHeaderLogo,
|
||||
'footer_logo' => $fiestaFooterLogo,
|
||||
'hero_bg_image' => $fiestaHeroBgImage,
|
||||
'hero_config' => [
|
||||
'title_html' => '<strong>ASEGURÁ TU LUGAR</strong>',
|
||||
'description_html' => '<strong>Comprá tu entrada oficial en segundos</strong> de forma 100% segura. Preparate para vivir la experiencia completa.',
|
||||
'button_text' => 'Quiero mi entrada',
|
||||
'button_href' => null,
|
||||
],
|
||||
'event_config' => [
|
||||
'title' => 'FIESTA NACIONAL DEL FÚTBOL INFANTIL',
|
||||
'location' => 'Sunchales, Santa Fe',
|
||||
'dates' => ['2026-10-09', '2026-10-10', '2026-10-11', '2026-10-12'],
|
||||
],
|
||||
'header_logo' => $this->uploadedImage(
|
||||
'images/futbol_infantil_header.png',
|
||||
'futbol_infantil_header.png',
|
||||
),
|
||||
'footer_logo' => $this->uploadedImage(
|
||||
'images/futbol_infantil_footer.png',
|
||||
'futbol_infantil_footer.png',
|
||||
),
|
||||
'social_media' => self::SOCIAL_MEDIA,
|
||||
]);
|
||||
}
|
||||
|
||||
private function deleteTenant(string $codigo): void
|
||||
{
|
||||
$tenant = Tenant::query()
|
||||
->where('codigo', $codigo)
|
||||
->first();
|
||||
|
||||
if ($tenant === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$attachmentService = app(AttachmentService::class);
|
||||
|
||||
if ($tenant->headerLogo) {
|
||||
try {
|
||||
$attachmentService->delete($tenant->headerLogo);
|
||||
} catch (Throwable) {
|
||||
// Ignore cleanup errors while recreating demo data.
|
||||
}
|
||||
}
|
||||
|
||||
if ($tenant->footerLogo && $tenant->footer_logo_id !== $tenant->header_logo_id) {
|
||||
try {
|
||||
$attachmentService->delete($tenant->footerLogo);
|
||||
} catch (Throwable) {
|
||||
// Ignore cleanup errors while recreating demo data.
|
||||
}
|
||||
}
|
||||
|
||||
$tenant->delete();
|
||||
}
|
||||
|
||||
private function uploadedImage(string $relativePath, string $filename): UploadedFile
|
||||
{
|
||||
$path = public_path($relativePath);
|
||||
|
||||
if (! file_exists($path)) {
|
||||
throw new RuntimeException("Image not found at path: {$path}");
|
||||
}
|
||||
|
||||
return new UploadedFile(
|
||||
$path,
|
||||
$filename,
|
||||
'image/png',
|
||||
null,
|
||||
true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user