|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors |
| 7 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 8 | + */ |
| 9 | + |
| 10 | +namespace OCA\Settings\SetupChecks; |
| 11 | + |
| 12 | +use OC\Memcache\Redis; |
| 13 | +use OCP\IConfig; |
| 14 | +use OCP\IL10N; |
| 15 | +use OCP\IURLGenerator; |
| 16 | +use OCP\SetupCheck\ISetupCheck; |
| 17 | +use OCP\SetupCheck\SetupResult; |
| 18 | + |
| 19 | +class MemcacheLegacy implements ISetupCheck { |
| 20 | + public function __construct( |
| 21 | + private readonly IL10N $l10n, |
| 22 | + private readonly IConfig $config, |
| 23 | + private readonly IURLGenerator $urlGenerator, |
| 24 | + ) { |
| 25 | + } |
| 26 | + |
| 27 | + #[\Override] |
| 28 | + public function getName(): string { |
| 29 | + return $this->l10n->t('Redis cache'); |
| 30 | + } |
| 31 | + |
| 32 | + #[\Override] |
| 33 | + public function getCategory(): string { |
| 34 | + return 'system'; |
| 35 | + } |
| 36 | + |
| 37 | + #[\Override] |
| 38 | + public function run(): SetupResult { |
| 39 | + if ($this->isLegacyRedisUsed()) { |
| 40 | + return SetupResult::info( |
| 41 | + $this->l10n->t('You are still using the old Redis cache backend. For full support of latest Valkey and Redis features, like clustering and sentinel, please switch to the new KeyValueCache backend.'), |
| 42 | + $this->urlGenerator->linkToDocs('admin-cache') |
| 43 | + ); |
| 44 | + } else { |
| 45 | + return SetupResult::success($this->l10n->t('No legacy Redis cache detected')); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + protected function isLegacyRedisUsed(): bool { |
| 50 | + $memcacheDistributedClass = $this->config->getSystemValue('memcache.distributed', null); |
| 51 | + $memcacheLockingClass = $this->config->getSystemValue('memcache.locking', null); |
| 52 | + |
| 53 | + /** @psalm-suppress DeprecatedClass */ |
| 54 | + if ($memcacheDistributedClass === Redis::class || $memcacheLockingClass === Redis::class) { |
| 55 | + return true; |
| 56 | + } |
| 57 | + return false; |
| 58 | + } |
| 59 | +} |
0 commit comments