X-Git-Url: http://source.bookstackapp.com/system-cli/blobdiff_plain/86ebe8ec271b9cefe217c5ed8b4335abec48c92b..64190bc3dd9ec02bcb4ebe55e1a03d02979b544c:/src/Commands/UpdateCommand.php diff --git a/src/Commands/UpdateCommand.php b/src/Commands/UpdateCommand.php index 5475aaa..23ffc2d 100644 --- a/src/Commands/UpdateCommand.php +++ b/src/Commands/UpdateCommand.php @@ -5,8 +5,10 @@ namespace Cli\Commands; use Cli\Services\AppLocator; use Cli\Services\ArtisanRunner; 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; @@ -30,6 +32,9 @@ class UpdateCommand extends Command $output->writeln("Checking system requirements..."); RequirementsValidator::validate(); + $output->writeln("Checking local Git repository is active..."); + $this->ensureGitRepoExists($appDir); + $output->writeln("Checking composer exists..."); $composerLocator = new ComposerLocator($appDir); $composer = $composerLocator->getProgram(); @@ -38,9 +43,18 @@ class UpdateCommand extends Command $composerLocator->download(); } + $cliPath = Phar::running(false); + $cliPreUpdateHash = $cliPath ? hash_file('sha256', $cliPath) : ''; + $output->writeln("Fetching latest code via Git..."); $this->updateCodeUsingGit($appDir); + $cliPostUpdateHash = $cliPath ? hash_file('sha256', $cliPath) : ''; + if ($cliPostUpdateHash !== $cliPreUpdateHash) { + $output->writeln("System CLI file changed during update!\nRe-run the update command to complete the update process."); + return Command::FAILURE; + } + $output->writeln("Installing PHP dependencies via composer..."); $this->installComposerDependencies($composer, $appDir); @@ -91,4 +105,16 @@ class UpdateCommand extends Command throw new CommandError("Failed composer install with errors:\n" . $errors); } } + + protected function ensureGitRepoExists(string $appDir): void + { + $expectedPath = Paths::join($appDir, '.git'); + if (!is_dir($expectedPath)) { + $message = "Could not find a local git repository, it does not look like this instance is managed via common means.\n"; + $message .= "If you are running BookStack via a docker container, you should update following the advised process for the docker container image in use.\n"; + $message .= "This typically involves pulling and using an updated docker container image."; + + throw new CommandError($message); + } + } }