Skip to content

Commit bd23116

Browse files
committed
Move existing setup checks to new API
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent 6000049 commit bd23116

File tree

5 files changed

+65
-62
lines changed

5 files changed

+65
-62
lines changed

apps/settings/lib/AppInfo/Application.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@
4848
use OCA\Settings\Search\SectionSearch;
4949
use OCA\Settings\SetupChecks\CheckUserCertificates;
5050
use OCA\Settings\SetupChecks\LegacySSEKeyFormat;
51+
use OCA\Settings\SetupChecks\PhpDefaultCharset;
5152
use OCA\Settings\SetupChecks\PhpOutdated;
53+
use OCA\Settings\SetupChecks\PhpOutputBuffering;
54+
use OCA\Settings\SetupChecks\SupportedDatabase;
5255
use OCA\Settings\UserMigration\AccountMigrator;
5356
use OCA\Settings\WellKnown\ChangePasswordHandler;
5457
use OCA\Settings\WellKnown\SecurityTxtHandler;
@@ -139,7 +142,10 @@ public function register(IRegistrationContext $context): void {
139142
});
140143
$context->registerSetupCheck(CheckUserCertificates::class);
141144
$context->registerSetupCheck(LegacySSEKeyFormat::class);
145+
$context->registerSetupCheck(PhpDefaultCharset::class);
142146
$context->registerSetupCheck(PhpOutdated::class);
147+
$context->registerSetupCheck(PhpOutputBuffering::class);
148+
$context->registerSetupCheck(SupportedDatabase::class);
143149

144150
$context->registerUserMigrator(AccountMigrator::class);
145151
}

apps/settings/lib/Controller/CheckSetupController.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
use bantu\IniGetWrapper\IniGetWrapper;
4949
use DirectoryIterator;
5050
use Doctrine\DBAL\Exception;
51-
use Doctrine\DBAL\Platforms\SqlitePlatform;
5251
use Doctrine\DBAL\TransactionIsolationLevel;
5352
use GuzzleHttp\Exception\ClientException;
5453
use OC;
@@ -62,12 +61,7 @@
6261
use OC\Lock\NoopLockingProvider;
6362
use OC\Lock\DBLockingProvider;
6463
use OC\MemoryInfo;
65-
use OCA\Settings\SetupChecks\CheckUserCertificates;
6664
use OCA\Settings\SetupChecks\NeedsSystemAddressBookSync;
67-
use OCA\Settings\SetupChecks\LegacySSEKeyFormat;
68-
use OCA\Settings\SetupChecks\PhpDefaultCharset;
69-
use OCA\Settings\SetupChecks\PhpOutputBuffering;
70-
use OCA\Settings\SetupChecks\SupportedDatabase;
7165
use OCP\App\IAppManager;
7266
use OCP\AppFramework\Controller;
7367
use OCP\AppFramework\Http\Attribute\IgnoreOpenAPI;
@@ -917,9 +911,6 @@ protected function imageMagickLacksSVGSupport(): bool {
917911
* @AuthorizedAdminSetting(settings=OCA\Settings\Settings\Admin\Overview)
918912
*/
919913
public function check() {
920-
$phpDefaultCharset = new PhpDefaultCharset();
921-
$phpOutputBuffering = new PhpOutputBuffering();
922-
$supportedDatabases = new SupportedDatabase($this->l10n, $this->connection);
923914
$needsSystemAddressBookSync = new NeedsSystemAddressBookSync($this->config, $this->l10n);
924915

925916
return new DataResponse(
@@ -968,10 +959,7 @@ public function check() {
968959
'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed' => $this->isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed(),
969960
'reverseProxyGeneratedURL' => $this->urlGenerator->getAbsoluteURL('index.php'),
970961
'imageMagickLacksSVGSupport' => $this->imageMagickLacksSVGSupport(),
971-
PhpDefaultCharset::class => ['pass' => $phpDefaultCharset->run(), 'description' => $phpDefaultCharset->description(), 'severity' => $phpDefaultCharset->severity()],
972-
PhpOutputBuffering::class => ['pass' => $phpOutputBuffering->run(), 'description' => $phpOutputBuffering->description(), 'severity' => $phpOutputBuffering->severity()],
973962
'isDefaultPhoneRegionSet' => $this->config->getSystemValueString('default_phone_region', '') !== '',
974-
SupportedDatabase::class => ['pass' => $supportedDatabases->run(), 'description' => $supportedDatabases->description(), 'severity' => $supportedDatabases->severity()],
975963
'temporaryDirectoryWritable' => $this->isTemporaryDirectoryWritable(),
976964
NeedsSystemAddressBookSync::class => ['pass' => $needsSystemAddressBookSync->run(), 'description' => $needsSystemAddressBookSync->description(), 'severity' => $needsSystemAddressBookSync->severity()],
977965
]

apps/settings/lib/SetupChecks/PhpDefaultCharset.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,29 @@
2525
*/
2626
namespace OCA\Settings\SetupChecks;
2727

28-
class PhpDefaultCharset {
29-
public function description(): string {
30-
return 'PHP configuration option default_charset should be UTF-8';
28+
use OCP\IL10N;
29+
use OCP\SetupCheck\ISetupCheck;
30+
use OCP\SetupCheck\SetupResult;
31+
32+
class PhpDefaultCharset implements ISetupCheck {
33+
public function __construct(
34+
private IL10N $l10n,
35+
) {
36+
}
37+
38+
public function getName(): string {
39+
return $this->l10n->t('Checking for PHP default charset');
3140
}
3241

33-
public function severity(): string {
34-
return 'warning';
42+
public function getCategory(): string {
43+
return 'php';
3544
}
3645

37-
public function run(): bool {
38-
return strtoupper(trim(ini_get('default_charset'))) === 'UTF-8';
46+
public function run(): SetupResult {
47+
if (strtoupper(trim(ini_get('default_charset'))) === 'UTF-8') {
48+
return new SetupResult(SetupResult::SUCCESS);
49+
} else {
50+
return new SetupResult(SetupResult::WARNING, $this->l10n->t('PHP configuration option default_charset should be UTF-8'));
51+
}
3952
}
4053
}

apps/settings/lib/SetupChecks/PhpOutputBuffering.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,30 @@
2525
*/
2626
namespace OCA\Settings\SetupChecks;
2727

28-
class PhpOutputBuffering {
29-
public function description(): string {
30-
return 'PHP configuration option output_buffering must be disabled';
28+
use OCP\IL10N;
29+
use OCP\SetupCheck\ISetupCheck;
30+
use OCP\SetupCheck\SetupResult;
31+
32+
class PhpOutputBuffering implements ISetupCheck {
33+
public function __construct(
34+
private IL10N $l10n,
35+
) {
36+
}
37+
38+
public function getCategory(): string {
39+
return 'php';
3140
}
3241

33-
public function severity(): string {
34-
return 'error';
42+
public function getName(): string {
43+
return $this->l10n->t('Checking for PHP output_buffering option');
3544
}
3645

37-
public function run(): bool {
46+
public function run(): SetupResult {
3847
$value = trim(ini_get('output_buffering'));
39-
return $value === '' || $value === '0';
48+
if ($value === '' || $value === '0') {
49+
return new SetupResult(SetupResult::SUCCESS);
50+
} else {
51+
return new SetupResult(SetupResult::ERROR, $this->l10n->t('PHP configuration option output_buffering must be disabled'));
52+
}
4053
}
4154
}

apps/settings/lib/SetupChecks/SupportedDatabase.php

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,25 @@
3737
use Doctrine\DBAL\Platforms\SqlitePlatform;
3838
use OCP\IDBConnection;
3939
use OCP\IL10N;
40+
use OCP\SetupCheck\ISetupCheck;
41+
use OCP\SetupCheck\SetupResult;
4042

41-
class SupportedDatabase {
42-
/** @var IL10N */
43-
private $l10n;
44-
/** @var IDBConnection */
45-
private $connection;
46-
47-
private $checked = false;
48-
private $description = '';
43+
class SupportedDatabase implements ISetupCheck {
44+
public function __construct(
45+
private IL10N $l10n,
46+
private IDBConnection $connection,
47+
) {
48+
}
4949

50-
public function __construct(IL10N $l10n, IDBConnection $connection) {
51-
$this->l10n = $l10n;
52-
$this->connection = $connection;
50+
public function getCategory(): string {
51+
return 'database';
5352
}
5453

55-
public function check() {
56-
if ($this->checked === true) {
57-
return;
58-
}
59-
$this->checked = true;
54+
public function getName(): string {
55+
return $this->l10n->t('Checking for database version');
56+
}
6057

58+
public function run(): SetupResult {
6159
switch (get_class($this->connection->getDatabasePlatform())) {
6260
case MySQL80Platform::class: # extends MySQL57Platform
6361
case MySQL57Platform::class: # extends MySQLPlatform
@@ -70,13 +68,11 @@ public function check() {
7068

7169
if (str_contains($version, 'mariadb')) {
7270
if (version_compare($version, '10.2', '<')) {
73-
$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']);
74-
return;
71+
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']));
7572
}
7673
} else {
7774
if (version_compare($version, '8', '<')) {
78-
$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']);
79-
return;
75+
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']));
8076
}
8177
}
8278
break;
@@ -88,26 +84,13 @@ public function check() {
8884
$result->execute();
8985
$row = $result->fetch();
9086
if (version_compare($row['server_version'], '9.6', '<')) {
91-
$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']);
92-
return;
87+
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']));
9388
}
9489
break;
9590
case OraclePlatform::class:
9691
break;
9792
}
98-
}
99-
100-
public function description(): string {
101-
$this->check();
102-
return $this->description;
103-
}
104-
105-
public function severity(): string {
106-
return 'info';
107-
}
108-
109-
public function run(): bool {
110-
$this->check();
111-
return $this->description === '';
93+
// TODO still show db and version on success?
94+
return new SetupResult(SetupResult::SUCCESS);
11295
}
11396
}

0 commit comments

Comments
 (0)