3 namespace Cli\Commands;
5 use Cli\Services\AppLocator;
6 use Cli\Services\ArtisanRunner;
7 use Cli\Services\RequirementsValidator;
8 use Symfony\Component\Console\Command\Command;
9 use Symfony\Component\Console\Input\InputArgument;
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Input\InputOption;
12 use Symfony\Component\Console\Output\OutputInterface;
14 class RestoreCommand extends Command
16 protected function configure(): void
18 $this->setName('restore');
19 $this->addArgument('backup-zip', InputArgument::REQUIRED, 'Path to the ZIP file containing your backup.');
20 $this->setDescription('Restore data and files from a backup ZIP file.');
21 $this->addOption('app-directory', null, InputOption::VALUE_OPTIONAL, 'BookStack install directory to restore into', '');
25 * @throws CommandError
27 protected function execute(InputInterface $input, OutputInterface $output): int
29 $appDir = AppLocator::require($input->getOption('app-directory'));
30 $output->writeln("<info>Checking system requirements...</info>");
31 RequirementsValidator::validate();
33 // TODO - Warn that potentially dangerous,
34 // warn for same/forward versions only,
35 // warn this won't handle server-level stuff
37 // TODO - Validate provided backup zip contents
38 // - Display and prompt to user
40 // TODO - Environment handling
41 // - Restore of old .env
42 // - Prompt for correct DB details (Test before serving?)
43 // - Prompt for correct URL (Allow entry of new?)
45 // TODO - Restore folders from backup
47 // TODO - Restore database from backup
49 $output->writeln("<info>Running database migrations...</info>");
50 $artisan = (new ArtisanRunner($appDir));
51 $artisan->run(['migrate', '--force']);
53 // TODO - Update system URL (via BookStack artisan command) if
54 // there's been a change from old backup env
56 $output->writeln("<info>Clearing app caches...</info>");
57 $artisan->run(['cache:clear']);
58 $artisan->run(['config:clear']);
59 $artisan->run(['view:clear']);
61 return Command::SUCCESS;