MemcacheConfigured.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Settings\SetupChecks;
  8. use OCP\IConfig;
  9. use OCP\IL10N;
  10. use OCP\IURLGenerator;
  11. use OCP\SetupCheck\ISetupCheck;
  12. use OCP\SetupCheck\SetupResult;
  13. class MemcacheConfigured implements ISetupCheck {
  14. public function __construct(
  15. private IL10N $l10n,
  16. private IConfig $config,
  17. private IURLGenerator $urlGenerator,
  18. ) {
  19. }
  20. public function getName(): string {
  21. return $this->l10n->t('Memcache');
  22. }
  23. public function getCategory(): string {
  24. return 'system';
  25. }
  26. public function run(): SetupResult {
  27. $memcacheDistributedClass = $this->config->getSystemValue('memcache.distributed', null);
  28. $memcacheLockingClass = $this->config->getSystemValue('memcache.locking', null);
  29. $memcacheLocalClass = $this->config->getSystemValue('memcache.local', null);
  30. $caches = array_filter([$memcacheDistributedClass,$memcacheLockingClass,$memcacheLocalClass]);
  31. if (in_array(\OC\Memcache\Memcached::class, array_map(fn (string $class) => ltrim($class, '\\'), $caches))) {
  32. // wrong PHP module is installed
  33. if (extension_loaded('memcache') && !extension_loaded('memcached')) {
  34. return SetupResult::warning(
  35. $this->l10n->t('Memcached is configured as distributed cache, but the wrong PHP module ("memcache") is installed. Please install the PHP module "memcached".')
  36. );
  37. }
  38. // required PHP module is missing
  39. if (!extension_loaded('memcached')) {
  40. return SetupResult::warning(
  41. $this->l10n->t('Memcached is configured as distributed cache, but the PHP module "memcached" is not installed. Please install the PHP module "memcached".')
  42. );
  43. }
  44. }
  45. if ($memcacheLocalClass === null) {
  46. return SetupResult::info(
  47. $this->l10n->t('No memory cache has been configured. To enhance performance, please configure a memcache, if available.'),
  48. $this->urlGenerator->linkToDocs('admin-performance')
  49. );
  50. }
  51. return SetupResult::success($this->l10n->t('Configured'));
  52. }
  53. }