]> BookStack Code Mirror - system-cli/blob - scripts/Commands/RestoreCommand.php
Started restore command, extracted artisan command
[system-cli] / scripts / Commands / RestoreCommand.php
1 <?php
2
3 namespace Cli\Commands;
4
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;
13
14 class RestoreCommand extends Command
15 {
16     protected function configure(): void
17     {
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', '');
22     }
23
24     /**
25      * @throws CommandError
26      */
27     protected function execute(InputInterface $input, OutputInterface $output): int
28     {
29         $appDir = AppLocator::require($input->getOption('app-directory'));
30         $output->writeln("<info>Checking system requirements...</info>");
31         RequirementsValidator::validate();
32
33         // TODO - Warn that potentially dangerous,
34         //        warn for same/forward versions only,
35         //        warn this won't handle server-level stuff
36
37         // TODO - Validate provided backup zip contents
38         //  - Display and prompt to user
39
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?)
44
45         // TODO - Restore folders from backup
46
47         // TODO - Restore database from backup
48
49         $output->writeln("<info>Running database migrations...</info>");
50         $artisan = (new ArtisanRunner($appDir));
51         $artisan->run(['migrate', '--force']);
52
53         // TODO - Update system URL (via BookStack artisan command) if
54         //   there's been a change from old backup env
55
56         $output->writeln("<info>Clearing app caches...</info>");
57         $artisan->run(['cache:clear']);
58         $artisan->run(['config:clear']);
59         $artisan->run(['view:clear']);
60
61         return Command::SUCCESS;
62     }
63 }