aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/composer/composer/autoload_classmap.php4
-rw-r--r--lib/composer/composer/autoload_static.php4
-rw-r--r--lib/private/AppFramework/Bootstrap/RegistrationContext.php30
-rw-r--r--lib/private/Server.php4
-rw-r--r--lib/private/SetupCheck/SetupCheckManager.php56
-rw-r--r--lib/public/AppFramework/Bootstrap/IRegistrationContext.php9
-rw-r--r--lib/public/SetupCheck/ISetupCheck.php51
-rw-r--r--lib/public/SetupCheck/ISetupCheckManager.php37
-rw-r--r--lib/public/SetupCheck/SetupResult.php124
9 files changed, 316 insertions, 3 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index 4387852556d..9d0570d349c 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -601,6 +601,9 @@ 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\\ISetupCheckManager' => $baseDir . '/lib/public/SetupCheck/ISetupCheckManager.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',
@@ -1653,6 +1656,7 @@ return array(
'OC\\Settings\\Manager' => $baseDir . '/lib/private/Settings/Manager.php',
'OC\\Settings\\Section' => $baseDir . '/lib/private/Settings/Section.php',
'OC\\Setup' => $baseDir . '/lib/private/Setup.php',
+ 'OC\\SetupCheck\\SetupCheckManager' => $baseDir . '/lib/private/SetupCheck/SetupCheckManager.php',
'OC\\Setup\\AbstractDatabase' => $baseDir . '/lib/private/Setup/AbstractDatabase.php',
'OC\\Setup\\MySQL' => $baseDir . '/lib/private/Setup/MySQL.php',
'OC\\Setup\\OCI' => $baseDir . '/lib/private/Setup/OCI.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index 9b33577d66a..63ad21216a4 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -634,6 +634,9 @@ 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\\ISetupCheckManager' => __DIR__ . '/../../..' . '/lib/public/SetupCheck/ISetupCheckManager.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',
@@ -1686,6 +1689,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\Settings\\Manager' => __DIR__ . '/../../..' . '/lib/private/Settings/Manager.php',
'OC\\Settings\\Section' => __DIR__ . '/../../..' . '/lib/private/Settings/Section.php',
'OC\\Setup' => __DIR__ . '/../../..' . '/lib/private/Setup.php',
+ 'OC\\SetupCheck\\SetupCheckManager' => __DIR__ . '/../../..' . '/lib/private/SetupCheck/SetupCheckManager.php',
'OC\\Setup\\AbstractDatabase' => __DIR__ . '/../../..' . '/lib/private/Setup/AbstractDatabase.php',
'OC\\Setup\\MySQL' => __DIR__ . '/../../..' . '/lib/private/Setup/MySQL.php',
'OC\\Setup\\OCI' => __DIR__ . '/../../..' . '/lib/private/Setup/OCI.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/Server.php b/lib/private/Server.php
index 949a7ccfd3f..b8004670634 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -149,6 +149,7 @@ use OC\Security\SecureRandom;
use OC\Security\TrustedDomainHelper;
use OC\Security\VerificationToken\VerificationToken;
use OC\Session\CryptoWrapper;
+use OC\SetupCheck\SetupCheckManager;
use OC\Share20\ProviderFactory;
use OC\Share20\ShareDisableChecker;
use OC\Share20\ShareHelper;
@@ -247,6 +248,7 @@ use OCP\Security\ISecureRandom;
use OCP\Security\ITrustedDomainHelper;
use OCP\Security\RateLimiting\ILimiter;
use OCP\Security\VerificationToken\IVerificationToken;
+use OCP\SetupCheck\ISetupCheckManager;
use OCP\Share\IShareHelper;
use OCP\SpeechToText\ISpeechToTextManager;
use OCP\SystemTag\ISystemTagManager;
@@ -1430,6 +1432,8 @@ class Server extends ServerContainer implements IServerContainer {
$this->registerAlias(IOCMProvider::class, OCMProvider::class);
+ $this->registerAlias(ISetupCheckManager::class, SetupCheckManager::class);
+
$this->connectDispatcher();
}
diff --git a/lib/private/SetupCheck/SetupCheckManager.php b/lib/private/SetupCheck/SetupCheckManager.php
new file mode 100644
index 00000000000..f9e67772019
--- /dev/null
+++ b/lib/private/SetupCheck/SetupCheckManager.php
@@ -0,0 +1,56 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2022 Carl Schwan <carl@carlschwan.eu>
+ *
+ * @author Carl Schwan <carl@carlschwan.eu>
+ * @author Côme Chilliet <come.chilliet@nextcloud.com>
+ *
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OC\SetupCheck;
+
+use OC\AppFramework\Bootstrap\Coordinator;
+use OCP\Server;
+use OCP\SetupCheck\ISetupCheck;
+use OCP\SetupCheck\ISetupCheckManager;
+use Psr\Log\LoggerInterface;
+
+class SetupCheckManager implements ISetupCheckManager {
+ public function __construct(
+ private Coordinator $coordinator,
+ private LoggerInterface $logger,
+ ) {
+ }
+
+ public function runAll(): array {
+ $results = [];
+ $setupChecks = $this->coordinator->getRegistrationContext()->getSetupChecks();
+ foreach ($setupChecks as $setupCheck) {
+ /** @var ISetupCheck $setupCheckObject */
+ $setupCheckObject = Server::get($setupCheck->getService());
+ $this->logger->debug('Running check '.get_class($setupCheckObject));
+ $setupResult = $setupCheckObject->run();
+ $category = $setupCheckObject->getCategory();
+ $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..2398c5ef931 100644
--- a/lib/public/AppFramework/Bootstrap/IRegistrationContext.php
+++ b/lib/public/AppFramework/Bootstrap/IRegistrationContext.php
@@ -371,4 +371,13 @@ 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
+ *
+ * @param class-string<\OCP\SetupCheck\ISetupCheck> $setupCheckClass
+ * @since 28.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..77eeaea4df1
--- /dev/null
+++ b/lib/public/SetupCheck/ISetupCheck.php
@@ -0,0 +1,51 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2022 Carl Schwan <carl@carlschwan.eu>
+ *
+ * @author Carl Schwan <carl@carlschwan.eu>
+ * @author Côme Chilliet <come.chilliet@nextcloud.com>
+ *
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+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 28.0.0
+ */
+interface ISetupCheck {
+ /**
+ * @since 28.0.0
+ */
+ public function getCategory(): string;
+
+ /**
+ * @since 28.0.0
+ */
+ public function getName(): string;
+
+ /**
+ * @since 28.0.0
+ */
+ public function run(): SetupResult;
+}
diff --git a/lib/public/SetupCheck/ISetupCheckManager.php b/lib/public/SetupCheck/ISetupCheckManager.php
new file mode 100644
index 00000000000..4b963e7c6b8
--- /dev/null
+++ b/lib/public/SetupCheck/ISetupCheckManager.php
@@ -0,0 +1,37 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2023 Côme Chilliet <come.chilliet@nextcloud.com>
+ *
+ * @author Côme Chilliet <come.chilliet@nextcloud.com>
+ *
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCP\SetupCheck;
+
+/**
+ * @since 28.0.0
+ */
+interface ISetupCheckManager {
+ /**
+ * @since 28.0.0
+ * @return array<string,array<string,SetupResult>> Result of each check, first level key is category, second level key is title
+ */
+ public function runAll(): array;
+}
diff --git a/lib/public/SetupCheck/SetupResult.php b/lib/public/SetupCheck/SetupResult.php
new file mode 100644
index 00000000000..27026f82815
--- /dev/null
+++ b/lib/public/SetupCheck/SetupResult.php
@@ -0,0 +1,124 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2022 Carl Schwan <carl@carlschwan.eu>
+ *
+ * @author Carl Schwan <carl@carlschwan.eu>
+ * @author Côme Chilliet <come.chilliet@nextcloud.com>
+ *
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCP\SetupCheck;
+
+/**
+ * @brief This class is used for storing the result of a setup check
+ *
+ * @since 28.0.0
+ */
+class SetupResult implements \JsonSerializable {
+ public const SUCCESS = 'success';
+ public const INFO = 'info';
+ public const WARNING = 'warning';
+ public const ERROR = 'error';
+
+ /**
+ * @brief Private constructor, use success()/info()/warning()/error() instead
+ * @param self::SUCCESS|self::INFO|self::WARNING|self::ERROR $severity
+ * @since 28.0.0
+ */
+ private function __construct(
+ private string $severity,
+ private ?string $description = null,
+ private ?string $linkToDoc = null,
+ ) {
+ }
+
+ /**
+ * @brief Create a success result object
+ * @since 28.0.0
+ */
+ public static function success(?string $description = null, ?string $linkToDoc = null): self {
+ return new self(self::SUCCESS, $description, $linkToDoc);
+ }
+
+ /**
+ * @brief Create an info result object
+ * @since 28.0.0
+ */
+ public static function info(?string $description = null, ?string $linkToDoc = null): self {
+ return new self(self::INFO, $description, $linkToDoc);
+ }
+
+ /**
+ * @brief Create a warning result object
+ * @since 28.0.0
+ */
+ public static function warning(?string $description = null, ?string $linkToDoc = null): self {
+ return new self(self::WARNING, $description, $linkToDoc);
+ }
+
+ /**
+ * @brief Create an error result object
+ * @since 28.0.0
+ */
+ public static function error(?string $description = null, ?string $linkToDoc = null): self {
+ return new self(self::ERROR, $description, $linkToDoc);
+ }
+
+ /**
+ * @brief Get the severity for the setup check result
+ *
+ * @return self::SUCCESS|self::INFO|self::WARNING|self::ERROR
+ * @since 28.0.0
+ */
+ public function getSeverity(): string {
+ return $this->severity;
+ }
+
+ /**
+ * @brief Get the description for the setup check result
+ *
+ * @since 28.0.0
+ */
+ public function getDescription(): ?string {
+ return $this->description;
+ }
+
+ /**
+ * @brief Get a link to the doc for the explanation.
+ *
+ * @since 28.0.0
+ */
+ public function getLinkToDoc(): ?string {
+ return $this->linkToDoc;
+ }
+
+ /**
+ * @brief Get an array representation of the result for API responses
+ *
+ * @since 28.0.0
+ */
+ public function jsonSerialize(): array {
+ return [
+ 'severity' => $this->severity,
+ 'description' => $this->description,
+ 'linkToDoc' => $this->linkToDoc,
+ ];
+ }
+}