SetupCheckManager.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OC\SetupCheck;
  8. use OC\AppFramework\Bootstrap\Coordinator;
  9. use OCP\Server;
  10. use OCP\SetupCheck\ISetupCheck;
  11. use OCP\SetupCheck\ISetupCheckManager;
  12. use OCP\SetupCheck\SetupResult;
  13. use Psr\Log\LoggerInterface;
  14. class SetupCheckManager implements ISetupCheckManager {
  15. public function __construct(
  16. private Coordinator $coordinator,
  17. private LoggerInterface $logger,
  18. ) {
  19. }
  20. public function runAll(): array {
  21. $results = [];
  22. $setupChecks = $this->coordinator->getRegistrationContext()->getSetupChecks();
  23. foreach ($setupChecks as $setupCheck) {
  24. /** @var ISetupCheck $setupCheckObject */
  25. $setupCheckObject = Server::get($setupCheck->getService());
  26. $this->logger->debug('Running check ' . get_class($setupCheckObject));
  27. try {
  28. $setupResult = $setupCheckObject->run();
  29. } catch (\Throwable $t) {
  30. $setupResult = SetupResult::error("An exception occured while running the setup check:\n$t");
  31. $this->logger->error('Exception running check ' . get_class($setupCheckObject) . ': ' . $t->getMessage(), ['exception' => $t]);
  32. }
  33. $setupResult->setName($setupCheckObject->getName());
  34. $category = $setupCheckObject->getCategory();
  35. $results[$category] ??= [];
  36. $results[$category][$setupCheckObject::class] = $setupResult;
  37. }
  38. return $results;
  39. }
  40. }