Back up existing env file before Installer changes it.

This commit is contained in:
Buster Neece 2023-01-05 19:30:46 -06:00
parent fb10802a12
commit b34b00fcd8
No known key found for this signature in database
GPG Key ID: F1D2E64A0005E80E
1 changed files with 11 additions and 0 deletions

View File

@ -149,6 +149,17 @@ abstract class AbstractEnvFile implements ArrayAccess
}
$envFileStr = implode("\n", $envFile);
if (is_file($this->path)) {
$existingFile = file_get_contents($this->path) ?: '';
if ($envFileStr !== $existingFile) {
$currentTimeUtc = new \DateTimeImmutable('now', new \DateTimeZone('UTC'));
$backupPath = $this->path . '_backup_' . $currentTimeUtc->format('Ymd-his') . '.bak';
copy($this->path, $backupPath);
}
}
file_put_contents($this->path, $envFileStr);
return $envFileStr;