Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable27] fix(memcache): Fix comparison of Memcache configs to classes #39947

Merged
merged 1 commit into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/settings/lib/Controller/CheckSetupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,8 @@ private function forwardedForHeadersWorking(): bool {
* @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;
}

Expand Down
16 changes: 9 additions & 7 deletions lib/private/Memcache/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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?';
Expand All @@ -97,9 +98,10 @@ public function __construct(string $globalPrefix, LoggerInterface $logger, IProf
]), $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;
Expand All @@ -116,7 +118,7 @@ public function __construct(string $globalPrefix, LoggerInterface $logger, IProf
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);
Expand All @@ -138,7 +140,7 @@ public function createLocking(string $prefix = ''): IMemcache {
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);
Expand All @@ -160,7 +162,7 @@ public function createDistributed(string $prefix = ''): ICache {
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);
Expand All @@ -179,7 +181,7 @@ public function createLocal(string $prefix = ''): ICache {
* @return bool
*/
public function isAvailable(): bool {
return ($this->distributedCacheClass !== self::NULL_CACHE);
return $this->distributedCacheClass !== self::NULL_CACHE;
}

/**
Expand All @@ -197,6 +199,6 @@ public function createLowLatency(string $prefix = ''): ICache {
* @return bool
*/
public function isLocalCacheAvailable(): bool {
return ($this->localCacheClass !== self::NULL_CACHE);
return $this->localCacheClass !== self::NULL_CACHE;
}
}
Loading