Skip to content

Commit

Permalink
Add setup check for missing UTF8MB4 on mysql
Browse files Browse the repository at this point in the history
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
  • Loading branch information
MorrisJobke committed Feb 27, 2019
1 parent 25bb091 commit e0c9690
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 13 deletions.
12 changes: 12 additions & 0 deletions core/js/setupchecks.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,18 @@
type: OC.SetupChecks.MESSAGE_TYPE_WARNING
});
}
if (data.isMysqlUsedWithoutUTF8MB4) {
messages.push({
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 <a target="_blank" rel="noreferrer noopener" href="{docLink}">the documentation page about this</a>.',
{
docLink: oc_defaults.docPlaceholderUrl.replace('PLACEHOLDER', 'admin-mysql-utf8mb4'),
}
),
type: OC.SetupChecks.MESSAGE_TYPE_WARNING
})
}

} else {
messages.push({
Expand Down
87 changes: 74 additions & 13 deletions core/js/tests/specs/setupchecksSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ describe('OC.SetupChecks tests', function() {
isMemoryLimitSufficient: true,
appDirsWithDifferentOwner: [],
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
pendingBigIntConversionColumns: [],
isMysqlUsedWithoutUTF8MB4: false
})
);

Expand Down Expand Up @@ -297,7 +298,8 @@ describe('OC.SetupChecks tests', function() {
isMemoryLimitSufficient: true,
appDirsWithDifferentOwner: [],
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
pendingBigIntConversionColumns: [],
isMysqlUsedWithoutUTF8MB4: false
})
);

Expand Down Expand Up @@ -348,7 +350,8 @@ describe('OC.SetupChecks tests', function() {
isMemoryLimitSufficient: true,
appDirsWithDifferentOwner: [],
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
pendingBigIntConversionColumns: [],
isMysqlUsedWithoutUTF8MB4: false
})
);

Expand Down Expand Up @@ -397,7 +400,8 @@ describe('OC.SetupChecks tests', function() {
isMemoryLimitSufficient: true,
appDirsWithDifferentOwner: [],
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
pendingBigIntConversionColumns: [],
isMysqlUsedWithoutUTF8MB4: false
})
);

Expand Down Expand Up @@ -444,7 +448,8 @@ describe('OC.SetupChecks tests', function() {
isMemoryLimitSufficient: true,
appDirsWithDifferentOwner: [],
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
pendingBigIntConversionColumns: [],
isMysqlUsedWithoutUTF8MB4: false
})
);

Expand Down Expand Up @@ -493,7 +498,8 @@ describe('OC.SetupChecks tests', function() {
'/some/path'
],
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
pendingBigIntConversionColumns: [],
isMysqlUsedWithoutUTF8MB4: false
})
);

Expand Down Expand Up @@ -540,7 +546,8 @@ describe('OC.SetupChecks tests', function() {
isMemoryLimitSufficient: true,
appDirsWithDifferentOwner: [],
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
pendingBigIntConversionColumns: [],
isMysqlUsedWithoutUTF8MB4: false
})
);

Expand Down Expand Up @@ -587,7 +594,8 @@ describe('OC.SetupChecks tests', function() {
isMemoryLimitSufficient: true,
appDirsWithDifferentOwner: [],
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
pendingBigIntConversionColumns: [],
isMysqlUsedWithoutUTF8MB4: false
})
);

Expand Down Expand Up @@ -634,7 +642,8 @@ describe('OC.SetupChecks tests', function() {
isMemoryLimitSufficient: false,
appDirsWithDifferentOwner: [],
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
pendingBigIntConversionColumns: [],
isMysqlUsedWithoutUTF8MB4: false
})
);

Expand Down Expand Up @@ -702,7 +711,8 @@ describe('OC.SetupChecks tests', function() {
isMemoryLimitSufficient: true,
appDirsWithDifferentOwner: [],
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
pendingBigIntConversionColumns: [],
isMysqlUsedWithoutUTF8MB4: false
})
);

Expand Down Expand Up @@ -750,7 +760,8 @@ describe('OC.SetupChecks tests', function() {
isMemoryLimitSufficient: true,
appDirsWithDifferentOwner: [],
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
pendingBigIntConversionColumns: [],
isMysqlUsedWithoutUTF8MB4: false
})
);

Expand Down Expand Up @@ -798,7 +809,8 @@ describe('OC.SetupChecks tests', function() {
isMemoryLimitSufficient: true,
appDirsWithDifferentOwner: [],
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
pendingBigIntConversionColumns: [],
isMysqlUsedWithoutUTF8MB4: false
})
);

Expand Down Expand Up @@ -846,7 +858,8 @@ describe('OC.SetupChecks tests', function() {
isMemoryLimitSufficient: true,
appDirsWithDifferentOwner: [],
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
pendingBigIntConversionColumns: [],
isMysqlUsedWithoutUTF8MB4: false
})
);

Expand All @@ -858,6 +871,54 @@ describe('OC.SetupChecks tests', function() {
done();
});
});

it('should return an error if the php version is no longer supported', function(done) {
var async = OC.SetupChecks.checkSetup();

suite.server.requests[0].respond(
200,
{
'Content-Type': 'application/json',
},
JSON.stringify({
hasFileinfoInstalled: true,
isGetenvServerWorking: true,
isReadOnlyConfig: false,
hasWorkingFileLocking: true,
hasValidTransactionIsolationLevel: true,
suggestedOverwriteCliURL: '',
isRandomnessSecure: true,
securityDocs: 'https://docs.owncloud.org/myDocs.html',
serverHasInternetConnection: true,
isMemcacheConfigured: true,
forwardedForHeadersWorking: true,
isCorrectMemcachedPHPModuleInstalled: true,
hasPassedCodeIntegrityCheck: true,
isOpcacheProperlySetup: true,
hasOpcacheLoaded: true,
isSettimelimitAvailable: true,
hasFreeTypeSupport: true,
missingIndexes: [],
cronErrors: [],
cronInfo: {
diffInSeconds: 0
},
isMemoryLimitSufficient: true,
appDirsWithDifferentOwner: [],
recommendedPHPModules: [],
pendingBigIntConversionColumns: [],
isMysqlUsedWithoutUTF8MB4: true
})
);

async.done(function( data, s, x ){
expect(data).toEqual([{
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 href="https://docs.example.org/admin-mysql-utf8mb4" rel="noreferrer noopener">the documentation page about this</a>.',
type: OC.SetupChecks.MESSAGE_TYPE_WARNING
}]);
done();
});
});
});

describe('checkGeneric', function() {
Expand Down
5 changes: 5 additions & 0 deletions settings/Controller/CheckSetupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,10 @@ protected function hasRecommendedPHPModules(): array {
return $recommendedPHPModules;
}

protected function isMysqlUsedWithoutUTF8MB4(): bool {
return $this->config->getSystemValue('dbtype', 'sqlite') === 'mysql' && $this->config->getSystemValue('mysql.utf8mb4', false) === false;
}

protected function hasBigIntConversionPendingColumns(): array {
// copy of ConvertFilecacheBigInt::getColumnsByTable()
$tables = [
Expand Down Expand Up @@ -664,6 +668,7 @@ public function check() {
'appDirsWithDifferentOwner' => $this->getAppDirsWithDifferentOwner(),
'recommendedPHPModules' => $this->hasRecommendedPHPModules(),
'pendingBigIntConversionColumns' => $this->hasBigIntConversionPendingColumns(),
'isMysqlUsedWithoutUTF8MB4' => $this->isMysqlUsedWithoutUTF8MB4(),
]
);
}
Expand Down
34 changes: 34 additions & 0 deletions tests/Settings/Controller/CheckSetupControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,11 @@ public function testCheck() {
->method('hasBigIntConversionPendingColumns')
->willReturn([]);

$this->checkSetupController
->expects($this->once())
->method('isMysqlUsedWithoutUTF8MB4')
->willReturn(false);

$expected = new DataResponse(
[
'isGetenvServerWorking' => true,
Expand Down Expand Up @@ -563,6 +568,7 @@ public function testCheck() {
'appDirsWithDifferentOwner' => [],
'recommendedPHPModules' => [],
'pendingBigIntConversionColumns' => [],
'isMysqlUsedWithoutUTF8MB4' => false,
]
);
$this->assertEquals($expected, $this->checkSetupController->check());
Expand Down Expand Up @@ -1344,4 +1350,32 @@ public function testGetFailedIntegrityCheckFilesWithSomeErrorsFound() {
);
$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->expects($this->at(0))
->method('getSystemValue')
->will($this->returnValue($db));
if ($db === 'mysql') {
$this->config->expects($this->at(1))
->method('getSystemValue')
->will($this->returnValue($useUTF8MB4));
}
$this->assertSame($expected, $this->invokePrivate($this->checkSetupController, 'isMysqlUsedWithoutUTF8MB4'));
}
}

0 comments on commit e0c9690

Please sign in to comment.