]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix(memcache): Fix comparison of Memcache configs to classes 39947/head
authorJoas Schilling <coding@schilljs.com>
Wed, 16 Aug 2023 14:01:00 +0000 (16:01 +0200)
committerbackportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com>
Thu, 17 Aug 2023 21:08:09 +0000 (21:08 +0000)
Signed-off-by: Joas Schilling <coding@schilljs.com>
apps/settings/lib/Controller/CheckSetupController.php
lib/private/Memcache/Factory.php

index a0c52f6e13d289705adee5f7e664a96e3c0f1507..a55596358e5dc61707d635c468c73c9f8c251648 100644 (file)
@@ -382,7 +382,8 @@ class CheckSetupController extends Controller {
         * @return bool
         */
        private function isCorrectMemcachedPHPModuleInstalled() {
-               if ($this->config->getSystemValue('memcache.distributed', null) !== '\OC\Memcache\Memcached') {
+               $memcacheDistributedClass = $this->config->getSystemValue('memcache.distributed', null);
+               if ($memcacheDistributedClass === null || ltrim($memcacheDistributedClass, '\\') !== \OC\Memcache\Memcached::class) {
                        return true;
                }
 
index 604f764c03c11e1258f85c6fb87a693b89195c79..788a7c2e8c91af7bf40651342aa6929e8047a7a6 100644 (file)
@@ -73,16 +73,17 @@ class Factory implements ICacheFactory {
         */
        public function __construct(string $globalPrefix, LoggerInterface $logger, IProfiler $profiler,
                ?string $localCacheClass = null, ?string $distributedCacheClass = null, ?string $lockingCacheClass = null, string $logFile = '') {
-               $this->logger = $logger;
                $this->logFile = $logFile;
                $this->globalPrefix = $globalPrefix;
 
                if (!$localCacheClass) {
                        $localCacheClass = self::NULL_CACHE;
                }
+               $localCacheClass = ltrim($localCacheClass, '\\');
                if (!$distributedCacheClass) {
                        $distributedCacheClass = $localCacheClass;
                }
+               $distributedCacheClass = ltrim($distributedCacheClass, '\\');
 
                $missingCacheMessage = 'Memcache {class} not available for {use} cache';
                $missingCacheHint = 'Is the matching PHP module installed and enabled?';
@@ -97,9 +98,10 @@ class Factory implements ICacheFactory {
                        ]), $missingCacheHint);
                }
                if (!($lockingCacheClass && class_exists($lockingCacheClass) && $lockingCacheClass::isAvailable())) {
-                       // don't fallback since the fallback might not be suitable for storing lock
+                       // don't fall back since the fallback might not be suitable for storing lock
                        $lockingCacheClass = self::NULL_CACHE;
                }
+               $lockingCacheClass = ltrim($lockingCacheClass, '\\');
 
                $this->localCacheClass = $localCacheClass;
                $this->distributedCacheClass = $distributedCacheClass;
@@ -116,7 +118,7 @@ class Factory implements ICacheFactory {
        public function createLocking(string $prefix = ''): IMemcache {
                assert($this->lockingCacheClass !== null);
                $cache = new $this->lockingCacheClass($this->globalPrefix . '/' . $prefix);
-               if ($this->profiler->isEnabled() && $this->lockingCacheClass === '\OC\Memcache\Redis') {
+               if ($this->lockingCacheClass === Redis::class && $this->profiler->isEnabled()) {
                        // We only support the profiler with Redis
                        $cache = new ProfilerWrapperCache($cache, 'Locking');
                        $this->profiler->add($cache);
@@ -138,7 +140,7 @@ class Factory implements ICacheFactory {
        public function createDistributed(string $prefix = ''): ICache {
                assert($this->distributedCacheClass !== null);
                $cache = new $this->distributedCacheClass($this->globalPrefix . '/' . $prefix);
-               if ($this->profiler->isEnabled() && $this->distributedCacheClass === '\OC\Memcache\Redis') {
+               if ($this->distributedCacheClass === Redis::class && $this->profiler->isEnabled()) {
                        // We only support the profiler with Redis
                        $cache = new ProfilerWrapperCache($cache, 'Distributed');
                        $this->profiler->add($cache);
@@ -160,7 +162,7 @@ class Factory implements ICacheFactory {
        public function createLocal(string $prefix = ''): ICache {
                assert($this->localCacheClass !== null);
                $cache = new $this->localCacheClass($this->globalPrefix . '/' . $prefix);
-               if ($this->profiler->isEnabled() && $this->localCacheClass === '\OC\Memcache\Redis') {
+               if ($this->localCacheClass === Redis::class && $this->profiler->isEnabled()) {
                        // We only support the profiler with Redis
                        $cache = new ProfilerWrapperCache($cache, 'Local');
                        $this->profiler->add($cache);
@@ -179,7 +181,7 @@ class Factory implements ICacheFactory {
         * @return bool
         */
        public function isAvailable(): bool {
-               return ($this->distributedCacheClass !== self::NULL_CACHE);
+               return $this->distributedCacheClass !== self::NULL_CACHE;
        }
 
        /**
@@ -197,6 +199,6 @@ class Factory implements ICacheFactory {
         * @return bool
         */
        public function isLocalCacheAvailable(): bool {
-               return ($this->localCacheClass !== self::NULL_CACHE);
+               return $this->localCacheClass !== self::NULL_CACHE;
        }
 }