1
0

FileLocking.php 1.6 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\Lock\DBLockingProvider;
  9. use OC\Lock\NoopLockingProvider;
  10. use OCP\IL10N;
  11. use OCP\IURLGenerator;
  12. use OCP\Lock\ILockingProvider;
  13. use OCP\SetupCheck\ISetupCheck;
  14. use OCP\SetupCheck\SetupResult;
  15. class FileLocking implements ISetupCheck {
  16. public function __construct(
  17. private IL10N $l10n,
  18. private IURLGenerator $urlGenerator,
  19. private ILockingProvider $lockingProvider,
  20. ) {
  21. }
  22. public function getName(): string {
  23. return $this->l10n->t('File locking');
  24. }
  25. public function getCategory(): string {
  26. return 'system';
  27. }
  28. protected function hasWorkingFileLocking(): bool {
  29. return !($this->lockingProvider instanceof NoopLockingProvider);
  30. }
  31. protected function hasDBFileLocking(): bool {
  32. return ($this->lockingProvider instanceof DBLockingProvider);
  33. }
  34. public function run(): SetupResult {
  35. if (!$this->hasWorkingFileLocking()) {
  36. return SetupResult::warning(
  37. $this->l10n->t('Transactional file locking is disabled, this might lead to issues with race conditions. Enable "filelocking.enabled" in config.php to avoid these problems.'),
  38. $this->urlGenerator->linkToDocs('admin-transactional-locking')
  39. );
  40. }
  41. if ($this->hasDBFileLocking()) {
  42. return SetupResult::info(
  43. $this->l10n->t('The database is used for transactional file locking. To enhance performance, please configure memcache, if available.'),
  44. $this->urlGenerator->linkToDocs('admin-transactional-locking')
  45. );
  46. }
  47. return SetupResult::success();
  48. }
  49. }