diff options
author | Côme Chilliet <91878298+come-nc@users.noreply.github.com> | 2023-11-07 16:51:57 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-07 16:51:57 +0100 |
commit | 3e6642ab0b4d0a95ef4ebff8553ae93a6b9e6d00 (patch) | |
tree | 3596bc688e7b4e7a0ff78d06c491eda9eced23c5 | |
parent | b49400cc18fc4726da7f7b581c76f37481467592 (diff) | |
parent | 86290dd8887eb2d87b6d6745eac78809238ff794 (diff) | |
download | nextcloud-server-3e6642ab0b4d0a95ef4ebff8553ae93a6b9e6d00.tar.gz nextcloud-server-3e6642ab0b4d0a95ef4ebff8553ae93a6b9e6d00.zip |
Merge pull request #41311 from nextcloud/fix/improve-setup-checks-api
Improve setup checks API
-rw-r--r-- | apps/settings/lib/SetupChecks/PhpModules.php | 4 | ||||
-rw-r--r-- | core/Command/SetupChecks.php | 6 | ||||
-rw-r--r-- | lib/private/SetupCheck/SetupCheckManager.php | 3 | ||||
-rw-r--r-- | lib/public/SetupCheck/ISetupCheck.php | 2 | ||||
-rw-r--r-- | lib/public/SetupCheck/SetupResult.php | 32 |
5 files changed, 41 insertions, 6 deletions
diff --git a/apps/settings/lib/SetupChecks/PhpModules.php b/apps/settings/lib/SetupChecks/PhpModules.php index 870c2b7ada1..feb5e587999 100644 --- a/apps/settings/lib/SetupChecks/PhpModules.php +++ b/apps/settings/lib/SetupChecks/PhpModules.php @@ -75,12 +75,12 @@ class PhpModules implements ISetupCheck { $missingRequiredModules = $this->getMissingModules(self::REQUIRED_MODULES); if (!empty($missingRequiredModules)) { return SetupResult::error( - $this->l10n->t('This instance is missing some required PHP modules. It is required to install them: %s', implode(', ', $missingRequiredModules)), + $this->l10n->t('This instance is missing some required PHP modules. It is required to install them: %s.', implode(', ', $missingRequiredModules)), $this->urlGenerator->linkToDocs('admin-php-modules') ); } elseif (!empty($missingRecommendedModules)) { return SetupResult::info( - $this->l10n->t('This instance is missing some recommended PHP modules. For improved performance and better compatibility it is highly recommended to install them: %s', implode(', ', $missingRecommendedModules)), + $this->l10n->t('This instance is missing some recommended PHP modules. For improved performance and better compatibility it is highly recommended to install them: %s.', implode(', ', $missingRecommendedModules)), $this->urlGenerator->linkToDocs('admin-php-modules') ); } else { diff --git a/core/Command/SetupChecks.php b/core/Command/SetupChecks.php index ed0d22bdfc0..bd76a9d1e65 100644 --- a/core/Command/SetupChecks.php +++ b/core/Command/SetupChecks.php @@ -55,7 +55,7 @@ class SetupChecks extends Base { default: foreach ($results as $category => $checks) { $output->writeln("\t{$category}:"); - foreach ($checks as $title => $check) { + foreach ($checks as $check) { $styleTag = match ($check->getSeverity()) { 'success' => 'info', 'error' => 'error', @@ -74,7 +74,7 @@ class SetupChecks extends Base { "\t\t". ($styleTag !== null ? "<{$styleTag}>" : ''). "{$emoji} ". - $title. + ($check->getName() ?? $check::class). ($description !== null ? ': '.$description : ''). ($styleTag !== null ? "</{$styleTag}>" : ''), $verbosity @@ -83,7 +83,7 @@ class SetupChecks extends Base { } } foreach ($results as $category => $checks) { - foreach ($checks as $title => $check) { + foreach ($checks as $check) { if ($check->getSeverity() !== 'success') { return self::FAILURE; } diff --git a/lib/private/SetupCheck/SetupCheckManager.php b/lib/private/SetupCheck/SetupCheckManager.php index f9e67772019..b8b6cfa11e7 100644 --- a/lib/private/SetupCheck/SetupCheckManager.php +++ b/lib/private/SetupCheck/SetupCheckManager.php @@ -47,9 +47,10 @@ class SetupCheckManager implements ISetupCheckManager { $setupCheckObject = Server::get($setupCheck->getService()); $this->logger->debug('Running check '.get_class($setupCheckObject)); $setupResult = $setupCheckObject->run(); + $setupResult->setName($setupCheckObject->getName()); $category = $setupCheckObject->getCategory(); $results[$category] ??= []; - $results[$category][$setupCheckObject->getName()] = $setupResult; + $results[$category][$setupCheckObject::class] = $setupResult; } return $results; } diff --git a/lib/public/SetupCheck/ISetupCheck.php b/lib/public/SetupCheck/ISetupCheck.php index 77eeaea4df1..96eb6ddd7da 100644 --- a/lib/public/SetupCheck/ISetupCheck.php +++ b/lib/public/SetupCheck/ISetupCheck.php @@ -36,11 +36,13 @@ namespace OCP\SetupCheck; interface ISetupCheck { /** * @since 28.0.0 + * @return string Category id, one of security/system/accounts, or a custom one which will be merged in system */ public function getCategory(): string; /** * @since 28.0.0 + * @return string Translated name to display to the user */ public function getName(): string; diff --git a/lib/public/SetupCheck/SetupResult.php b/lib/public/SetupCheck/SetupResult.php index 27026f82815..e4a7744178a 100644 --- a/lib/public/SetupCheck/SetupResult.php +++ b/lib/public/SetupCheck/SetupResult.php @@ -38,6 +38,11 @@ class SetupResult implements \JsonSerializable { public const ERROR = 'error'; /** + * @param string $name Translated name to display to the user + */ + private ?string $name = null; + + /** * @brief Private constructor, use success()/info()/warning()/error() instead * @param self::SUCCESS|self::INFO|self::WARNING|self::ERROR $severity * @since 28.0.0 @@ -51,6 +56,8 @@ class SetupResult implements \JsonSerializable { /** * @brief Create a success result object + * @param ?string $description Translated detailed description to display to the user + * @param ?string $linkToDoc URI of related relevent documentation, be it from Nextcloud or another project * @since 28.0.0 */ public static function success(?string $description = null, ?string $linkToDoc = null): self { @@ -59,6 +66,8 @@ class SetupResult implements \JsonSerializable { /** * @brief Create an info result object + * @param ?string $description Translated detailed description to display to the user + * @param ?string $linkToDoc URI of related relevent documentation, be it from Nextcloud or another project * @since 28.0.0 */ public static function info(?string $description = null, ?string $linkToDoc = null): self { @@ -67,6 +76,8 @@ class SetupResult implements \JsonSerializable { /** * @brief Create a warning result object + * @param ?string $description Translated detailed description to display to the user + * @param ?string $linkToDoc URI of related relevent documentation, be it from Nextcloud or another project * @since 28.0.0 */ public static function warning(?string $description = null, ?string $linkToDoc = null): self { @@ -75,6 +86,8 @@ class SetupResult implements \JsonSerializable { /** * @brief Create an error result object + * @param ?string $description Translated detailed description to display to the user + * @param ?string $linkToDoc URI of related relevent documentation, be it from Nextcloud or another project * @since 28.0.0 */ public static function error(?string $description = null, ?string $linkToDoc = null): self { @@ -101,6 +114,24 @@ class SetupResult implements \JsonSerializable { } /** + * @brief Get the name for the setup check + * + * @since 28.0.0 + */ + public function getName(): ?string { + return $this->name; + } + + /** + * @brief Set the name from the setup check + * + * @since 28.0.0 + */ + public function setName(string $name): void { + $this->name = $name; + } + + /** * @brief Get a link to the doc for the explanation. * * @since 28.0.0 @@ -116,6 +147,7 @@ class SetupResult implements \JsonSerializable { */ public function jsonSerialize(): array { return [ + 'name' => $this->name, 'severity' => $this->severity, 'description' => $this->description, 'linkToDoc' => $this->linkToDoc, |