aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2024-01-16 11:30:08 +0100
committerCôme Chilliet <91878298+come-nc@users.noreply.github.com>2024-01-23 17:34:04 +0100
commit10664e952917094f7af15900421f0c0d50b860b8 (patch)
tree2027c146cf1f0998b1b740760ec517a28810c93d /apps
parenta09107af7a8a62862ec1e76cf8d518efc18f0d34 (diff)
downloadnextcloud-server-10664e952917094f7af15900421f0c0d50b860b8.tar.gz
nextcloud-server-10664e952917094f7af15900421f0c0d50b860b8.zip
Migrate MySQL utf8mb4 check to new SetupCheck API
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'apps')
-rw-r--r--apps/settings/composer/composer/autoload_classmap.php1
-rw-r--r--apps/settings/composer/composer/autoload_static.php1
-rw-r--r--apps/settings/lib/AppInfo/Application.php2
-rw-r--r--apps/settings/lib/Controller/CheckSetupController.php5
-rw-r--r--apps/settings/lib/SetupChecks/MysqlUnicodeSupport.php63
-rw-r--r--apps/settings/tests/Controller/CheckSetupControllerTest.php51
6 files changed, 67 insertions, 56 deletions
diff --git a/apps/settings/composer/composer/autoload_classmap.php b/apps/settings/composer/composer/autoload_classmap.php
index effa9c3b426..80953034208 100644
--- a/apps/settings/composer/composer/autoload_classmap.php
+++ b/apps/settings/composer/composer/autoload_classmap.php
@@ -95,6 +95,7 @@ return array(
'OCA\\Settings\\SetupChecks\\LegacySSEKeyFormat' => $baseDir . '/../lib/SetupChecks/LegacySSEKeyFormat.php',
'OCA\\Settings\\SetupChecks\\MaintenanceWindowStart' => $baseDir . '/../lib/SetupChecks/MaintenanceWindowStart.php',
'OCA\\Settings\\SetupChecks\\MemcacheConfigured' => $baseDir . '/../lib/SetupChecks/MemcacheConfigured.php',
+ 'OCA\\Settings\\SetupChecks\\MysqlUnicodeSupport' => $baseDir . '/../lib/SetupChecks/MysqlUnicodeSupport.php',
'OCA\\Settings\\SetupChecks\\OverwriteCliUrl' => $baseDir . '/../lib/SetupChecks/OverwriteCliUrl.php',
'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' => $baseDir . '/../lib/SetupChecks/PhpDefaultCharset.php',
'OCA\\Settings\\SetupChecks\\PhpDisabledFunctions' => $baseDir . '/../lib/SetupChecks/PhpDisabledFunctions.php',
diff --git a/apps/settings/composer/composer/autoload_static.php b/apps/settings/composer/composer/autoload_static.php
index 20834644eb5..9e23bbb47ae 100644
--- a/apps/settings/composer/composer/autoload_static.php
+++ b/apps/settings/composer/composer/autoload_static.php
@@ -110,6 +110,7 @@ class ComposerStaticInitSettings
'OCA\\Settings\\SetupChecks\\LegacySSEKeyFormat' => __DIR__ . '/..' . '/../lib/SetupChecks/LegacySSEKeyFormat.php',
'OCA\\Settings\\SetupChecks\\MaintenanceWindowStart' => __DIR__ . '/..' . '/../lib/SetupChecks/MaintenanceWindowStart.php',
'OCA\\Settings\\SetupChecks\\MemcacheConfigured' => __DIR__ . '/..' . '/../lib/SetupChecks/MemcacheConfigured.php',
+ 'OCA\\Settings\\SetupChecks\\MysqlUnicodeSupport' => __DIR__ . '/..' . '/../lib/SetupChecks/MysqlUnicodeSupport.php',
'OCA\\Settings\\SetupChecks\\OverwriteCliUrl' => __DIR__ . '/..' . '/../lib/SetupChecks/OverwriteCliUrl.php',
'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpDefaultCharset.php',
'OCA\\Settings\\SetupChecks\\PhpDisabledFunctions' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpDisabledFunctions.php',
diff --git a/apps/settings/lib/AppInfo/Application.php b/apps/settings/lib/AppInfo/Application.php
index 2c3584e3c03..32cb3af3ef8 100644
--- a/apps/settings/lib/AppInfo/Application.php
+++ b/apps/settings/lib/AppInfo/Application.php
@@ -67,6 +67,7 @@ use OCA\Settings\SetupChecks\JavaScriptModules;
use OCA\Settings\SetupChecks\LegacySSEKeyFormat;
use OCA\Settings\SetupChecks\MaintenanceWindowStart;
use OCA\Settings\SetupChecks\MemcacheConfigured;
+use OCA\Settings\SetupChecks\MysqlUnicodeSupport;
use OCA\Settings\SetupChecks\OverwriteCliUrl;
use OCA\Settings\SetupChecks\PhpDefaultCharset;
use OCA\Settings\SetupChecks\PhpDisabledFunctions;
@@ -190,6 +191,7 @@ class Application extends App implements IBootstrap {
$context->registerSetupCheck(LegacySSEKeyFormat::class);
$context->registerSetupCheck(MaintenanceWindowStart::class);
$context->registerSetupCheck(MemcacheConfigured::class);
+ $context->registerSetupCheck(MysqlUnicodeSupport::class);
$context->registerSetupCheck(OverwriteCliUrl::class);
$context->registerSetupCheck(PhpDefaultCharset::class);
$context->registerSetupCheck(PhpDisabledFunctions::class);
diff --git a/apps/settings/lib/Controller/CheckSetupController.php b/apps/settings/lib/Controller/CheckSetupController.php
index 21161be7cf2..bc898060928 100644
--- a/apps/settings/lib/Controller/CheckSetupController.php
+++ b/apps/settings/lib/Controller/CheckSetupController.php
@@ -202,10 +202,6 @@ Raw output
return false;
}
- protected function isMysqlUsedWithoutUTF8MB4(): bool {
- return ($this->config->getSystemValue('dbtype', 'sqlite') === 'mysql') && ($this->config->getSystemValue('mysql.utf8mb4', false) === false);
- }
-
protected function isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed(): bool {
$objectStore = $this->config->getSystemValue('objectstore', null);
$objectStoreMultibucket = $this->config->getSystemValue('objectstore_multibucket', null);
@@ -251,7 +247,6 @@ Raw output
[
'isFairUseOfFreePushService' => $this->isFairUseOfFreePushService(),
'reverseProxyDocs' => $this->urlGenerator->linkToDocs('admin-reverse-proxy'),
- 'isMysqlUsedWithoutUTF8MB4' => $this->isMysqlUsedWithoutUTF8MB4(),
'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed' => $this->isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed(),
'reverseProxyGeneratedURL' => $this->urlGenerator->getAbsoluteURL('index.php'),
'temporaryDirectoryWritable' => $this->isTemporaryDirectoryWritable(),
diff --git a/apps/settings/lib/SetupChecks/MysqlUnicodeSupport.php b/apps/settings/lib/SetupChecks/MysqlUnicodeSupport.php
new file mode 100644
index 00000000000..c90081c7398
--- /dev/null
+++ b/apps/settings/lib/SetupChecks/MysqlUnicodeSupport.php
@@ -0,0 +1,63 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2023 Côme Chilliet <come.chilliet@nextcloud.com>
+ *
+ * @author Côme Chilliet <come.chilliet@nextcloud.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+namespace OCA\Settings\SetupChecks;
+
+use OCP\IConfig;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+use OCP\SetupCheck\ISetupCheck;
+use OCP\SetupCheck\SetupResult;
+
+class MysqlUnicodeSupport implements ISetupCheck {
+ public function __construct(
+ private IL10N $l10n,
+ private IConfig $config,
+ private IURLGenerator $urlGenerator,
+ ) {
+ }
+
+ public function getName(): string {
+ return $this->l10n->t('MySQL unicode support');
+ }
+
+ public function getCategory(): string {
+ return 'database';
+ }
+
+ public function run(): SetupResult {
+ if ($this->config->getSystemValueString('dbtype') !== 'mysql') {
+ return SetupResult::success($this->l10n->t('You are not using MySQL'));
+ }
+ if ($this->config->getSystemValueBool('mysql.utf8mb4', false)) {
+ return SetupResult::success($this->l10n->t('MySQL is used as database and does support 4-byte characters'));
+ } else {
+ return SetupResult::warning(
+ $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.'),
+ $this->urlGenerator->linkToDocs('admin-mysql-utf8mb4'),
+ );
+ }
+ }
+}
diff --git a/apps/settings/tests/Controller/CheckSetupControllerTest.php b/apps/settings/tests/Controller/CheckSetupControllerTest.php
index bad15a72191..b888e0ce7c8 100644
--- a/apps/settings/tests/Controller/CheckSetupControllerTest.php
+++ b/apps/settings/tests/Controller/CheckSetupControllerTest.php
@@ -118,7 +118,6 @@ class CheckSetupControllerTest extends TestCase {
'getCurlVersion',
'isPhpOutdated',
'isPHPMailerUsed',
- 'isMysqlUsedWithoutUTF8MB4',
'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed',
])->getMock();
}
@@ -144,11 +143,6 @@ class CheckSetupControllerTest extends TestCase {
$this->checkSetupController
->expects($this->once())
- ->method('isMysqlUsedWithoutUTF8MB4')
- ->willReturn(false);
-
- $this->checkSetupController
- ->expects($this->once())
->method('isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed')
->willReturn(true);
@@ -186,7 +180,6 @@ class CheckSetupControllerTest extends TestCase {
$expected = new DataResponse(
[
'reverseProxyDocs' => 'reverse-proxy-doc-link',
- 'isMysqlUsedWithoutUTF8MB4' => false,
'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed' => true,
'reverseProxyGeneratedURL' => 'https://server/index.php',
'isFairUseOfFreePushService' => false,
@@ -653,50 +646,6 @@ Array
$this->assertEquals($expected, $this->checkSetupController->getFailedIntegrityCheckFiles());
}
- public function dataForIsMysqlUsedWithoutUTF8MB4() {
- return [
- ['sqlite', false, false],
- ['sqlite', true, false],
- ['postgres', false, false],
- ['postgres', true, false],
- ['oci', false, false],
- ['oci', true, false],
- ['mysql', false, true],
- ['mysql', true, false],
- ];
- }
-
- /**
- * @dataProvider dataForIsMysqlUsedWithoutUTF8MB4
- */
- public function testIsMysqlUsedWithoutUTF8MB4(string $db, bool $useUTF8MB4, bool $expected) {
- $this->config->method('getSystemValue')
- ->willReturnCallback(function ($key, $default) use ($db, $useUTF8MB4) {
- if ($key === 'dbtype') {
- return $db;
- }
- if ($key === 'mysql.utf8mb4') {
- return $useUTF8MB4;
- }
- return $default;
- });
-
- $checkSetupController = new CheckSetupController(
- 'settings',
- $this->request,
- $this->config,
- $this->urlGenerator,
- $this->l10n,
- $this->checker,
- $this->logger,
- $this->tempManager,
- $this->notificationManager,
- $this->setupCheckManager,
- );
-
- $this->assertSame($expected, $this->invokePrivate($checkSetupController, 'isMysqlUsedWithoutUTF8MB4'));
- }
-
public function dataForIsEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed() {
return [
['singlebucket', 'OC\\Files\\ObjectStore\\Swift', true],