From 02016a6545b8da1256c8f570a578d7caa6f8d42d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 14 May 2026 13:07:25 +0000 Subject: [PATCH 1/2] Initial plan From c0b1e16010b1db59e52289f1878c34813cdce27d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 14 May 2026 13:28:49 +0000 Subject: [PATCH 2/2] Fix FlexMigrator::migrateEnvFile() to not overwrite existing .env.local When the flex migration template step is retried (e.g., after a partial failure where symfony.lock wasn't created), migrateEnvFile() would be called again. On the second call, .env contained defaults (from the first migration) and .env.local contained the real DATABASE_URL (renamed from original .env). The rename() call would overwrite .env.local with the default content from .env, losing the user's real DATABASE_URL. Fix: Add a guard to skip the rename if .env.local already exists, preserving any existing configuration in .env.local." Agent-Logs-Url: https://github.com/shopware/web-installer/sessions/27549929-0551-46e2-b276-d1fddc3e85f2 Co-authored-by: shyim <6224096+shyim@users.noreply.github.com> --- Services/FlexMigrator.php | 6 +++++- Tests/Services/FlexMigratorTest.php | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Services/FlexMigrator.php b/Services/FlexMigrator.php index 90dc5c7..920bb70 100644 --- a/Services/FlexMigrator.php +++ b/Services/FlexMigrator.php @@ -173,6 +173,7 @@ public function copyNewTemplateFiles(string $projectDir): void public function migrateEnvFile(string $projectDir): void { $envPath = $projectDir . '/.env'; + $envLocalPath = $projectDir . '/.env.local'; if (!is_file($envPath)) { file_put_contents($envPath, self::ENV_DEFAULT); @@ -180,7 +181,10 @@ public function migrateEnvFile(string $projectDir): void return; } - rename($envPath, $envPath . '.local'); + if (!is_file($envLocalPath)) { + rename($envPath, $envLocalPath); + } + file_put_contents($envPath, self::ENV_DEFAULT); } diff --git a/Tests/Services/FlexMigratorTest.php b/Tests/Services/FlexMigratorTest.php index 06bc74f..7dacf63 100644 --- a/Tests/Services/FlexMigratorTest.php +++ b/Tests/Services/FlexMigratorTest.php @@ -87,6 +87,27 @@ public function testMigrateEnvExistingEnv(): void $fs->remove($tmpDir); } + public function testMigrateEnvDoesNotOverwriteExistingEnvLocal(): void + { + $tmpDir = sys_get_temp_dir() . '/flex-migrator-test'; + $fs = new Filesystem(); + $fs->mkdir($tmpDir); + $fs->dumpFile($tmpDir . '/.env', 'DATABASE_URL=mysql://user:pass@localhost/real_db'); + $fs->dumpFile($tmpDir . '/.env.local', 'DATABASE_URL=mysql://user:pass@localhost/real_db'); + + $flexMigrator = new FlexMigrator(); + + $flexMigrator->migrateEnvFile($tmpDir); + + static::assertFileExists($tmpDir . '/.env'); + static::assertFileExists($tmpDir . '/.env.local'); + static::assertStringContainsString('###> symfony/lock ###', (string) file_get_contents($tmpDir . '/.env')); + // The existing .env.local must not be overwritten + static::assertSame('DATABASE_URL=mysql://user:pass@localhost/real_db', (string) file_get_contents($tmpDir . '/.env.local')); + + $fs->remove($tmpDir); + } + public static function composerCases(): \Generator { yield 'no repos' => [