Skip to content

Commit e834d5e

Browse files
committed
Migrate sqlite setup check
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
1 parent 9589acb commit e834d5e

7 files changed

Lines changed: 143 additions & 30 deletions

File tree

apps/settings/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,5 @@
5959
'OCA\\Settings\\SetupChecks\\LegacySSEKeyFormat' => $baseDir . '/../lib/SetupChecks/LegacySSEKeyFormat.php',
6060
'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' => $baseDir . '/../lib/SetupChecks/PhpDefaultCharset.php',
6161
'OCA\\Settings\\SetupChecks\\PhpOutputBuffering' => $baseDir . '/../lib/SetupChecks/PhpOutputBuffering.php',
62+
'OCA\\Settings\\SetupChecks\\SqliteDatabase' => $baseDir . '/../lib/SetupChecks/SqliteDatabase.php',
6263
);

apps/settings/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class ComposerStaticInitSettings
7474
'OCA\\Settings\\SetupChecks\\LegacySSEKeyFormat' => __DIR__ . '/..' . '/../lib/SetupChecks/LegacySSEKeyFormat.php',
7575
'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpDefaultCharset.php',
7676
'OCA\\Settings\\SetupChecks\\PhpOutputBuffering' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpOutputBuffering.php',
77+
'OCA\\Settings\\SetupChecks\\SqliteDatabase' => __DIR__ . '/..' . '/../lib/SetupChecks/SqliteDatabase.php',
7778
);
7879

7980
public static function getInitializer(ClassLoader $loader)

apps/settings/lib/Controller/CheckSetupController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
use OCA\Settings\SetupChecks\LegacySSEKeyFormat;
5757
use OCA\Settings\SetupChecks\PhpDefaultCharset;
5858
use OCA\Settings\SetupChecks\PhpOutputBuffering;
59+
use OCA\Settings\SetupChecks\SqliteDatabase;
5960
use OCP\AppFramework\Controller;
6061
use OCP\AppFramework\Http\DataDisplayResponse;
6162
use OCP\AppFramework\Http\DataResponse;
@@ -693,7 +694,8 @@ public function check() {
693694
$newChecks = $this->runSetupChecks([
694695
PhpDefaultCharset::class,
695696
PhpOutputBuffering::class,
696-
LegacySSEKeyFormat::class
697+
LegacySSEKeyFormat::class,
698+
SqliteDatabase::class,
697699
]);
698700

699701
return new DataResponse(
@@ -725,8 +727,6 @@ public function check() {
725727
'hasFreeTypeSupport' => $this->hasFreeTypeSupport(),
726728
'missingIndexes' => $this->hasMissingIndexes(),
727729
'missingColumns' => $this->hasMissingColumns(),
728-
'isSqliteUsed' => $this->isSqliteUsed(),
729-
'databaseConversionDocumentation' => $this->urlGenerator->linkToDocs('admin-db-conversion'),
730730
'isPHPMailerUsed' => $this->isPHPMailerUsed(),
731731
'mailSettingsDocumentation' => $this->urlGenerator->getAbsoluteURL('index.php/settings/admin'),
732732
'isMemoryLimitSufficient' => $this->memoryInfo->isMemoryLimitSufficient(),
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2020 Daniel Kesselberg <mail@danielkesselberg.de>
7+
*
8+
* @author Daniel Kesselberg <mail@danielkesselberg.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 OCP\IConfig;
30+
use OCP\IL10N;
31+
use OCP\IURLGenerator;
32+
use OCP\Settings\SetupChecks\ISetupCheck;
33+
34+
class SqliteDatabase implements ISetupCheck {
35+
/** @var IL10N */
36+
private $l10n;
37+
/** @var IConfig */
38+
private $config;
39+
/** @var IURLGenerator */
40+
private $urlGenerator;
41+
42+
public function __construct(IL10N $l10n, IConfig $config, IURLGenerator $urlGenerator) {
43+
$this->l10n = $l10n;
44+
$this->config = $config;
45+
$this->urlGenerator = $urlGenerator;
46+
}
47+
48+
public function description(): string {
49+
return $this->l10n->t('SQLite is used as database. For larger installations we recommend to switch to a different database.');
50+
}
51+
52+
public function severity(): string {
53+
return ISetupCheck::SEVERITY_WARNING;
54+
}
55+
56+
public function passes(): bool {
57+
return strpos($this->config->getSystemValueString('dbtype'), 'sqlite') === false;
58+
}
59+
60+
public function linkToDocumentation(): string {
61+
return $this->urlGenerator->linkToDocs('admin-db-conversion');
62+
}
63+
}

apps/settings/tests/Controller/CheckSetupControllerTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ protected function setUp(): void {
165165
'isOpcacheProperlySetup',
166166
'hasFreeTypeSupport',
167167
'hasMissingIndexes',
168-
'isSqliteUsed',
169168
'isPHPMailerUsed',
170169
'hasOpcacheLoaded',
171170
'getAppDirsWithDifferentOwner',
@@ -381,23 +380,27 @@ public function testForwardedHostPresentButTrustedProxiesEmpty() {
381380
}
382381

383382
public function testCheck() {
384-
$this->config->expects($this->at(0))
383+
$this->config
384+
->method('getSystemValueString')
385+
->with('dbtype')
386+
->willReturn('sqlite');
387+
$this->config->expects($this->at(2))
385388
->method('getAppValue')
386389
->with('core', 'cronErrors')
387390
->willReturn('');
388-
$this->config->expects($this->at(2))
391+
$this->config->expects($this->at(4))
389392
->method('getSystemValue')
390393
->with('connectivity_check_domains', ['www.nextcloud.com', 'www.startpage.com', 'www.eff.org', 'www.edri.org'])
391394
->willReturn(['www.nextcloud.com', 'www.startpage.com', 'www.eff.org', 'www.edri.org']);
392-
$this->config->expects($this->at(3))
395+
$this->config->expects($this->at(5))
393396
->method('getSystemValue')
394397
->with('memcache.local', null)
395398
->willReturn('SomeProvider');
396-
$this->config->expects($this->at(4))
399+
$this->config->expects($this->at(6))
397400
->method('getSystemValue')
398401
->with('has_internet_connection', true)
399402
->willReturn(true);
400-
$this->config->expects($this->at(5))
403+
$this->config->expects($this->at(7))
401404
->method('getSystemValue')
402405
->with('appstoreenabled', true)
403406
->willReturn(false);
@@ -444,9 +447,6 @@ public function testCheck() {
444447
$this->checkSetupController
445448
->method('hasMissingIndexes')
446449
->willReturn([]);
447-
$this->checkSetupController
448-
->method('isSqliteUsed')
449-
->willReturn(false);
450450
$this->checkSetupController
451451
->expects($this->once())
452452
->method('isReadOnlyConfig')
@@ -554,6 +554,7 @@ public function testCheck() {
554554
});
555555

556556
$this->overwriteService(IURLGenerator::class, $this->urlGenerator);
557+
$this->overwriteService(IConfig::class, $this->config);
557558
// OC::$server->registerService(IURLGenerator::class, function () {
558559
// return $this->urlGenerator;
559560
// });
@@ -592,8 +593,6 @@ public function testCheck() {
592593
'phpOpcacheDocumentation' => 'http://docs.example.org/server/go.php?to=admin-php-opcache',
593594
'isSettimelimitAvailable' => true,
594595
'hasFreeTypeSupport' => false,
595-
'isSqliteUsed' => false,
596-
'databaseConversionDocumentation' => 'http://docs.example.org/server/go.php?to=admin-db-conversion',
597596
'missingIndexes' => [],
598597
'missingColumns' => [],
599598
'isPHPMailerUsed' => false,
@@ -608,6 +607,7 @@ public function testCheck() {
608607
'OCA\Settings\SetupChecks\PhpDefaultCharset' => ['pass' => true, 'description' => 'PHP configuration option default_charset should be UTF-8', 'severity' => 'warning', 'linkToDocumentation' => null],
609608
'OCA\Settings\SetupChecks\PhpOutputBuffering' => ['pass' => true, 'description' => 'PHP configuration option output_buffering must be disabled', 'severity' => 'error', 'linkToDocumentation' => null],
610609
'OCA\Settings\SetupChecks\LegacySSEKeyFormat' => ['pass' => true, 'description' => 'The old server-side-encryption format is enabled. We recommend disabling this.', 'severity' => 'warning', 'linkToDocumentation' => 'http://docs.example.org/server/go.php?to=admin-sse-legacy-format'],
610+
'OCA\Settings\SetupChecks\SqliteDatabase' => ['pass' => false, 'description' => 'SQLite is used as database. For larger installations we recommend to switch to a different database.', 'severity' => 'warning', 'linkToDocumentation' => 'http://docs.example.org/server/go.php?to=admin-db-conversion'],
611611
]
612612
);
613613
$this->assertEquals($expected, $this->checkSetupController->check());
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2020 Daniel Kesselberg <mail@danielkesselberg.de>
7+
*
8+
* @author Daniel Kesselberg <mail@danielkesselberg.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 OC\L10N\L10N;
30+
use OC\URLGenerator;
31+
use OCA\Settings\SetupChecks\SqliteDatabase;
32+
use OCP\IConfig;
33+
use PHPUnit\Framework\MockObject\MockObject;
34+
use Test\TestCase;
35+
36+
class SqliteDatabaseTest extends TestCase {
37+
/** @var IConfig|MockObject */
38+
private $config;
39+
/** @var SqliteDatabase */
40+
private $check;
41+
42+
public function setUp(): void {
43+
parent::setUp();
44+
$this->config = $this->createMock(IConfig::class);
45+
$this->check = new SqliteDatabase(
46+
$this->createMock(L10N::class),
47+
$this->config,
48+
$this->createMock(URLGenerator::class)
49+
);
50+
}
51+
52+
public function testPass(): void {
53+
$this->config->method('getSystemValue')
54+
->willReturn('mysql');
55+
$this->assertTrue($this->check->passes());
56+
}
57+
58+
public function testFail(): void {
59+
$this->config->method('getSystemValue')
60+
->willReturn('sqlite');
61+
$this->assertFalse($this->check->passes());
62+
}
63+
}

core/js/setupchecks.js

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -401,22 +401,6 @@
401401
type: OC.SetupChecks.MESSAGE_TYPE_INFO
402402
})
403403
}
404-
if (data.isSqliteUsed) {
405-
messages.push({
406-
msg: t(
407-
'core',
408-
'SQLite is currently being used as the backend database. For larger installations we recommend that you switch to a different database backend.'
409-
) + ' ' + t('core', 'This is particularly recommended when using the desktop client for file synchronisation.') + ' ' +
410-
t(
411-
'core',
412-
'To migrate to another database use the command line tool: \'occ db:convert-type\', or see the <a target="_blank" rel="noreferrer noopener" href="{docLink}">documentation ↗</a>.',
413-
{
414-
docLink: data.databaseConversionDocumentation,
415-
}
416-
),
417-
type: OC.SetupChecks.MESSAGE_TYPE_WARNING
418-
})
419-
}
420404
if (data.isPHPMailerUsed) {
421405
messages.push({
422406
msg: t(
@@ -491,6 +475,7 @@
491475
OC.SetupChecks.addGenericSetupCheck(data, 'OCA\\Settings\\SetupChecks\\PhpDefaultCharset', messages)
492476
OC.SetupChecks.addGenericSetupCheck(data, 'OCA\\Settings\\SetupChecks\\PhpOutputBuffering', messages)
493477
OC.SetupChecks.addGenericSetupCheck(data, 'OCA\\Settings\\SetupChecks\\LegacySSEKeyFormat', messages)
478+
OC.SetupChecks.addGenericSetupCheck(data, 'OCA\\Settings\\SetupChecks\\SqliteWarning', messages)
494479

495480
} else {
496481
messages.push({

0 commit comments

Comments
 (0)