diff --git a/database/migrations/2026_08_12_060000_set_desfile_footer_background_image.php b/database/migrations/2026_08_12_060000_set_desfile_footer_background_image.php new file mode 100644 index 0000000..abb4f06 --- /dev/null +++ b/database/migrations/2026_08_12_060000_set_desfile_footer_background_image.php @@ -0,0 +1,78 @@ +where('codigo', self::TENANT_CODE) + ->first(['id', 'footer_bg_image_id']); + + if ($tenant === null || $tenant->footer_bg_image_id !== null) { + return; + } + + $sourcePath = public_path( + 'images/tennants/desfile_pura_tendencia/'.self::FILENAME + ); + + if (! is_file($sourcePath)) { + throw new RuntimeException("Image not found at path: {$sourcePath}"); + } + + $contents = file_get_contents($sourcePath); + + if ($contents === false) { + throw new RuntimeException("Could not read image at path: {$sourcePath}"); + } + + $key = (string) Str::uuid(); + $storedPath = 'tenants/'.self::TENANT_CODE.'/'.$key.'.png'; + + if (! Storage::disk('s3')->put($storedPath, $contents)) { + throw new RuntimeException("Could not store image at path: {$storedPath}"); + } + + try { + DB::transaction(function () use ($contents, $key, $storedPath): void { + $attachmentId = DB::table('attachments')->insertGetId([ + 'key' => $key, + 'path' => $storedPath, + 'filename' => self::FILENAME, + 'type' => 'image', + 'mime_type' => 'image/png', + 'extension' => 'png', + 'size' => strlen($contents), + 'created_at' => now(), + 'updated_at' => now(), + ]); + + DB::table('tenants') + ->where('codigo', self::TENANT_CODE) + ->update([ + 'footer_bg_image_id' => $attachmentId, + 'updated_at' => now(), + ]); + }); + } catch (Throwable $throwable) { + Storage::disk('s3')->delete($storedPath); + + throw $throwable; + } + } + + public function down(): void + { + // The attachment may already be referenced externally; keep this data + // migration irreversible instead of deleting a potentially active asset. + } +}; diff --git a/public/images/tennants/desfile_pura_tendencia/desfile_pura_tendencia_footer_background.png b/public/images/tennants/desfile_pura_tendencia/desfile_pura_tendencia_footer_background.png new file mode 100644 index 0000000..cac27aa Binary files /dev/null and b/public/images/tennants/desfile_pura_tendencia/desfile_pura_tendencia_footer_background.png differ diff --git a/tests/Feature/Migrations/CreateDesfilePuraTendenciaTenantTest.php b/tests/Feature/Migrations/CreateDesfilePuraTendenciaTenantTest.php index a616b11..08be0c9 100644 --- a/tests/Feature/Migrations/CreateDesfilePuraTendenciaTenantTest.php +++ b/tests/Feature/Migrations/CreateDesfilePuraTendenciaTenantTest.php @@ -31,6 +31,11 @@ class CreateDesfilePuraTendenciaTenantTest extends TestCase ); $migration->up(); + $footerBackgroundMigration = require database_path( + 'migrations/2026_08_12_060000_set_desfile_footer_background_image.php' + ); + $footerBackgroundMigration->up(); + $this->assertDatabaseHas('tenants', [ 'codigo' => 'desfile_pura_tendencia', 'nombre' => 'Desfile Pura Tendencia', @@ -85,11 +90,20 @@ class CreateDesfilePuraTendenciaTenantTest extends TestCase 'filename' => 'desfile_pura_tendencia_hero.png', 'type' => 'image', ]); + $footerBackgroundImageId = DB::table('tenants') + ->where('codigo', 'desfile_pura_tendencia') + ->value('footer_bg_image_id'); + $this->assertDatabaseHas('attachments', [ + 'id' => $footerBackgroundImageId, + 'filename' => 'desfile_pura_tendencia_footer_background.png', + 'type' => 'image', + ]); foreach ([ 'desfile_pura_tendencia_header.png', 'desfile_pura_tendencia_footer.png', 'desfile_pura_tendencia_hero.png', + 'desfile_pura_tendencia_footer_background.png', 'entrada_pasarela.png', ] as $filename) { $path = DB::table('attachments')->where('filename', $filename)->value('path');