]> BookStack Code Mirror - system-cli/commitdiff
Added some CLI change handling to prevent errors
authorDan Brown <redacted>
Sun, 9 Mar 2025 16:00:51 +0000 (16:00 +0000)
committerDan Brown <redacted>
Sun, 9 Mar 2025 16:00:51 +0000 (16:00 +0000)
Added proper detection of CLI changes, with early quite and output to
tell user to re-run, instead of erroring with a stack trace.
Used in scenario where the CLI will change itself as part of BookStack
updates.

Toyed with the idea of pre-compiling CLI PHP files, or handling the
scenario to switch to the new CLI version, but those are a lot more
complex and potentially error prone.

composer.lock
src/Commands/UpdateCommand.php

index 3cc8538594a82476d7a98552f4b3a6c49982854d..df6d1d1e04ba6dfc46a91af23945a5adb78f799c 100644 (file)
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "dfedeb5644f1db57e37ec243b28033ee",
+    "content-hash": "4f9274d16374a47807601a331304aaae",
     "packages": [
         {
             "name": "graham-campbell/result-type",
index 02cf3c6ccb9452416d3d0632e7881e7f39f314f8..23ffc2d445d3524bb128fca0a1bdbc301ea61d9e 100644 (file)
@@ -8,6 +8,7 @@ use Cli\Services\ComposerLocator;
 use Cli\Services\Paths;
 use Cli\Services\ProgramRunner;
 use Cli\Services\RequirementsValidator;
+use Phar;
 use Symfony\Component\Console\Command\Command;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Input\InputOption;
@@ -42,9 +43,18 @@ class UpdateCommand extends Command
             $composerLocator->download();
         }
 
+        $cliPath = Phar::running(false);
+        $cliPreUpdateHash = $cliPath ? hash_file('sha256', $cliPath) : '';
+
         $output->writeln("<info>Fetching latest code via Git...</info>");
         $this->updateCodeUsingGit($appDir);
 
+        $cliPostUpdateHash = $cliPath ? hash_file('sha256', $cliPath) : '';
+        if ($cliPostUpdateHash !== $cliPreUpdateHash) {
+            $output->writeln("<error>System CLI file changed during update!\nRe-run the update command to complete the update process.</error>");
+            return Command::FAILURE;
+        }
+
         $output->writeln("<info>Installing PHP dependencies via composer...</info>");
         $this->installComposerDependencies($composer, $appDir);