1
0

MemcacheConfigured.php 2.0 KB

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