FakeDBLockingProvider.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\Testing\Locking;
  8. use OC\Lock\DBLockingProvider;
  9. use OCP\AppFramework\Utility\ITimeFactory;
  10. use OCP\IDBConnection;
  11. class FakeDBLockingProvider extends DBLockingProvider {
  12. // Lock for 10 hours just to be sure
  13. public const TTL = 36000;
  14. /**
  15. * Need a new child, because parent::connection is private instead of protected...
  16. */
  17. protected IDBConnection $db;
  18. public function __construct(
  19. IDBConnection $connection,
  20. ITimeFactory $timeFactory
  21. ) {
  22. parent::__construct($connection, $timeFactory);
  23. $this->db = $connection;
  24. }
  25. /** @inheritDoc */
  26. public function releaseLock(string $path, int $type): void {
  27. // we DONT keep shared locks till the end of the request
  28. if ($type === self::LOCK_SHARED) {
  29. $this->db->executeUpdate(
  30. 'UPDATE `*PREFIX*file_locks` SET `lock` = 0 WHERE `key` = ? AND `lock` = 1',
  31. [$path]
  32. );
  33. }
  34. parent::releaseLock($path, $type);
  35. }
  36. public function __destruct() {
  37. // Prevent cleaning up at the end of the live time.
  38. // parent::__destruct();
  39. }
  40. }