FakeDBLockingProvider.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OCA\Testing\Locking;
  25. use OC\Lock\DBLockingProvider;
  26. use OCP\AppFramework\Utility\ITimeFactory;
  27. use OCP\IDBConnection;
  28. class FakeDBLockingProvider extends DBLockingProvider {
  29. // Lock for 10 hours just to be sure
  30. public const TTL = 36000;
  31. /**
  32. * Need a new child, because parent::connection is private instead of protected...
  33. */
  34. protected IDBConnection $db;
  35. public function __construct(
  36. IDBConnection $connection,
  37. ITimeFactory $timeFactory
  38. ) {
  39. parent::__construct($connection, $timeFactory);
  40. $this->db = $connection;
  41. }
  42. /** @inheritDoc */
  43. public function releaseLock(string $path, int $type): void {
  44. // we DONT keep shared locks till the end of the request
  45. if ($type === self::LOCK_SHARED) {
  46. $this->db->executeUpdate(
  47. 'UPDATE `*PREFIX*file_locks` SET `lock` = 0 WHERE `key` = ? AND `lock` = 1',
  48. [$path]
  49. );
  50. }
  51. parent::releaseLock($path, $type);
  52. }
  53. public function __destruct() {
  54. // Prevent cleaning up at the end of the live time.
  55. // parent::__destruct();
  56. }
  57. }