]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add $name property in SetupResult and improve API
authorCôme Chilliet <come.chilliet@nextcloud.com>
Mon, 6 Nov 2023 15:21:15 +0000 (16:21 +0100)
committerCôme Chilliet <come.chilliet@nextcloud.com>
Tue, 7 Nov 2023 13:15:47 +0000 (14:15 +0100)
Keys for check results are not locale dependent anymore, the name of the
 setup check is instead stored in the setup result object.

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
core/Command/SetupChecks.php
lib/private/SetupCheck/SetupCheckManager.php
lib/public/SetupCheck/ISetupCheck.php
lib/public/SetupCheck/SetupResult.php

index ed0d22bdfc04c7adb39bc57894e6968691aa0628..bd76a9d1e657f75cc508f20efb9624d8071864bb 100644 (file)
@@ -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;
                                }
index f9e67772019ac4e311c47134905a6c9bcd07393c..b8b6cfa11e7d935fb52f21190f0f2e1a8f9c65f7 100644 (file)
@@ -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;
        }
index 77eeaea4df1419745ab9ec44bae3db7df4f33436..96eb6ddd7dacaacae7c1f708baeee5f431ede669 100644 (file)
@@ -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;
 
index 27026f82815069e5389feb7dd961d4ecaa88ae87..e4a7744178a244def5ecbe7262baa929cdc23b2b 100644 (file)
@@ -37,6 +37,11 @@ class SetupResult implements \JsonSerializable {
        public const WARNING = 'warning';
        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
@@ -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 {
@@ -100,6 +113,24 @@ class SetupResult implements \JsonSerializable {
                return $this->description;
        }
 
+       /**
+        * @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.
         *
@@ -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,