]> BookStack Code Mirror - system-cli/blobdiff - src/Commands/RestoreCommand.php
Added path check/validation for provided restore file path
[system-cli] / src / Commands / RestoreCommand.php
index 84c7106d948eab47e43f8d7702f8db2742d2d1ac..3fb91540dc8328696ba269741b6714579a5d3deb 100644 (file)
@@ -48,7 +48,13 @@ class RestoreCommand extends Command
         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();
 
@@ -104,9 +110,9 @@ class RestoreCommand extends Command
         }
 
         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'],
             ]);
         }
@@ -165,9 +171,9 @@ class RestoreCommand extends Command
         ];
 
         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;
         }