1
0

Check.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2018, Tobia De Koninck (tobia@ledfan.be)
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author J0WI <J0WI@users.noreply.github.com>
  8. * @author Joas Schilling <coding@schilljs.com>
  9. * @author Tobia De Koninck <LEDfan@users.noreply.github.com>
  10. *
  11. * @license GNU AGPL version 3 or any later version
  12. *
  13. * This program is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License as
  15. * published by the Free Software Foundation, either version 3 of the
  16. * License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  25. *
  26. */
  27. namespace OCA\UpdateNotification\Command;
  28. use OC\App\AppManager;
  29. use OC\Installer;
  30. use OCA\UpdateNotification\UpdateChecker;
  31. use Symfony\Component\Console\Command\Command;
  32. use Symfony\Component\Console\Input\InputInterface;
  33. use Symfony\Component\Console\Output\OutputInterface;
  34. class Check extends Command {
  35. /**
  36. * @var Installer $installer
  37. */
  38. private $installer;
  39. /**
  40. * @var AppManager $appManager
  41. */
  42. private $appManager;
  43. /**
  44. * @var UpdateChecker $updateChecker
  45. */
  46. private $updateChecker;
  47. public function __construct(AppManager $appManager, UpdateChecker $updateChecker, Installer $installer) {
  48. parent::__construct();
  49. $this->installer = $installer;
  50. $this->appManager = $appManager;
  51. $this->updateChecker = $updateChecker;
  52. }
  53. protected function configure(): void {
  54. $this
  55. ->setName('update:check')
  56. ->setDescription('Check for server and app updates')
  57. ;
  58. }
  59. protected function execute(InputInterface $input, OutputInterface $output): int {
  60. $updatesAvailableCount = 0;
  61. // Server
  62. $r = $this->updateChecker->getUpdateState();
  63. if (isset($r['updateAvailable']) && $r['updateAvailable']) {
  64. $output->writeln($r['updateVersionString'] . ' is available. Get more information on how to update at '. $r['updateLink'] . '.');
  65. $updatesAvailableCount += 1;
  66. }
  67. // Apps
  68. $apps = $this->appManager->getInstalledApps();
  69. foreach ($apps as $app) {
  70. $update = $this->installer->isUpdateAvailable($app);
  71. if ($update !== false) {
  72. $output->writeln('Update for ' . $app . ' to version ' . $update . ' is available.');
  73. $updatesAvailableCount += 1;
  74. }
  75. }
  76. // Report summary
  77. if ($updatesAvailableCount === 0) {
  78. $output->writeln('<info>Everything up to date</info>');
  79. } elseif ($updatesAvailableCount === 1) {
  80. $output->writeln('<comment>1 update available</comment>');
  81. } else {
  82. $output->writeln('<comment>' . $updatesAvailableCount . ' updates available</comment>');
  83. }
  84. return 0;
  85. }
  86. }