feat(seeder): add FiestaTradicionArrufoSeeder to tenant provisioning and update OnTicketTenantSeeder for image validation
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Database\Seeders\FiestaTradicionArrufoSeeder;
|
||||||
use Database\Seeders\OnTicketTenantSeeder;
|
use Database\Seeders\OnTicketTenantSeeder;
|
||||||
use Database\Seeders\WebsiteTypeSeeder;
|
use Database\Seeders\WebsiteTypeSeeder;
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
@@ -34,6 +35,7 @@ return new class extends Migration
|
|||||||
|
|
||||||
app(WebsiteTypeSeeder::class)->run();
|
app(WebsiteTypeSeeder::class)->run();
|
||||||
app(OnTicketTenantSeeder::class)->run();
|
app(OnTicketTenantSeeder::class)->run();
|
||||||
|
app(FiestaTradicionArrufoSeeder::class)->run();
|
||||||
|
|
||||||
$now = now();
|
$now = now();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Domains\Core\Tenant\Models\AdminWebsiteType;
|
||||||
|
use Database\Seeders\FiestaTradicionArrufoSeeder;
|
||||||
|
use Database\Seeders\OnTicketTenantSeeder;
|
||||||
|
use Database\Seeders\WebsiteTypeSeeder;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
if (app()->environment('testing')) {
|
||||||
|
Storage::fake('s3');
|
||||||
|
}
|
||||||
|
|
||||||
|
$type = AdminWebsiteType::query()
|
||||||
|
->with(['siteLogo', 'footerLogo', 'favicon'])
|
||||||
|
->where('codigo', 'onticket')
|
||||||
|
->first();
|
||||||
|
$typeAssets = $type === null
|
||||||
|
? []
|
||||||
|
: [$type->siteLogo, $type->footerLogo, $type->favicon];
|
||||||
|
|
||||||
|
if (
|
||||||
|
$type === null
|
||||||
|
|| collect($typeAssets)->contains(
|
||||||
|
fn ($attachment): bool => $attachment === null
|
||||||
|
|| ! Storage::disk('s3')->exists($attachment->path)
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
app(WebsiteTypeSeeder::class)->run();
|
||||||
|
}
|
||||||
|
|
||||||
|
app(OnTicketTenantSeeder::class)->run();
|
||||||
|
app(FiestaTradicionArrufoSeeder::class)->run();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
// Reference and operational data are intentionally preserved.
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -3,8 +3,8 @@
|
|||||||
namespace Database\Seeders;
|
namespace Database\Seeders;
|
||||||
|
|
||||||
use App\Domains\Commerce\Catalog\Enums\InventoryPolicy;
|
use App\Domains\Commerce\Catalog\Enums\InventoryPolicy;
|
||||||
use App\Domains\Commerce\Catalog\Models\CatalogItem;
|
|
||||||
use App\Domains\Commerce\Catalog\Models\Attribute;
|
use App\Domains\Commerce\Catalog\Models\Attribute;
|
||||||
|
use App\Domains\Commerce\Catalog\Models\CatalogItem;
|
||||||
use App\Domains\Commerce\Catalog\Services\CatalogService;
|
use App\Domains\Commerce\Catalog\Services\CatalogService;
|
||||||
use App\Domains\Core\Tenant\Models\Tenant;
|
use App\Domains\Core\Tenant\Models\Tenant;
|
||||||
use App\Domains\Ticketing\Event\Models\Event;
|
use App\Domains\Ticketing\Event\Models\Event;
|
||||||
@@ -13,6 +13,7 @@ use App\Shared\Enums\FieldType;
|
|||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
use Illuminate\Http\UploadedFile;
|
use Illuminate\Http\UploadedFile;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
|
|
||||||
class FiestaTradicionArrufoSeeder extends Seeder
|
class FiestaTradicionArrufoSeeder extends Seeder
|
||||||
@@ -51,7 +52,8 @@ class FiestaTradicionArrufoSeeder extends Seeder
|
|||||||
'location' => 'Predio de Doma del Club Unión Deportiva Arrufó',
|
'location' => 'Predio de Doma del Club Unión Deportiva Arrufó',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($event->attachment_id === null) {
|
$eventImage = $event->attachment;
|
||||||
|
if ($eventImage === null || ! Storage::disk('s3')->exists($eventImage->path)) {
|
||||||
$event->update(['attachment_id' => $this->attachments->store($this->image(), 'events')->id]);
|
$event->update(['attachment_id' => $this->attachments->store($this->image(), 'events')->id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,6 +87,7 @@ class FiestaTradicionArrufoSeeder extends Seeder
|
|||||||
$existing = CatalogItem::query()->where('tenant_code', $tenant->codigo)->where('slug', $data['slug'])->first();
|
$existing = CatalogItem::query()->where('tenant_code', $tenant->codigo)->where('slug', $data['slug'])->first();
|
||||||
if ($existing !== null) {
|
if ($existing !== null) {
|
||||||
$existing->update(['sales_end_at' => $data['sales_end_at'] ?? null]);
|
$existing->update(['sales_end_at' => $data['sales_end_at'] ?? null]);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use App\Domains\Core\Tenant\Services\TenantProvisioningService;
|
|||||||
use App\Domains\Core\Tenant\Services\WebsiteExtraService;
|
use App\Domains\Core\Tenant\Services\WebsiteExtraService;
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
use Illuminate\Http\UploadedFile;
|
use Illuminate\Http\UploadedFile;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
|
|
||||||
class OnTicketTenantSeeder extends Seeder
|
class OnTicketTenantSeeder extends Seeder
|
||||||
@@ -58,10 +59,22 @@ class OnTicketTenantSeeder extends Seeder
|
|||||||
'display_seach_bar' => true,
|
'display_seach_bar' => true,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($tenant->header_bg_image_id === null) {
|
$missingImages = [];
|
||||||
$tenant = $this->tenantProvisioningService->update($tenant, [
|
foreach ([
|
||||||
'header_bg_image' => $this->uploadedImage('onticket_header_background.png'),
|
'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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user