X-Git-Url: http://source.bookstackapp.com/system-cli/blobdiff_plain/a69f2bc809fa3ea207cc138e0443dfb310b2a763..154a3ff7220d9c6ceb7ce06cb39e9b8e5b0ef558:/scripts/Commands/UpdateCommand.php
diff --git a/scripts/Commands/UpdateCommand.php b/scripts/Commands/UpdateCommand.php
index 573b04c..e9dfa60 100644
--- a/scripts/Commands/UpdateCommand.php
+++ b/scripts/Commands/UpdateCommand.php
@@ -2,27 +2,23 @@
namespace Cli\Commands;
+use Cli\Services\AppLocator;
use Cli\Services\ComposerLocator;
use Cli\Services\EnvironmentLoader;
use Cli\Services\ProgramRunner;
use Cli\Services\RequirementsValidator;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class UpdateCommand extends Command
{
-
- public function __construct(
- protected string $appDir
- ) {
- parent::__construct();
- }
-
protected function configure(): void
{
$this->setName('update');
$this->setDescription('Update an existing BookStack instance.');
+ $this->addOption('app-directory', null, InputOption::VALUE_OPTIONAL, 'BookStack install directory to update', '');
}
/**
@@ -30,11 +26,12 @@ class UpdateCommand extends Command
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
+ $appDir = AppLocator::require($input->getOption('app-directory'));
$output->writeln("Checking system requirements...");
RequirementsValidator::validate();
$output->writeln("Checking composer exists...");
- $composerLocator = new ComposerLocator($this->appDir);
+ $composerLocator = new ComposerLocator($appDir);
$composer = $composerLocator->getProgram();
if (!$composer->isFound()) {
$output->writeln("Composer does not exist, downloading a local copy...");
@@ -42,18 +39,18 @@ class UpdateCommand extends Command
}
$output->writeln("Fetching latest code via Git...");
- $this->updateCodeUsingGit();
+ $this->updateCodeUsingGit($appDir);
$output->writeln("Installing PHP dependencies via composer...");
- $this->installComposerDependencies($composer);
+ $this->installComposerDependencies($composer, $appDir);
$output->writeln("Running database migrations...");
- $this->runArtisanCommand(['migrate', '--force']);
+ $this->runArtisanCommand(['migrate', '--force'], $appDir);
$output->writeln("Clearing app caches...");
- $this->runArtisanCommand(['cache:clear']);
- $this->runArtisanCommand(['config:clear']);
- $this->runArtisanCommand(['view:clear']);
+ $this->runArtisanCommand(['cache:clear'], $appDir);
+ $this->runArtisanCommand(['config:clear'], $appDir);
+ $this->runArtisanCommand(['view:clear'], $appDir);
return Command::SUCCESS;
}
@@ -61,13 +58,13 @@ class UpdateCommand extends Command
/**
* @throws CommandError
*/
- protected function updateCodeUsingGit(): void
+ protected function updateCodeUsingGit(string $appDir): void
{
$errors = (new ProgramRunner('git', '/usr/bin/git'))
->withTimeout(240)
->withIdleTimeout(15)
->runCapturingStdErr([
- '-C', $this->appDir,
+ '-C', $appDir,
'pull', '-q', 'origin', 'release',
]);
@@ -79,12 +76,12 @@ class UpdateCommand extends Command
/**
* @throws CommandError
*/
- protected function installComposerDependencies(ProgramRunner $composer): void
+ protected function installComposerDependencies(ProgramRunner $composer, string $appDir): void
{
$errors = $composer->runCapturingStdErr([
'install',
'--no-dev', '-n', '-q', '--no-progress',
- '-d', $this->appDir,
+ '-d', $appDir,
]);
if ($errors) {
@@ -92,14 +89,14 @@ class UpdateCommand extends Command
}
}
- protected function runArtisanCommand(array $commandArgs): void
+ protected function runArtisanCommand(array $commandArgs, string $appDir): void
{
$errors = (new ProgramRunner('php', '/usr/bin/php'))
->withTimeout(60)
->withIdleTimeout(5)
- ->withEnvironment(EnvironmentLoader::load($this->appDir))
+ ->withEnvironment(EnvironmentLoader::load($appDir))
->runCapturingAllOutput([
- $this->appDir . DIRECTORY_SEPARATOR . 'artisan',
+ $appDir . DIRECTORY_SEPARATOR . 'artisan',
'-n', '-q',
...$commandArgs
]);