Skip to content

Commit 2916812

Browse files
committed
Migrate MySQL utf8mb4 check to new SetupCheck API
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent 5a7b145 commit 2916812

File tree

8 files changed

+67
-109
lines changed

8 files changed

+67
-109
lines changed

apps/settings/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
'OCA\\Settings\\SetupChecks\\LegacySSEKeyFormat' => $baseDir . '/../lib/SetupChecks/LegacySSEKeyFormat.php',
9696
'OCA\\Settings\\SetupChecks\\MaintenanceWindowStart' => $baseDir . '/../lib/SetupChecks/MaintenanceWindowStart.php',
9797
'OCA\\Settings\\SetupChecks\\MemcacheConfigured' => $baseDir . '/../lib/SetupChecks/MemcacheConfigured.php',
98+
'OCA\\Settings\\SetupChecks\\MysqlUnicodeSupport' => $baseDir . '/../lib/SetupChecks/MysqlUnicodeSupport.php',
9899
'OCA\\Settings\\SetupChecks\\OverwriteCliUrl' => $baseDir . '/../lib/SetupChecks/OverwriteCliUrl.php',
99100
'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' => $baseDir . '/../lib/SetupChecks/PhpDefaultCharset.php',
100101
'OCA\\Settings\\SetupChecks\\PhpDisabledFunctions' => $baseDir . '/../lib/SetupChecks/PhpDisabledFunctions.php',

apps/settings/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class ComposerStaticInitSettings
110110
'OCA\\Settings\\SetupChecks\\LegacySSEKeyFormat' => __DIR__ . '/..' . '/../lib/SetupChecks/LegacySSEKeyFormat.php',
111111
'OCA\\Settings\\SetupChecks\\MaintenanceWindowStart' => __DIR__ . '/..' . '/../lib/SetupChecks/MaintenanceWindowStart.php',
112112
'OCA\\Settings\\SetupChecks\\MemcacheConfigured' => __DIR__ . '/..' . '/../lib/SetupChecks/MemcacheConfigured.php',
113+
'OCA\\Settings\\SetupChecks\\MysqlUnicodeSupport' => __DIR__ . '/..' . '/../lib/SetupChecks/MysqlUnicodeSupport.php',
113114
'OCA\\Settings\\SetupChecks\\OverwriteCliUrl' => __DIR__ . '/..' . '/../lib/SetupChecks/OverwriteCliUrl.php',
114115
'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpDefaultCharset.php',
115116
'OCA\\Settings\\SetupChecks\\PhpDisabledFunctions' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpDisabledFunctions.php',

apps/settings/lib/AppInfo/Application.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
use OCA\Settings\SetupChecks\LegacySSEKeyFormat;
6868
use OCA\Settings\SetupChecks\MaintenanceWindowStart;
6969
use OCA\Settings\SetupChecks\MemcacheConfigured;
70+
use OCA\Settings\SetupChecks\MysqlUnicodeSupport;
7071
use OCA\Settings\SetupChecks\OverwriteCliUrl;
7172
use OCA\Settings\SetupChecks\PhpDefaultCharset;
7273
use OCA\Settings\SetupChecks\PhpDisabledFunctions;
@@ -190,6 +191,7 @@ public function register(IRegistrationContext $context): void {
190191
$context->registerSetupCheck(LegacySSEKeyFormat::class);
191192
$context->registerSetupCheck(MaintenanceWindowStart::class);
192193
$context->registerSetupCheck(MemcacheConfigured::class);
194+
$context->registerSetupCheck(MysqlUnicodeSupport::class);
193195
$context->registerSetupCheck(OverwriteCliUrl::class);
194196
$context->registerSetupCheck(PhpDefaultCharset::class);
195197
$context->registerSetupCheck(PhpDisabledFunctions::class);

apps/settings/lib/Controller/CheckSetupController.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,6 @@ private function isTemporaryDirectoryWritable(): bool {
202202
return false;
203203
}
204204

205-
protected function isMysqlUsedWithoutUTF8MB4(): bool {
206-
return ($this->config->getSystemValue('dbtype', 'sqlite') === 'mysql') && ($this->config->getSystemValue('mysql.utf8mb4', false) === false);
207-
}
208-
209205
protected function isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed(): bool {
210206
$objectStore = $this->config->getSystemValue('objectstore', null);
211207
$objectStoreMultibucket = $this->config->getSystemValue('objectstore_multibucket', null);
@@ -251,7 +247,6 @@ public function check() {
251247
[
252248
'isFairUseOfFreePushService' => $this->isFairUseOfFreePushService(),
253249
'reverseProxyDocs' => $this->urlGenerator->linkToDocs('admin-reverse-proxy'),
254-
'isMysqlUsedWithoutUTF8MB4' => $this->isMysqlUsedWithoutUTF8MB4(),
255250
'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed' => $this->isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed(),
256251
'reverseProxyGeneratedURL' => $this->urlGenerator->getAbsoluteURL('index.php'),
257252
'temporaryDirectoryWritable' => $this->isTemporaryDirectoryWritable(),
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) 2023 Côme Chilliet <come.chilliet@nextcloud.com>
7+
*
8+
* @author Côme Chilliet <come.chilliet@nextcloud.com>
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+
namespace OCA\Settings\SetupChecks;
27+
28+
use OCP\IConfig;
29+
use OCP\IL10N;
30+
use OCP\IURLGenerator;
31+
use OCP\SetupCheck\ISetupCheck;
32+
use OCP\SetupCheck\SetupResult;
33+
34+
class MysqlUnicodeSupport implements ISetupCheck {
35+
public function __construct(
36+
private IL10N $l10n,
37+
private IConfig $config,
38+
private IURLGenerator $urlGenerator,
39+
) {
40+
}
41+
42+
public function getName(): string {
43+
return $this->l10n->t('MySQL unicode support');
44+
}
45+
46+
public function getCategory(): string {
47+
return 'database';
48+
}
49+
50+
public function run(): SetupResult {
51+
if ($this->config->getSystemValueString('dbtype') !== 'mysql') {
52+
return SetupResult::success($this->l10n->t('You are not using MySQL'));
53+
}
54+
if ($this->config->getSystemValueBool('mysql.utf8mb4', false)) {
55+
return SetupResult::success($this->l10n->t('MySQL is used as database and does support 4-byte characters'));
56+
} else {
57+
return SetupResult::warning(
58+
$this->l10n->t('MySQL is used as database but does not support 4-byte characters. To be able to handle 4-byte characters (like emojis) without issues in filenames or comments for example it is recommended to enable the 4-byte support in MySQL.'),
59+
$this->urlGenerator->linkToDocs('admin-mysql-utf8mb4'),
60+
);
61+
}
62+
}
63+
}

apps/settings/tests/Controller/CheckSetupControllerTest.php

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ protected function setUp(): void {
118118
'getCurlVersion',
119119
'isPhpOutdated',
120120
'isPHPMailerUsed',
121-
'isMysqlUsedWithoutUTF8MB4',
122121
'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed',
123122
])->getMock();
124123
}
@@ -142,11 +141,6 @@ public function testCheck() {
142141
$this->request->expects($this->never())
143142
->method('getHeader');
144143

145-
$this->checkSetupController
146-
->expects($this->once())
147-
->method('isMysqlUsedWithoutUTF8MB4')
148-
->willReturn(false);
149-
150144
$this->checkSetupController
151145
->expects($this->once())
152146
->method('isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed')
@@ -186,7 +180,6 @@ public function testCheck() {
186180
$expected = new DataResponse(
187181
[
188182
'reverseProxyDocs' => 'reverse-proxy-doc-link',
189-
'isMysqlUsedWithoutUTF8MB4' => false,
190183
'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed' => true,
191184
'reverseProxyGeneratedURL' => 'https://server/index.php',
192185
'isFairUseOfFreePushService' => false,
@@ -653,50 +646,6 @@ public function testGetFailedIntegrityCheckFilesWithSomeErrorsFound() {
653646
$this->assertEquals($expected, $this->checkSetupController->getFailedIntegrityCheckFiles());
654647
}
655648

656-
public function dataForIsMysqlUsedWithoutUTF8MB4() {
657-
return [
658-
['sqlite', false, false],
659-
['sqlite', true, false],
660-
['postgres', false, false],
661-
['postgres', true, false],
662-
['oci', false, false],
663-
['oci', true, false],
664-
['mysql', false, true],
665-
['mysql', true, false],
666-
];
667-
}
668-
669-
/**
670-
* @dataProvider dataForIsMysqlUsedWithoutUTF8MB4
671-
*/
672-
public function testIsMysqlUsedWithoutUTF8MB4(string $db, bool $useUTF8MB4, bool $expected) {
673-
$this->config->method('getSystemValue')
674-
->willReturnCallback(function ($key, $default) use ($db, $useUTF8MB4) {
675-
if ($key === 'dbtype') {
676-
return $db;
677-
}
678-
if ($key === 'mysql.utf8mb4') {
679-
return $useUTF8MB4;
680-
}
681-
return $default;
682-
});
683-
684-
$checkSetupController = new CheckSetupController(
685-
'settings',
686-
$this->request,
687-
$this->config,
688-
$this->urlGenerator,
689-
$this->l10n,
690-
$this->checker,
691-
$this->logger,
692-
$this->tempManager,
693-
$this->notificationManager,
694-
$this->setupCheckManager,
695-
);
696-
697-
$this->assertSame($expected, $this->invokePrivate($checkSetupController, 'isMysqlUsedWithoutUTF8MB4'));
698-
}
699-
700649
public function dataForIsEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed() {
701650
return [
702651
['singlebucket', 'OC\\Files\\ObjectStore\\Swift', true],

core/js/setupchecks.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,6 @@
189189
});
190190
}
191191

192-
if (data.isMysqlUsedWithoutUTF8MB4) {
193-
messages.push({
194-
msg: t('core', 'MySQL is used as database but does not support 4-byte characters. To be able to handle 4-byte characters (like emojis) without issues in filenames or comments for example it is recommended to enable the 4-byte support in MySQL. For further details read {linkstart}the documentation page about this ↗{linkend}.')
195-
.replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + OC.theme.docPlaceholderUrl.replace('PLACEHOLDER', 'admin-mysql-utf8mb4') + '">')
196-
.replace('{linkend}', '</a>'),
197-
type: OC.SetupChecks.MESSAGE_TYPE_WARNING
198-
})
199-
}
200192
if (!data.isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed) {
201193
messages.push({
202194
msg: t('core', 'This instance uses an S3 based object store as primary storage. The uploaded files are stored temporarily on the server and thus it is recommended to have 50 GB of free space available in the temp directory of PHP. Check the logs for full details about the path and the available space. To improve this please change the temporary directory in the php.ini or make more space available in that path.'),

core/js/tests/specs/setupchecksSpec.js

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ describe('OC.SetupChecks tests', function() {
224224
},
225225
JSON.stringify({
226226
isFairUseOfFreePushService: true,
227-
isMysqlUsedWithoutUTF8MB4: false,
228227
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
229228
reverseProxyGeneratedURL: 'https://server',
230229
temporaryDirectoryWritable: true,
@@ -261,7 +260,6 @@ describe('OC.SetupChecks tests', function() {
261260
},
262261
JSON.stringify({
263262
isFairUseOfFreePushService: true,
264-
isMysqlUsedWithoutUTF8MB4: false,
265263
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
266264
reverseProxyGeneratedURL: 'https://server',
267265
temporaryDirectoryWritable: true,
@@ -298,7 +296,6 @@ describe('OC.SetupChecks tests', function() {
298296
},
299297
JSON.stringify({
300298
isFairUseOfFreePushService: true,
301-
isMysqlUsedWithoutUTF8MB4: false,
302299
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
303300
reverseProxyGeneratedURL: 'https://server',
304301
temporaryDirectoryWritable: true,
@@ -336,7 +333,6 @@ describe('OC.SetupChecks tests', function() {
336333
JSON.stringify({
337334
isFairUseOfFreePushService: true,
338335
reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
339-
isMysqlUsedWithoutUTF8MB4: false,
340336
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
341337
reverseProxyGeneratedURL: 'https://server',
342338
temporaryDirectoryWritable: true,
@@ -403,7 +399,6 @@ describe('OC.SetupChecks tests', function() {
403399
},
404400
JSON.stringify({
405401
isFairUseOfFreePushService: true,
406-
isMysqlUsedWithoutUTF8MB4: false,
407402
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
408403
reverseProxyGeneratedURL: 'https://server',
409404
temporaryDirectoryWritable: true,
@@ -435,41 +430,6 @@ describe('OC.SetupChecks tests', function() {
435430
});
436431
});
437432

438-
it('should return an error if the php version is no longer supported', function(done) {
439-
var async = OC.SetupChecks.checkSetup();
440-
441-
suite.server.requests[0].respond(
442-
200,
443-
{
444-
'Content-Type': 'application/json',
445-
},
446-
JSON.stringify({
447-
isFairUseOfFreePushService: true,
448-
isMysqlUsedWithoutUTF8MB4: true,
449-
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
450-
reverseProxyGeneratedURL: 'https://server',
451-
temporaryDirectoryWritable: true,
452-
generic: {
453-
network: {
454-
"Internet connectivity": {
455-
severity: "success",
456-
description: null,
457-
linkToDoc: null
458-
}
459-
},
460-
},
461-
})
462-
);
463-
464-
async.done(function( data, s, x ){
465-
expect(data).toEqual([{
466-
msg: 'MySQL is used as database but does not support 4-byte characters. To be able to handle 4-byte characters (like emojis) without issues in filenames or comments for example it is recommended to enable the 4-byte support in MySQL. For further details read <a target="_blank" rel="noreferrer noopener" class="external" href="https://docs.example.org/admin-mysql-utf8mb4">the documentation page about this ↗</a>.',
467-
type: OC.SetupChecks.MESSAGE_TYPE_WARNING
468-
}]);
469-
done();
470-
});
471-
});
472-
473433
// THe following test is invalid as the code in core/js/setupchecks.js is calling
474434
// window.location.protocol which always return http during tests
475435
// if there is a way to trick window.location.protocol during test, then we could re-activate it
@@ -484,7 +444,6 @@ describe('OC.SetupChecks tests', function() {
484444
},
485445
JSON.stringify({
486446
isFairUseOfFreePushService: true,
487-
isMysqlUsedWithoutUTF8MB4: false,
488447
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
489448
reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
490449
reverseProxyGeneratedURL: 'http://server',
@@ -520,7 +479,6 @@ describe('OC.SetupChecks tests', function() {
520479
},
521480
JSON.stringify({
522481
isFairUseOfFreePushService: true,
523-
isMysqlUsedWithoutUTF8MB4: false,
524482
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
525483
reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
526484
reverseProxyGeneratedURL: 'http://server',
@@ -553,7 +511,6 @@ describe('OC.SetupChecks tests', function() {
553511
},
554512
JSON.stringify({
555513
isFairUseOfFreePushService: true,
556-
isMysqlUsedWithoutUTF8MB4: false,
557514
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: false,
558515
reverseProxyGeneratedURL: 'https://server',
559516
temporaryDirectoryWritable: true,
@@ -588,7 +545,6 @@ describe('OC.SetupChecks tests', function() {
588545
},
589546
JSON.stringify({
590547
isFairUseOfFreePushService: true,
591-
isMysqlUsedWithoutUTF8MB4: false,
592548
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
593549
reverseProxyGeneratedURL: 'https://server',
594550
temporaryDirectoryWritable: true,
@@ -630,7 +586,6 @@ describe('OC.SetupChecks tests', function() {
630586
},
631587
JSON.stringify({
632588
isFairUseOfFreePushService: true,
633-
isMysqlUsedWithoutUTF8MB4: false,
634589
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
635590
reverseProxyGeneratedURL: 'https://server',
636591
temporaryDirectoryWritable: false,

0 commit comments

Comments
 (0)