Lines
68.00%
17 / 25
Methods
66.66%
2 / 3
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 1 | ||
| configure | 100.00% | 8 / 8 | 100.00% | 1 / 1 | 1 | ||
| execute | 42.85% | 6 / 14 | 0.00% | 0 / 1 | 4.68 | ||
| 33 | class UpdateCommand extends Command | |
| 34 | { | |
| 35 | protected static string $defaultName = 'phpmyfaq:update'; | |
| 36 | ||
| 37 | private Configuration $configuration; | |
| 38 | ||
| 39 | private System $system; | |
| 40 | ||
| 41 | public function __construct() | |
| 42 | { | |
| 43 | parent::__construct(); | |
| 44 | ||
| 45 | $this->configuration = Configuration::getConfigurationInstance(); | |
| 46 | $this->system = new System(); | |
| 47 | } | |
| 48 | ||
| 49 | /** | |
| 50 | * {@inheritdoc} | |
| 51 | */ | |
| 52 | protected function configure(): void | |
| 53 | { | |
| 54 | $this | |
| 55 | ->setName(self::$defaultName) | |
| 56 | ->setDescription(description: 'Executes the phpMyFAQ update process') | |
| 57 | ->addArgument( | |
| 58 | name: 'version', | |
| 59 | mode: InputArgument::OPTIONAL, | |
| 60 | description: 'Requested version for the update', | |
| 61 | ); | |
| 62 | } | |
| 63 | ||
| 64 | protected function execute(InputInterface $input, OutputInterface $output): int | |
| 65 | { | |
| 66 | $symfonyStyle = new SymfonyStyle($input, $output); | |
| 67 | ||
| 68 | $symfonyStyle->title(message: 'Start automatic phpMyFAQ update ...'); | |
| 69 | ||
| 70 | try { | |
| 71 | $updateRunner = new UpdateRunner($this->configuration, $this->system); | |
| 72 | $result = $updateRunner->run($symfonyStyle); | |
| 73 | ||
| 74 | if (Command::SUCCESS !== $result) { | |
| 75 | return Command::FAILURE; | |
| 76 | } | |
| 77 | ||
| 78 | $symfonyStyle->success(message: strtr('phpMyFAQ was successfully updated to version version: on date:.', [ | |
| 79 | 'version:' => System::getVersion(), | |
| 80 | 'date:' => new DateTime()->format(format: 'Y-m-d H:i:s'), | |
| 81 | ])); | |
| 82 | ||
| 83 | return Command::SUCCESS; | |
| 84 | } catch (Throwable $throwable) { | |
| 85 | $symfonyStyle->error(message: 'Error during update: ' . $throwable->getMessage()); | |
| 86 | return Command::FAILURE; | |
| 87 | } | |
| 88 | } | |
| 89 | } |