RequirementsValidator::validate();
(new ProgramRunner('mysql', '/usr/bin/mysql'))->ensureFound();
- $zipPath = realpath($input->getArgument('backup-zip'));
+ $providedZipPath = $input->getArgument('backup-zip');
+ $zipPath = realpath($providedZipPath);
+ if (!$zipPath || !file_exists($zipPath)) {
+ $pathToDisplay = $zipPath ?: $providedZipPath;
+ throw new CommandError("Could not find ZIP file for restoration at provided path [{$pathToDisplay}].");
+ }
+
$zip = new BackupZip($zipPath);
$contents = $zip->getContentsOverview();
}
if ($envChanges && $envChanges['old_url'] !== $envChanges['new_url']) {
- $output->writeln("<info>App URL change made, Updating database with URL change...</info>");
+ $output->writeln("<info>App URL change made, updating database with URL change...</info>");
$artisan->run([
- 'bookstack:update-url',
+ 'bookstack:update-url', '--force',
$envChanges['old_url'], $envChanges['new_url'],
]);
}
protected function restoreEnv(string $extractDir, string $appDir, OutputInterface $output, InteractiveConsole $interactions): array
{
- $oldEnv = EnvironmentLoader::load($extractDir);
+ $oldEnv = EnvironmentLoader::loadMergedWithCurrentEnv($extractDir);
$currentEnv = EnvironmentLoader::load($appDir);
$envContents = file_get_contents(Paths::join($extractDir, '.env'));
$appEnvPath = Paths::real(Paths::join($appDir, '.env'));
$currentEnvDbLines = array_values(array_filter(explode("\n", $currentEnvContents), function (string $line) {
return str_starts_with($line, 'DB_');
}));
- $oldEnvLines = array_values(array_filter(explode("\n", $currentEnvContents), function (string $line) {
+ $oldEnvLines = array_values(array_filter(explode("\n", $envContents), function (string $line) {
return !str_starts_with($line, 'DB_');
}));
$envContents = implode("\n", [
];
if ($oldUrl !== $newUrl) {
- $output->writeln("Found different APP_URL values:");
- $changedUrl = $interactions->choice('Which would you like to use?', array_filter([$oldUrl, $newUrl]));
- $envContents = preg_replace('/^APP_URL=.*?$/', 'APP_URL="' . $changedUrl . '"', $envContents);
+ $question = 'Found different APP_URL values, which would you like to use?';
+ $changedUrl = $interactions->choice($question, array_filter([$oldUrl, $newUrl]));
+ $envContents = preg_replace('/^APP_URL=.*?$/m', 'APP_URL="' . $changedUrl . '"', $envContents);
$returnData['new_url'] = $changedUrl;
}
protected function restoreDatabase(string $appDir, string $extractDir): void
{
$dbDump = Paths::join($extractDir, 'db.sql');
- $currentEnv = EnvironmentLoader::load($appDir);
+ $currentEnv = EnvironmentLoader::loadMergedWithCurrentEnv($appDir);
$mysql = MySqlRunner::fromEnvOptions($currentEnv);
// Drop existing tables