diff options
author | Carl Schwan <carl@carlschwan.eu> | 2022-05-23 09:25:47 +0200 |
---|---|---|
committer | Côme Chilliet <come.chilliet@nextcloud.com> | 2023-10-19 11:43:58 +0200 |
commit | eb1d612d961b562e744b8c6d8d361075b6daad55 (patch) | |
tree | 910769252cef71397c4ccfa03974f940b1b7c579 /lib | |
parent | a572a547f97e8643863958fba12410ac1a60db54 (diff) | |
download | nextcloud-server-eb1d612d961b562e744b8c6d8d361075b6daad55.tar.gz nextcloud-server-eb1d612d961b562e744b8c6d8d361075b6daad55.zip |
Add api to register setup checks
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/composer/composer/autoload_classmap.php | 2 | ||||
-rw-r--r-- | lib/composer/composer/autoload_static.php | 2 | ||||
-rw-r--r-- | lib/private/AppFramework/Bootstrap/RegistrationContext.php | 30 | ||||
-rw-r--r-- | lib/private/SetupCheck/SetupCheckManager.php | 31 | ||||
-rw-r--r-- | lib/public/AppFramework/Bootstrap/IRegistrationContext.php | 10 | ||||
-rw-r--r-- | lib/public/SetupCheck/ISetupCheck.php | 23 | ||||
-rw-r--r-- | lib/public/SetupCheck/SetupResult.php | 66 |
7 files changed, 161 insertions, 3 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 4387852556d..204b749befc 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -601,6 +601,8 @@ return array( 'OCP\\Settings\\IManager' => $baseDir . '/lib/public/Settings/IManager.php', 'OCP\\Settings\\ISettings' => $baseDir . '/lib/public/Settings/ISettings.php', 'OCP\\Settings\\ISubAdminSettings' => $baseDir . '/lib/public/Settings/ISubAdminSettings.php', + 'OCP\\SetupCheck\\ISetupCheck' => $baseDir . '/lib/public/SetupCheck/ISetupCheck.php', + 'OCP\\SetupCheck\\SetupResult' => $baseDir . '/lib/public/SetupCheck/SetupResult.php', 'OCP\\Share' => $baseDir . '/lib/public/Share.php', 'OCP\\Share\\Events\\BeforeShareCreatedEvent' => $baseDir . '/lib/public/Share/Events/BeforeShareCreatedEvent.php', 'OCP\\Share\\Events\\BeforeShareDeletedEvent' => $baseDir . '/lib/public/Share/Events/BeforeShareDeletedEvent.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 9b33577d66a..9ad208fc854 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -634,6 +634,8 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OCP\\Settings\\IManager' => __DIR__ . '/../../..' . '/lib/public/Settings/IManager.php', 'OCP\\Settings\\ISettings' => __DIR__ . '/../../..' . '/lib/public/Settings/ISettings.php', 'OCP\\Settings\\ISubAdminSettings' => __DIR__ . '/../../..' . '/lib/public/Settings/ISubAdminSettings.php', + 'OCP\\SetupCheck\\ISetupCheck' => __DIR__ . '/../../..' . '/lib/public/SetupCheck/ISetupCheck.php', + 'OCP\\SetupCheck\\SetupResult' => __DIR__ . '/../../..' . '/lib/public/SetupCheck/SetupResult.php', 'OCP\\Share' => __DIR__ . '/../../..' . '/lib/public/Share.php', 'OCP\\Share\\Events\\BeforeShareCreatedEvent' => __DIR__ . '/../../..' . '/lib/public/Share/Events/BeforeShareCreatedEvent.php', 'OCP\\Share\\Events\\BeforeShareDeletedEvent' => __DIR__ . '/../../..' . '/lib/public/Share/Events/BeforeShareDeletedEvent.php', diff --git a/lib/private/AppFramework/Bootstrap/RegistrationContext.php b/lib/private/AppFramework/Bootstrap/RegistrationContext.php index b3ef3ee65fb..d4588527006 100644 --- a/lib/private/AppFramework/Bootstrap/RegistrationContext.php +++ b/lib/private/AppFramework/Bootstrap/RegistrationContext.php @@ -55,6 +55,7 @@ use OCP\Http\WellKnown\IHandler; use OCP\Notification\INotifier; use OCP\Profile\ILinkAction; use OCP\Search\IProvider; +use OCP\SetupCheck\ISetupCheck; use OCP\Share\IPublicShareTemplateProvider; use OCP\Support\CrashReport\IReporter; use OCP\UserMigration\IMigrator as IUserMigrator; @@ -143,11 +144,13 @@ class RegistrationContext { /** @var ServiceRegistration<IPublicShareTemplateProvider>[] */ private $publicShareTemplateProviders = []; - /** @var LoggerInterface */ - private $logger; + private LoggerInterface $logger; + + /** @var ServiceRegistration<ISetupCheck>[] */ + private array $setupChecks = []; /** @var PreviewProviderRegistration[] */ - private $previewProviders = []; + private array $previewProviders = []; public function __construct(LoggerInterface $logger) { $this->logger = $logger; @@ -369,6 +372,13 @@ class RegistrationContext { $class ); } + + public function registerSetupCheck(string $setupCheckClass): void { + $this->context->registerSetupCheck( + $this->appId, + $setupCheckClass + ); + } }; } @@ -521,6 +531,13 @@ class RegistrationContext { } /** + * @psalm-param class-string<ISetupCheck> $setupCheckClass + */ + public function registerSetupCheck(string $appId, string $setupCheckClass): void { + $this->setupChecks[] = new ServiceRegistration($appId, $setupCheckClass); + } + + /** * @param App[] $apps */ public function delegateCapabilityRegistrations(array $apps): void { @@ -822,4 +839,11 @@ class RegistrationContext { public function getPublicShareTemplateProviders(): array { return $this->publicShareTemplateProviders; } + + /** + * @return ServiceRegistration<ISetupCheck>[] + */ + public function getSetupChecks(): array { + return $this->setupChecks; + } } diff --git a/lib/private/SetupCheck/SetupCheckManager.php b/lib/private/SetupCheck/SetupCheckManager.php new file mode 100644 index 00000000000..08c73fda893 --- /dev/null +++ b/lib/private/SetupCheck/SetupCheckManager.php @@ -0,0 +1,31 @@ +<?php + +namespace OC\SetupCheck; + +use OC\AppFramework\Bootstrap\Coordinator; +use OCP\Server; +use OCP\SetupCheck\ISetupCheck; + +class SetupCheckManager { + private Coordinator $coordinator; + + public function __construct(Coordinator $coordinator) { + $this->coordinator = $coordinator; + } + + public function runAll(): array { + $results = []; + $setupChecks = $this->coordinator->getRegistrationContext()->getSetupChecks(); + foreach ($setupChecks as $setupCheck) { + /** @var ISetupCheck $setupCheckObject */ + $setupCheckObject = Server::get($setupCheck->getService()); + $setupResult = $setupCheckObject->run(); + $category = $setupCheckObject->getCategory(); + if (!isset($results[$category])) { + $results[$category] = []; + } + $results[$category][$setupCheckObject->getName()] = $setupResult; + } + return $results; + } +} diff --git a/lib/public/AppFramework/Bootstrap/IRegistrationContext.php b/lib/public/AppFramework/Bootstrap/IRegistrationContext.php index c34cec38eb1..ad83129514f 100644 --- a/lib/public/AppFramework/Bootstrap/IRegistrationContext.php +++ b/lib/public/AppFramework/Bootstrap/IRegistrationContext.php @@ -371,4 +371,14 @@ interface IRegistrationContext { * @since 26.0.0 */ public function registerPublicShareTemplateProvider(string $class): void; + + /** + * Register an implementation of \OCP\SetupCheck\ISetupCheck that + * will handle the implementation of a setup check + * + * @psalm-param class-string<\OCP\SetupCheck\ISetupCheck> $setupCheckClass + * @return void + * @since 25.0.0 + */ + public function registerSetupCheck(string $setupCheckClass): void; } diff --git a/lib/public/SetupCheck/ISetupCheck.php b/lib/public/SetupCheck/ISetupCheck.php new file mode 100644 index 00000000000..e4f35b55f3c --- /dev/null +++ b/lib/public/SetupCheck/ISetupCheck.php @@ -0,0 +1,23 @@ +<?php +declare(strict_types=1); + +namespace OCP\SetupCheck; + +/** + * This interface needs to be implemented if you want to provide custom + * setup checks in your application. The results of these checks will them + * be displayed in the admin overview. + * + * @since 25.0.0 + */ +interface ISetupCheck { + /** + * @since 25.0.0 + */ + public function getCategory(): string; + + /** + * @since 25.0.0 + */ + public function run(): SetupResult; +} diff --git a/lib/public/SetupCheck/SetupResult.php b/lib/public/SetupCheck/SetupResult.php new file mode 100644 index 00000000000..d2096301690 --- /dev/null +++ b/lib/public/SetupCheck/SetupResult.php @@ -0,0 +1,66 @@ +<?php + +namespace OCP\SetupCheck; + +/** + * @brief This class is used for storing the result of a setup check + * + * @since 25.0.0 + */ +class SetupResult implements \JsonSerializable { + const SUCCESS = 'success'; + const INFO = 'info'; + const WARNING = 'warning'; + const ERROR = 'error'; + + private string $severity; + private ?string $description; + private ?string $linkToDoc; + + /** + * @psalm-param self::SUCCESS|self::INFO|self::WARNING|self::ERROR $severity + * @since 25.0.0 + */ + public function __construct(string $severity, ?string $description = null, ?string $linkToDoc = null) { + $this->severity = $severity; + $this->description = $description; + $this->linkToDoc = $linkToDoc; + } + + /** + * @brief Get the severity for the setup check result + * + * @psalm-return self::INFO|self::WARNING|self::ERROR + * @since 25.0.0 + */ + public function getSeverity(): string { + return $this->severity; + } + + /** + * @brief Get the description for the setup check result + * + * @since 25.0.0 + */ + public function getDescription(): ?string { + return $this->description; + } + + /** + * @brief Get a link to the doc for the explanation. + * + * @since 25.0.0 + */ + public function getLinkToDoc(): ?string { + return $this->linkToDoc; + } + + #[\ReturnTypeWillChange] + function jsonSerialize() { + return [ + 'severity' => $this->severity, + 'description' => $this->description, + 'linkToDoc' => $this->linkToDoc, + ]; + } +} |