diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2023-10-02 11:21:45 +0200 |
---|---|---|
committer | Côme Chilliet <come.chilliet@nextcloud.com> | 2023-10-19 11:44:00 +0200 |
commit | a4618cfea0710e919fcab9a80a61fcf4ed55759c (patch) | |
tree | 710dfe9ebcc81293ff9b0c2688201a3c3392374b | |
parent | a56d40cf2d8a16171bacf712124a5e025ffd8d83 (diff) | |
download | nextcloud-server-a4618cfea0710e919fcab9a80a61fcf4ed55759c.tar.gz nextcloud-server-a4618cfea0710e919fcab9a80a61fcf4ed55759c.zip |
Move existing setup checks to new API
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
-rw-r--r-- | apps/settings/lib/AppInfo/Application.php | 6 | ||||
-rw-r--r-- | apps/settings/lib/Controller/CheckSetupController.php | 12 | ||||
-rw-r--r-- | apps/settings/lib/SetupChecks/PhpDefaultCharset.php | 27 | ||||
-rw-r--r-- | apps/settings/lib/SetupChecks/PhpOutputBuffering.php | 27 | ||||
-rw-r--r-- | apps/settings/lib/SetupChecks/SupportedDatabase.php | 55 |
5 files changed, 65 insertions, 62 deletions
diff --git a/apps/settings/lib/AppInfo/Application.php b/apps/settings/lib/AppInfo/Application.php index 83f801208ed..48dc28c7216 100644 --- a/apps/settings/lib/AppInfo/Application.php +++ b/apps/settings/lib/AppInfo/Application.php @@ -50,7 +50,10 @@ use OCA\Settings\Search\SectionSearch; use OCA\Settings\Search\UserSearch; use OCA\Settings\SetupChecks\CheckUserCertificates; use OCA\Settings\SetupChecks\LegacySSEKeyFormat; +use OCA\Settings\SetupChecks\PhpDefaultCharset; use OCA\Settings\SetupChecks\PhpOutdated; +use OCA\Settings\SetupChecks\PhpOutputBuffering; +use OCA\Settings\SetupChecks\SupportedDatabase; use OCA\Settings\UserMigration\AccountMigrator; use OCA\Settings\WellKnown\ChangePasswordHandler; use OCA\Settings\WellKnown\SecurityTxtHandler; @@ -142,7 +145,10 @@ class Application extends App implements IBootstrap { }); $context->registerSetupCheck(CheckUserCertificates::class); $context->registerSetupCheck(LegacySSEKeyFormat::class); + $context->registerSetupCheck(PhpDefaultCharset::class); $context->registerSetupCheck(PhpOutdated::class); + $context->registerSetupCheck(PhpOutputBuffering::class); + $context->registerSetupCheck(SupportedDatabase::class); $context->registerUserMigrator(AccountMigrator::class); } diff --git a/apps/settings/lib/Controller/CheckSetupController.php b/apps/settings/lib/Controller/CheckSetupController.php index 829873f0069..564f39e411a 100644 --- a/apps/settings/lib/Controller/CheckSetupController.php +++ b/apps/settings/lib/Controller/CheckSetupController.php @@ -48,7 +48,6 @@ namespace OCA\Settings\Controller; use bantu\IniGetWrapper\IniGetWrapper; use DirectoryIterator; use Doctrine\DBAL\Exception; -use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\TransactionIsolationLevel; use GuzzleHttp\Exception\ClientException; use OC; @@ -62,12 +61,7 @@ use OC\IntegrityCheck\Checker; use OC\Lock\NoopLockingProvider; use OC\Lock\DBLockingProvider; use OC\MemoryInfo; -use OCA\Settings\SetupChecks\CheckUserCertificates; use OCA\Settings\SetupChecks\NeedsSystemAddressBookSync; -use OCA\Settings\SetupChecks\LegacySSEKeyFormat; -use OCA\Settings\SetupChecks\PhpDefaultCharset; -use OCA\Settings\SetupChecks\PhpOutputBuffering; -use OCA\Settings\SetupChecks\SupportedDatabase; use OCP\App\IAppManager; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\Attribute\IgnoreOpenAPI; @@ -917,9 +911,6 @@ Raw output * @AuthorizedAdminSetting(settings=OCA\Settings\Settings\Admin\Overview) */ public function check() { - $phpDefaultCharset = new PhpDefaultCharset(); - $phpOutputBuffering = new PhpOutputBuffering(); - $supportedDatabases = new SupportedDatabase($this->l10n, $this->connection); $needsSystemAddressBookSync = new NeedsSystemAddressBookSync($this->config, $this->l10n); return new DataResponse( @@ -968,10 +959,7 @@ Raw output 'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed' => $this->isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed(), 'reverseProxyGeneratedURL' => $this->urlGenerator->getAbsoluteURL('index.php'), 'imageMagickLacksSVGSupport' => $this->imageMagickLacksSVGSupport(), - PhpDefaultCharset::class => ['pass' => $phpDefaultCharset->run(), 'description' => $phpDefaultCharset->description(), 'severity' => $phpDefaultCharset->severity()], - PhpOutputBuffering::class => ['pass' => $phpOutputBuffering->run(), 'description' => $phpOutputBuffering->description(), 'severity' => $phpOutputBuffering->severity()], 'isDefaultPhoneRegionSet' => $this->config->getSystemValueString('default_phone_region', '') !== '', - SupportedDatabase::class => ['pass' => $supportedDatabases->run(), 'description' => $supportedDatabases->description(), 'severity' => $supportedDatabases->severity()], 'temporaryDirectoryWritable' => $this->isTemporaryDirectoryWritable(), NeedsSystemAddressBookSync::class => ['pass' => $needsSystemAddressBookSync->run(), 'description' => $needsSystemAddressBookSync->description(), 'severity' => $needsSystemAddressBookSync->severity()], ] diff --git a/apps/settings/lib/SetupChecks/PhpDefaultCharset.php b/apps/settings/lib/SetupChecks/PhpDefaultCharset.php index 0ad5e2f56ea..5c14e9a6734 100644 --- a/apps/settings/lib/SetupChecks/PhpDefaultCharset.php +++ b/apps/settings/lib/SetupChecks/PhpDefaultCharset.php @@ -25,16 +25,29 @@ declare(strict_types=1); */ namespace OCA\Settings\SetupChecks; -class PhpDefaultCharset { - public function description(): string { - return 'PHP configuration option default_charset should be UTF-8'; +use OCP\IL10N; +use OCP\SetupCheck\ISetupCheck; +use OCP\SetupCheck\SetupResult; + +class PhpDefaultCharset implements ISetupCheck { + public function __construct( + private IL10N $l10n, + ) { + } + + public function getName(): string { + return $this->l10n->t('Checking for PHP default charset'); } - public function severity(): string { - return 'warning'; + public function getCategory(): string { + return 'php'; } - public function run(): bool { - return strtoupper(trim(ini_get('default_charset'))) === 'UTF-8'; + public function run(): SetupResult { + if (strtoupper(trim(ini_get('default_charset'))) === 'UTF-8') { + return new SetupResult(SetupResult::SUCCESS); + } else { + return new SetupResult(SetupResult::WARNING, $this->l10n->t('PHP configuration option default_charset should be UTF-8')); + } } } diff --git a/apps/settings/lib/SetupChecks/PhpOutputBuffering.php b/apps/settings/lib/SetupChecks/PhpOutputBuffering.php index 3bf52695301..f3a21418c1c 100644 --- a/apps/settings/lib/SetupChecks/PhpOutputBuffering.php +++ b/apps/settings/lib/SetupChecks/PhpOutputBuffering.php @@ -25,17 +25,30 @@ declare(strict_types=1); */ namespace OCA\Settings\SetupChecks; -class PhpOutputBuffering { - public function description(): string { - return 'PHP configuration option output_buffering must be disabled'; +use OCP\IL10N; +use OCP\SetupCheck\ISetupCheck; +use OCP\SetupCheck\SetupResult; + +class PhpOutputBuffering implements ISetupCheck { + public function __construct( + private IL10N $l10n, + ) { + } + + public function getCategory(): string { + return 'php'; } - public function severity(): string { - return 'error'; + public function getName(): string { + return $this->l10n->t('Checking for PHP output_buffering option'); } - public function run(): bool { + public function run(): SetupResult { $value = trim(ini_get('output_buffering')); - return $value === '' || $value === '0'; + if ($value === '' || $value === '0') { + return new SetupResult(SetupResult::SUCCESS); + } else { + return new SetupResult(SetupResult::ERROR, $this->l10n->t('PHP configuration option output_buffering must be disabled')); + } } } diff --git a/apps/settings/lib/SetupChecks/SupportedDatabase.php b/apps/settings/lib/SetupChecks/SupportedDatabase.php index c925ad48043..0cbaa5b114e 100644 --- a/apps/settings/lib/SetupChecks/SupportedDatabase.php +++ b/apps/settings/lib/SetupChecks/SupportedDatabase.php @@ -37,27 +37,25 @@ use Doctrine\DBAL\Platforms\PostgreSQL94Platform; use Doctrine\DBAL\Platforms\SqlitePlatform; use OCP\IDBConnection; use OCP\IL10N; +use OCP\SetupCheck\ISetupCheck; +use OCP\SetupCheck\SetupResult; -class SupportedDatabase { - /** @var IL10N */ - private $l10n; - /** @var IDBConnection */ - private $connection; - - private $checked = false; - private $description = ''; +class SupportedDatabase implements ISetupCheck { + public function __construct( + private IL10N $l10n, + private IDBConnection $connection, + ) { + } - public function __construct(IL10N $l10n, IDBConnection $connection) { - $this->l10n = $l10n; - $this->connection = $connection; + public function getCategory(): string { + return 'database'; } - public function check() { - if ($this->checked === true) { - return; - } - $this->checked = true; + public function getName(): string { + return $this->l10n->t('Checking for database version'); + } + public function run(): SetupResult { switch (get_class($this->connection->getDatabasePlatform())) { case MySQL80Platform::class: # extends MySQL57Platform case MySQL57Platform::class: # extends MySQLPlatform @@ -70,13 +68,11 @@ class SupportedDatabase { if (str_contains($version, 'mariadb')) { if (version_compare($version, '10.2', '<')) { - $this->description = $this->l10n->t('MariaDB version "%s" is used. Nextcloud 21 and higher do not support this version and require MariaDB 10.2 or higher.', $row['Value']); - return; + return new SetupResult(SetupResult::WARNING, $this->l10n->t('MariaDB version "%s" is used. Nextcloud 21 and higher do not support this version and require MariaDB 10.2 or higher.', $row['Value'])); } } else { if (version_compare($version, '8', '<')) { - $this->description = $this->l10n->t('MySQL version "%s" is used. Nextcloud 21 and higher do not support this version and require MySQL 8.0 or MariaDB 10.2 or higher.', $row['Value']); - return; + return new SetupResult(SetupResult::WARNING, $this->l10n->t('MySQL version "%s" is used. Nextcloud 21 and higher do not support this version and require MySQL 8.0 or MariaDB 10.2 or higher.', $row['Value'])); } } break; @@ -88,26 +84,13 @@ class SupportedDatabase { $result->execute(); $row = $result->fetch(); if (version_compare($row['server_version'], '9.6', '<')) { - $this->description = $this->l10n->t('PostgreSQL version "%s" is used. Nextcloud 21 and higher do not support this version and require PostgreSQL 9.6 or higher.', $row['server_version']); - return; + return new SetupResult(SetupResult::WARNING, $this->l10n->t('PostgreSQL version "%s" is used. Nextcloud 21 and higher do not support this version and require PostgreSQL 9.6 or higher.', $row['server_version'])); } break; case OraclePlatform::class: break; } - } - - public function description(): string { - $this->check(); - return $this->description; - } - - public function severity(): string { - return 'info'; - } - - public function run(): bool { - $this->check(); - return $this->description === ''; + // TODO still show db and version on success? + return new SetupResult(SetupResult::SUCCESS); } } |