Skip to content

Commit efde9a7

Browse files
committed
Add setup check to verify that the used DB version is still supported in the next major release
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
1 parent 2dd04f7 commit efde9a7

6 files changed

Lines changed: 157 additions & 1 deletion

File tree

apps/settings/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,5 @@
6161
'OCA\\Settings\\SetupChecks\\LegacySSEKeyFormat' => $baseDir . '/../lib/SetupChecks/LegacySSEKeyFormat.php',
6262
'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' => $baseDir . '/../lib/SetupChecks/PhpDefaultCharset.php',
6363
'OCA\\Settings\\SetupChecks\\PhpOutputBuffering' => $baseDir . '/../lib/SetupChecks/PhpOutputBuffering.php',
64+
'OCA\\Settings\\SetupChecks\\SupportedDatabase' => $baseDir . '/../lib/SetupChecks/SupportedDatabase.php',
6465
);

apps/settings/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class ComposerStaticInitSettings
7676
'OCA\\Settings\\SetupChecks\\LegacySSEKeyFormat' => __DIR__ . '/..' . '/../lib/SetupChecks/LegacySSEKeyFormat.php',
7777
'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpDefaultCharset.php',
7878
'OCA\\Settings\\SetupChecks\\PhpOutputBuffering' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpOutputBuffering.php',
79+
'OCA\\Settings\\SetupChecks\\SupportedDatabase' => __DIR__ . '/..' . '/../lib/SetupChecks/SupportedDatabase.php',
7980
);
8081

8182
public static function getInitializer(ClassLoader $loader)

apps/settings/lib/Controller/CheckSetupController.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
use OCA\Settings\SetupChecks\LegacySSEKeyFormat;
6363
use OCA\Settings\SetupChecks\PhpDefaultCharset;
6464
use OCA\Settings\SetupChecks\PhpOutputBuffering;
65+
use OCA\Settings\SetupChecks\SupportedDatabase;
6566
use OCP\AppFramework\Controller;
6667
use OCP\AppFramework\Http\DataDisplayResponse;
6768
use OCP\AppFramework\Http\DataResponse;
@@ -106,6 +107,8 @@ class CheckSetupController extends Controller {
106107
private $secureRandom;
107108
/** @var IniGetWrapper */
108109
private $iniGetWrapper;
110+
/** @var IDBConnection */
111+
private $connection;
109112

110113
public function __construct($AppName,
111114
IRequest $request,
@@ -121,7 +124,8 @@ public function __construct($AppName,
121124
IDateTimeFormatter $dateTimeFormatter,
122125
MemoryInfo $memoryInfo,
123126
ISecureRandom $secureRandom,
124-
IniGetWrapper $iniGetWrapper) {
127+
IniGetWrapper $iniGetWrapper,
128+
IDBConnection $connection) {
125129
parent::__construct($AppName, $request);
126130
$this->config = $config;
127131
$this->clientService = $clientService;
@@ -136,6 +140,7 @@ public function __construct($AppName,
136140
$this->memoryInfo = $memoryInfo;
137141
$this->secureRandom = $secureRandom;
138142
$this->iniGetWrapper = $iniGetWrapper;
143+
$this->connection = $connection;
139144
}
140145

141146
/**
@@ -713,6 +718,7 @@ public function check() {
713718
$phpOutputBuffering = new PhpOutputBuffering();
714719
$legacySSEKeyFormat = new LegacySSEKeyFormat($this->l10n, $this->config, $this->urlGenerator);
715720
$checkUserCertificates = new CheckUserCertificates($this->l10n, $this->config, $this->urlGenerator);
721+
$supportedDatabases = new SupportedDatabase($this->l10n, $this->connection);
716722

717723
return new DataResponse(
718724
[
@@ -759,6 +765,7 @@ public function check() {
759765
LegacySSEKeyFormat::class => ['pass' => $legacySSEKeyFormat->run(), 'description' => $legacySSEKeyFormat->description(), 'severity' => $legacySSEKeyFormat->severity(), 'linkToDocumentation' => $legacySSEKeyFormat->linkToDocumentation()],
760766
CheckUserCertificates::class => ['pass' => $checkUserCertificates->run(), 'description' => $checkUserCertificates->description(), 'severity' => $checkUserCertificates->severity(), 'elements' => $checkUserCertificates->elements()],
761767
'isDefaultPhoneRegionSet' => $this->config->getSystemValueString('default_phone_region', '') !== '',
768+
SupportedDatabase::class => ['pass' => $supportedDatabases->run(), 'description' => $supportedDatabases->description(), 'severity' => $supportedDatabases->severity()],
762769
]
763770
);
764771
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2021 Morris Jobke <hey@morrisjobke.de>
7+
*
8+
* @author Morris Jobke <hey@morrisjobke.de>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
27+
namespace OCA\Settings\SetupChecks;
28+
29+
use Doctrine\DBAL\Platforms\MariaDb1027Platform;
30+
use Doctrine\DBAL\Platforms\MySQL57Platform;
31+
use Doctrine\DBAL\Platforms\MySQL80Platform;
32+
use Doctrine\DBAL\Platforms\MySQLPlatform;
33+
use Doctrine\DBAL\Platforms\OraclePlatform;
34+
use Doctrine\DBAL\Platforms\PostgreSQL100Platform;
35+
use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
36+
use Doctrine\DBAL\Platforms\SqlitePlatform;
37+
use OCP\IDBConnection;
38+
use OCP\IL10N;
39+
40+
class SupportedDatabase {
41+
/** @var IL10N */
42+
private $l10n;
43+
/** @var IDBConnection */
44+
private $connection;
45+
46+
private $description = '';
47+
48+
public function __construct(IL10N $l10n, IDBConnection $connection) {
49+
$this->l10n = $l10n;
50+
$this->connection = $connection;
51+
52+
$this->check();
53+
}
54+
55+
public function check() {
56+
switch (get_class($this->connection->getDatabasePlatform())) {
57+
case MySQL80Platform::class: # extends MySQL57Platform
58+
case MySQL57Platform::class: # extends MySQLPlatform
59+
case MariaDb1027Platform::class: # extends MySQLPlatform
60+
case MySQLPlatform::class:
61+
$result = $this->connection->prepare('SHOW VARIABLES LIKE "version";');
62+
$row = $result->execute()->fetchOne();
63+
$version = strtolower($row['Value']);
64+
65+
if (strpos($version, 'mariadb') !== false) {
66+
if (version_compare($version, '10.4', '<')) {
67+
$this->description = $this->l10n->t('MariaDB version "%s" is used. Nextcloud 21 will no longer support this version and requires MariaDB 10.4 or higher.', $row['Value']);
68+
return;
69+
}
70+
} else {
71+
if (version_compare($version, '8', '<')) {
72+
$this->description = $this->l10n->t('MySQL version "%s" is used. Nextcloud 21 will no longer support this version and requires MariaDB 8 or higher.', $row['Value']);
73+
return;
74+
}
75+
}
76+
break;
77+
case SqlitePlatform::class:
78+
break;
79+
case PostgreSQL100Platform::class: # extends PostgreSQL94Platform
80+
case PostgreSQL94Platform::class:
81+
$result = $this->connection->prepare('SHOW server_version;');
82+
$row = $result->execute()->fetchOne();
83+
if (version_compare($row['server_version'], '9.6', '<')) {
84+
$this->description = $this->l10n->t('PostgreSQL version "%s" is used. Nextcloud 21 will no longer support this version and requires PostgreSQL 9.6 or higher.', $row['server_version']);
85+
return;
86+
}
87+
break;
88+
case OraclePlatform::class:
89+
break;
90+
}
91+
}
92+
93+
public function description(): string {
94+
return $this->description;
95+
}
96+
97+
public function severity(): string {
98+
return 'info';
99+
}
100+
101+
public function run(): bool {
102+
return $this->description === '';
103+
}
104+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2021 Morris Jobke <hey@morrisjobke.de>
7+
*
8+
* @author Morris Jobke <hey@morrisjobke.de>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
27+
namespace OCA\Settings\Tests;
28+
29+
use OCA\Settings\SetupChecks\SupportedDatabase;
30+
use OCP\IL10N;
31+
use Test\TestCase;
32+
33+
/**
34+
* @group DB
35+
*/
36+
class SupportedDatabaseTest extends TestCase {
37+
public function testPass(): void {
38+
$l10n = $this->getMockBuilder(IL10N::class)->getMock();
39+
$check = new SupportedDatabase($l10n, \OC::$server->getDatabaseConnection());
40+
$this->assertTrue($check->run());
41+
}
42+
}

core/js/setupchecks.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@
513513
OC.SetupChecks.addGenericSetupCheck(data, 'OCA\\Settings\\SetupChecks\\PhpOutputBuffering', messages)
514514
OC.SetupChecks.addGenericSetupCheck(data, 'OCA\\Settings\\SetupChecks\\LegacySSEKeyFormat', messages)
515515
OC.SetupChecks.addGenericSetupCheck(data, 'OCA\\Settings\\SetupChecks\\CheckUserCertificates', messages)
516+
OC.SetupChecks.addGenericSetupCheck(data, 'OCA\\Settings\\SetupChecks\\SupportedDatabase', messages)
516517

517518
} else {
518519
messages.push({

0 commit comments

Comments
 (0)