Skip to content

Commit 1334055

Browse files
authored
Merge pull request #42812 from nextcloud/enh/migrate-memcached-setupcheck
Migrate memcached PHP module setup check to new API
2 parents 24dc742 + 5ad549a commit 1334055

5 files changed

Lines changed: 19 additions & 82 deletions

File tree

apps/settings/lib/Controller/CheckSetupController.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -123,24 +123,6 @@ private function isFairUseOfFreePushService(): bool {
123123
return $this->manager->isFairUseOfFreePushService();
124124
}
125125

126-
/**
127-
* Checks if the correct memcache module for PHP is installed. Only
128-
* fails if memcached is configured and the working module is not installed.
129-
*
130-
* @return bool
131-
*/
132-
private function isCorrectMemcachedPHPModuleInstalled() {
133-
$memcacheDistributedClass = $this->config->getSystemValue('memcache.distributed', null);
134-
if ($memcacheDistributedClass === null || ltrim($memcacheDistributedClass, '\\') !== \OC\Memcache\Memcached::class) {
135-
return true;
136-
}
137-
138-
// there are two different memcache modules for PHP
139-
// we only support memcached and not memcache
140-
// https://code.google.com/p/memcached/wiki/PHPClientComparison
141-
return !(!extension_loaded('memcached') && extension_loaded('memcache'));
142-
}
143-
144126
/**
145127
* Checks if set_time_limit is not disabled.
146128
*
@@ -293,7 +275,6 @@ public function check() {
293275
[
294276
'isFairUseOfFreePushService' => $this->isFairUseOfFreePushService(),
295277
'reverseProxyDocs' => $this->urlGenerator->linkToDocs('admin-reverse-proxy'),
296-
'isCorrectMemcachedPHPModuleInstalled' => $this->isCorrectMemcachedPHPModuleInstalled(),
297278
'isSettimelimitAvailable' => $this->isSettimelimitAvailable(),
298279
'areWebauthnExtensionsEnabled' => $this->areWebauthnExtensionsEnabled(),
299280
'isMysqlUsedWithoutUTF8MB4' => $this->isMysqlUsedWithoutUTF8MB4(),

apps/settings/lib/SetupChecks/MemcacheConfigured.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,29 @@ public function getCategory(): string {
4848
}
4949

5050
public function run(): SetupResult {
51-
if ($this->config->getSystemValue('memcache.local', null) !== null) {
52-
return SetupResult::success($this->l10n->t('Configured'));
53-
} else {
51+
$memcacheDistributedClass = $this->config->getSystemValue('memcache.distributed', null);
52+
$memcacheLockingClass = $this->config->getSystemValue('memcache.locking', null);
53+
$memcacheLocalClass = $this->config->getSystemValue('memcache.local', null);
54+
$caches = array_filter([$memcacheDistributedClass,$memcacheLockingClass,$memcacheLocalClass]);
55+
if (in_array(\OC\Memcache\Memcached::class, array_map(fn (string $class) => ltrim($class, '\\'), $caches))) {
56+
if (extension_loaded('memcache')) {
57+
return SetupResult::warning(
58+
$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".'),
59+
'https://code.google.com/p/memcached/wiki/PHPClientComparison'
60+
);
61+
}
62+
if (!extension_loaded('memcached')) {
63+
return SetupResult::warning(
64+
$this->l10n->t('Memcached is configured as distributed cache, but the PHP module "memcached" is not installed.')
65+
);
66+
}
67+
}
68+
if ($memcacheLocalClass === null) {
5469
return SetupResult::info(
5570
$this->l10n->t('No memory cache has been configured. To enhance performance, please configure a memcache, if available.'),
5671
$this->urlGenerator->linkToDocs('admin-performance')
5772
);
5873
}
74+
return SetupResult::success($this->l10n->t('Configured'));
5975
}
6076
}

apps/settings/tests/Controller/CheckSetupControllerTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ public function testCheck() {
192192
$expected = new DataResponse(
193193
[
194194
'reverseProxyDocs' => 'reverse-proxy-doc-link',
195-
'isCorrectMemcachedPHPModuleInstalled' => true,
196195
'isSettimelimitAvailable' => true,
197196
'areWebauthnExtensionsEnabled' => false,
198197
'isMysqlUsedWithoutUTF8MB4' => false,

core/js/setupchecks.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,6 @@
188188
type: OC.SetupChecks.MESSAGE_TYPE_ERROR
189189
});
190190
}
191-
if(!data.isCorrectMemcachedPHPModuleInstalled) {
192-
messages.push({
193-
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}.')
194-
.replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="https://code.google.com/p/memcached/wiki/PHPClientComparison">')
195-
.replace('{linkend}', '</a>'),
196-
type: OC.SetupChecks.MESSAGE_TYPE_WARNING
197-
});
198-
}
199191
if(!data.isSettimelimitAvailable) {
200192
messages.push({
201193
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.'),

core/js/tests/specs/setupchecksSpec.js

Lines changed: 0 additions & 51 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-
isCorrectMemcachedPHPModuleInstalled: true,
228227
isSettimelimitAvailable: true,
229228
areWebauthnExtensionsEnabled: true,
230229
isMysqlUsedWithoutUTF8MB4: false,
@@ -264,7 +263,6 @@ describe('OC.SetupChecks tests', function() {
264263
},
265264
JSON.stringify({
266265
isFairUseOfFreePushService: true,
267-
isCorrectMemcachedPHPModuleInstalled: true,
268266
isSettimelimitAvailable: true,
269267
areWebauthnExtensionsEnabled: true,
270268
isMysqlUsedWithoutUTF8MB4: false,
@@ -304,7 +302,6 @@ describe('OC.SetupChecks tests', function() {
304302
},
305303
JSON.stringify({
306304
isFairUseOfFreePushService: true,
307-
isCorrectMemcachedPHPModuleInstalled: true,
308305
isSettimelimitAvailable: true,
309306
areWebauthnExtensionsEnabled: true,
310307
isMysqlUsedWithoutUTF8MB4: false,
@@ -334,44 +331,6 @@ describe('OC.SetupChecks tests', function() {
334331
});
335332
});
336333

337-
it('should return an error if the wrong memcache PHP module is installed', function(done) {
338-
var async = OC.SetupChecks.checkSetup();
339-
340-
suite.server.requests[0].respond(
341-
200,
342-
{
343-
'Content-Type': 'application/json',
344-
},
345-
JSON.stringify({
346-
isFairUseOfFreePushService: true,
347-
isCorrectMemcachedPHPModuleInstalled: false,
348-
isSettimelimitAvailable: true,
349-
areWebauthnExtensionsEnabled: true,
350-
isMysqlUsedWithoutUTF8MB4: false,
351-
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
352-
reverseProxyGeneratedURL: 'https://server',
353-
temporaryDirectoryWritable: true,
354-
generic: {
355-
network: {
356-
"Internet connectivity": {
357-
severity: "success",
358-
description: null,
359-
linkToDoc: null
360-
}
361-
},
362-
},
363-
})
364-
);
365-
366-
async.done(function( data, s, x ){
367-
expect(data).toEqual([{
368-
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>.',
369-
type: OC.SetupChecks.MESSAGE_TYPE_WARNING
370-
}]);
371-
done();
372-
});
373-
});
374-
375334
it('should return an error if set_time_limit is unavailable', function(done) {
376335
var async = OC.SetupChecks.checkSetup();
377336

@@ -383,7 +342,6 @@ describe('OC.SetupChecks tests', function() {
383342
JSON.stringify({
384343
isFairUseOfFreePushService: true,
385344
reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
386-
isCorrectMemcachedPHPModuleInstalled: true,
387345
isSettimelimitAvailable: false,
388346
areWebauthnExtensionsEnabled: true,
389347
isMysqlUsedWithoutUTF8MB4: false,
@@ -422,7 +380,6 @@ describe('OC.SetupChecks tests', function() {
422380
JSON.stringify({
423381
isFairUseOfFreePushService: true,
424382
reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
425-
isCorrectMemcachedPHPModuleInstalled: true,
426383
isSettimelimitAvailable: true,
427384
areWebauthnExtensionsEnabled: true,
428385
isMysqlUsedWithoutUTF8MB4: false,
@@ -492,7 +449,6 @@ describe('OC.SetupChecks tests', function() {
492449
},
493450
JSON.stringify({
494451
isFairUseOfFreePushService: true,
495-
isCorrectMemcachedPHPModuleInstalled: true,
496452
isSettimelimitAvailable: true,
497453
areWebauthnExtensionsEnabled: true,
498454
isMysqlUsedWithoutUTF8MB4: false,
@@ -537,7 +493,6 @@ describe('OC.SetupChecks tests', function() {
537493
},
538494
JSON.stringify({
539495
isFairUseOfFreePushService: true,
540-
isCorrectMemcachedPHPModuleInstalled: true,
541496
isSettimelimitAvailable: true,
542497
areWebauthnExtensionsEnabled: true,
543498
isMysqlUsedWithoutUTF8MB4: true,
@@ -579,7 +534,6 @@ describe('OC.SetupChecks tests', function() {
579534
},
580535
JSON.stringify({
581536
isFairUseOfFreePushService: true,
582-
isCorrectMemcachedPHPModuleInstalled: true,
583537
isSettimelimitAvailable: true,
584538
areWebauthnExtensionsEnabled: true,
585539
isMysqlUsedWithoutUTF8MB4: false,
@@ -618,7 +572,6 @@ describe('OC.SetupChecks tests', function() {
618572
},
619573
JSON.stringify({
620574
isFairUseOfFreePushService: true,
621-
isCorrectMemcachedPHPModuleInstalled: true,
622575
isSettimelimitAvailable: true,
623576
areWebauthnExtensionsEnabled: true,
624577
isMysqlUsedWithoutUTF8MB4: false,
@@ -654,7 +607,6 @@ describe('OC.SetupChecks tests', function() {
654607
},
655608
JSON.stringify({
656609
isFairUseOfFreePushService: true,
657-
isCorrectMemcachedPHPModuleInstalled: true,
658610
isSettimelimitAvailable: true,
659611
areWebauthnExtensionsEnabled: true,
660612
isMysqlUsedWithoutUTF8MB4: false,
@@ -692,7 +644,6 @@ describe('OC.SetupChecks tests', function() {
692644
},
693645
JSON.stringify({
694646
isFairUseOfFreePushService: true,
695-
isCorrectMemcachedPHPModuleInstalled: true,
696647
isSettimelimitAvailable: true,
697648
areWebauthnExtensionsEnabled: false,
698649
isMysqlUsedWithoutUTF8MB4: false,
@@ -730,7 +681,6 @@ describe('OC.SetupChecks tests', function() {
730681
},
731682
JSON.stringify({
732683
isFairUseOfFreePushService: true,
733-
isCorrectMemcachedPHPModuleInstalled: true,
734684
isSettimelimitAvailable: true,
735685
areWebauthnExtensionsEnabled: true,
736686
isMysqlUsedWithoutUTF8MB4: false,
@@ -775,7 +725,6 @@ describe('OC.SetupChecks tests', function() {
775725
},
776726
JSON.stringify({
777727
isFairUseOfFreePushService: true,
778-
isCorrectMemcachedPHPModuleInstalled: true,
779728
isSettimelimitAvailable: true,
780729
areWebauthnExtensionsEnabled: true,
781730
isMysqlUsedWithoutUTF8MB4: false,

0 commit comments

Comments
 (0)