CheckCore.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OC\Core\Command\Integrity;
  8. use OC\Core\Command\Base;
  9. use OC\IntegrityCheck\Checker;
  10. use Symfony\Component\Console\Input\InputInterface;
  11. use Symfony\Component\Console\Output\OutputInterface;
  12. /**
  13. * Class CheckCore
  14. *
  15. * @package OC\Core\Command\Integrity
  16. */
  17. class CheckCore extends Base {
  18. public function __construct(
  19. private Checker $checker,
  20. ) {
  21. parent::__construct();
  22. }
  23. /**
  24. * {@inheritdoc }
  25. */
  26. protected function configure() {
  27. parent::configure();
  28. $this
  29. ->setName('integrity:check-core')
  30. ->setDescription('Check integrity of core code using a signature.');
  31. }
  32. /**
  33. * {@inheritdoc }
  34. */
  35. protected function execute(InputInterface $input, OutputInterface $output): int {
  36. if (!$this->checker->isCodeCheckEnforced()) {
  37. $output->writeln('<comment>integrity:check-core can not be used on git checkouts</comment>');
  38. return 2;
  39. }
  40. $result = $this->checker->verifyCoreSignature();
  41. $this->writeArrayInOutputFormat($input, $output, $result);
  42. if (count($result) > 0) {
  43. $output->writeln('<error>' . count($result) . ' errors found</error>', OutputInterface::VERBOSITY_VERBOSE);
  44. return 1;
  45. }
  46. $output->writeln('<info>No errors found</info>', OutputInterface::VERBOSITY_VERBOSE);
  47. return 0;
  48. }
  49. }