|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Kimai 2 - Remote Console. |
| 5 | + * |
| 6 | + * For the full copyright and license information, please view the LICENSE |
| 7 | + * file that was distributed with this source code. |
| 8 | + */ |
| 9 | + |
| 10 | +namespace KimaiConsole\Command; |
| 11 | + |
| 12 | +use KimaiConsole\Constants; |
| 13 | +use Symfony\Component\Console\Input\InputInterface; |
| 14 | +use Symfony\Component\Console\Output\OutputInterface; |
| 15 | +use Symfony\Component\Console\Style\SymfonyStyle; |
| 16 | + |
| 17 | +class SelfCheckCommand extends AbstractSelfCommand |
| 18 | +{ |
| 19 | + /** |
| 20 | + * {@inheritdoc} |
| 21 | + */ |
| 22 | + protected function configure() |
| 23 | + { |
| 24 | + $this |
| 25 | + ->setName('self:check') |
| 26 | + ->setDescription('Checks for available updates') |
| 27 | + ->setHelp('This command checks if there is a new version available') |
| 28 | + ; |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * {@inheritdoc} |
| 33 | + */ |
| 34 | + protected function execute(InputInterface $input, OutputInterface $output) |
| 35 | + { |
| 36 | + $io = new SymfonyStyle($input, $output); |
| 37 | + |
| 38 | + $updater = $this->getUpdater(); |
| 39 | + |
| 40 | + try { |
| 41 | + $result = $updater->hasUpdate(); |
| 42 | + |
| 43 | + if ($result) { |
| 44 | + // this is also triggered, if the current local version is higher then the remote version |
| 45 | + // it does not trigger a version_compare, but only compare if the two versions are equal |
| 46 | + $io->success(sprintf('There is a new release available in version: %s', $updater->getNewVersion())); |
| 47 | + } elseif (false === $updater->getNewVersion()) { |
| 48 | + $io->success('There are no stable builds available.'); |
| 49 | + } else { |
| 50 | + $io->success(sprintf('You are running the latest version: %s', Constants::VERSION)); |
| 51 | + } |
| 52 | + } catch (\Exception $ex) { |
| 53 | + $io->error('Failed to check for updates: ' . $ex->getMessage()); |
| 54 | + |
| 55 | + return 1; |
| 56 | + } |
| 57 | + |
| 58 | + return 0; |
| 59 | + } |
| 60 | +} |
0 commit comments