Skip to content

Commit

Permalink
Migrate memcached PHP module setup check to new API
Browse files Browse the repository at this point in the history
Merged it with the other existing memcache setup check as it fits

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
  • Loading branch information
come-nc committed Jan 15, 2024
1 parent 77a0e56 commit 1b47c74
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 82 deletions.
19 changes: 0 additions & 19 deletions apps/settings/lib/Controller/CheckSetupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,24 +123,6 @@ private function isFairUseOfFreePushService(): bool {
return $this->manager->isFairUseOfFreePushService();
}

/**
* Checks if the correct memcache module for PHP is installed. Only
* fails if memcached is configured and the working module is not installed.
*
* @return bool
*/
private function isCorrectMemcachedPHPModuleInstalled() {
$memcacheDistributedClass = $this->config->getSystemValue('memcache.distributed', null);
if ($memcacheDistributedClass === null || ltrim($memcacheDistributedClass, '\\') !== \OC\Memcache\Memcached::class) {
return true;
}

// there are two different memcache modules for PHP
// we only support memcached and not memcache
// https://code.google.com/p/memcached/wiki/PHPClientComparison
return !(!extension_loaded('memcached') && extension_loaded('memcache'));
}

/**
* Checks if set_time_limit is not disabled.
*
Expand Down Expand Up @@ -293,7 +275,6 @@ public function check() {
[
'isFairUseOfFreePushService' => $this->isFairUseOfFreePushService(),
'reverseProxyDocs' => $this->urlGenerator->linkToDocs('admin-reverse-proxy'),
'isCorrectMemcachedPHPModuleInstalled' => $this->isCorrectMemcachedPHPModuleInstalled(),
'isSettimelimitAvailable' => $this->isSettimelimitAvailable(),
'areWebauthnExtensionsEnabled' => $this->areWebauthnExtensionsEnabled(),
'isMysqlUsedWithoutUTF8MB4' => $this->isMysqlUsedWithoutUTF8MB4(),
Expand Down
22 changes: 19 additions & 3 deletions apps/settings/lib/SetupChecks/MemcacheConfigured.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,29 @@ public function getCategory(): string {
}

public function run(): SetupResult {
if ($this->config->getSystemValue('memcache.local', null) !== null) {
return SetupResult::success($this->l10n->t('Configured'));
} else {
$memcacheDistributedClass = $this->config->getSystemValue('memcache.distributed', null);
$memcacheLockingClass = $this->config->getSystemValue('memcache.locking', null);
$memcacheLocalClass = $this->config->getSystemValue('memcache.local', null);
$caches = array_filter([$memcacheDistributedClass,$memcacheLockingClass,$memcacheLocalClass]);
if (in_array(\OC\Memcache\Memcached::class, array_map(fn (string $class) => ltrim($class, '\\'), $caches))) {
if (extension_loaded('memcache')) {
return SetupResult::warning(
$this->l10n->t('Memcached is configured as distributed cache, but the wrong PHP module "memcache" is installed. \\OC\\Memcache\\Memcached only supports "memcached" and not "memcache".'),
'https://code.google.com/p/memcached/wiki/PHPClientComparison'
);
}
if (!extension_loaded('memcached')) {
return SetupResult::warning(
$this->l10n->t('Memcached is configured as distributed cache, but the PHP module "memcached" is not installed.')
);
}
}
if ($memcacheLocalClass === null) {
return SetupResult::info(
$this->l10n->t('No memory cache has been configured. To enhance performance, please configure a memcache, if available.'),
$this->urlGenerator->linkToDocs('admin-performance')
);
}
return SetupResult::success($this->l10n->t('Configured'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ public function testCheck() {
$expected = new DataResponse(
[
'reverseProxyDocs' => 'reverse-proxy-doc-link',
'isCorrectMemcachedPHPModuleInstalled' => true,
'isSettimelimitAvailable' => true,
'areWebauthnExtensionsEnabled' => false,
'isMysqlUsedWithoutUTF8MB4' => false,
Expand Down
8 changes: 0 additions & 8 deletions core/js/setupchecks.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,6 @@
type: OC.SetupChecks.MESSAGE_TYPE_ERROR
});
}
if(!data.isCorrectMemcachedPHPModuleInstalled) {
messages.push({
msg: t('core', 'Memcached is configured as distributed cache, but the wrong PHP module "memcache" is installed. \\OC\\Memcache\\Memcached only supports "memcached" and not "memcache". See the {linkstart}memcached wiki about both modules ↗{linkend}.')
.replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="https://code.google.com/p/memcached/wiki/PHPClientComparison">')
.replace('{linkend}', '</a>'),
type: OC.SetupChecks.MESSAGE_TYPE_WARNING
});
}
if(!data.isSettimelimitAvailable) {
messages.push({
msg: t('core', 'The PHP function "set_time_limit" is not available. This could result in scripts being halted mid-execution, breaking your installation. Enabling this function is strongly recommended.'),
Expand Down
51 changes: 0 additions & 51 deletions core/js/tests/specs/setupchecksSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
isFairUseOfFreePushService: true,
isCorrectMemcachedPHPModuleInstalled: true,
isSettimelimitAvailable: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
Expand Down Expand Up @@ -264,7 +263,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
isFairUseOfFreePushService: true,
isCorrectMemcachedPHPModuleInstalled: true,
isSettimelimitAvailable: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
Expand Down Expand Up @@ -304,7 +302,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
isFairUseOfFreePushService: true,
isCorrectMemcachedPHPModuleInstalled: true,
isSettimelimitAvailable: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
Expand Down Expand Up @@ -334,44 +331,6 @@ describe('OC.SetupChecks tests', function() {
});
});

it('should return an error if the wrong memcache PHP module is installed', function(done) {
var async = OC.SetupChecks.checkSetup();

suite.server.requests[0].respond(
200,
{
'Content-Type': 'application/json',
},
JSON.stringify({
isFairUseOfFreePushService: true,
isCorrectMemcachedPHPModuleInstalled: false,
isSettimelimitAvailable: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
reverseProxyGeneratedURL: 'https://server',
temporaryDirectoryWritable: true,
generic: {
network: {
"Internet connectivity": {
severity: "success",
description: null,
linkToDoc: null
}
},
},
})
);

async.done(function( data, s, x ){
expect(data).toEqual([{
msg: 'Memcached is configured as distributed cache, but the wrong PHP module "memcache" is installed. \\OC\\Memcache\\Memcached only supports "memcached" and not "memcache". See the <a target="_blank" rel="noreferrer noopener" class="external" href="https://code.google.com/p/memcached/wiki/PHPClientComparison">memcached wiki about both modules ↗</a>.',
type: OC.SetupChecks.MESSAGE_TYPE_WARNING
}]);
done();
});
});

it('should return an error if set_time_limit is unavailable', function(done) {
var async = OC.SetupChecks.checkSetup();

Expand All @@ -383,7 +342,6 @@ describe('OC.SetupChecks tests', function() {
JSON.stringify({
isFairUseOfFreePushService: true,
reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
isCorrectMemcachedPHPModuleInstalled: true,
isSettimelimitAvailable: false,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
Expand Down Expand Up @@ -422,7 +380,6 @@ describe('OC.SetupChecks tests', function() {
JSON.stringify({
isFairUseOfFreePushService: true,
reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
isCorrectMemcachedPHPModuleInstalled: true,
isSettimelimitAvailable: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
Expand Down Expand Up @@ -492,7 +449,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
isFairUseOfFreePushService: true,
isCorrectMemcachedPHPModuleInstalled: true,
isSettimelimitAvailable: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
Expand Down Expand Up @@ -537,7 +493,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
isFairUseOfFreePushService: true,
isCorrectMemcachedPHPModuleInstalled: true,
isSettimelimitAvailable: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: true,
Expand Down Expand Up @@ -579,7 +534,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
isFairUseOfFreePushService: true,
isCorrectMemcachedPHPModuleInstalled: true,
isSettimelimitAvailable: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
Expand Down Expand Up @@ -618,7 +572,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
isFairUseOfFreePushService: true,
isCorrectMemcachedPHPModuleInstalled: true,
isSettimelimitAvailable: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
Expand Down Expand Up @@ -654,7 +607,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
isFairUseOfFreePushService: true,
isCorrectMemcachedPHPModuleInstalled: true,
isSettimelimitAvailable: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
Expand Down Expand Up @@ -692,7 +644,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
isFairUseOfFreePushService: true,
isCorrectMemcachedPHPModuleInstalled: true,
isSettimelimitAvailable: true,
areWebauthnExtensionsEnabled: false,
isMysqlUsedWithoutUTF8MB4: false,
Expand Down Expand Up @@ -730,7 +681,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
isFairUseOfFreePushService: true,
isCorrectMemcachedPHPModuleInstalled: true,
isSettimelimitAvailable: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
Expand Down Expand Up @@ -775,7 +725,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
isFairUseOfFreePushService: true,
isCorrectMemcachedPHPModuleInstalled: true,
isSettimelimitAvailable: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
Expand Down

0 comments on commit 1b47c74

Please sign in to comment.