FakeDBLockingProvider.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 OCP\AppFramework\Utility\ITimeFactory;
  26. use OCP\IDBConnection;
  27. use Psr\Log\LoggerInterface;
  28. use OC\Lock\DBLockingProvider;
  29. class FakeDBLockingProvider extends DBLockingProvider {
  30. // Lock for 10 hours just to be sure
  31. public const TTL = 36000;
  32. /**
  33. * Need a new child, because parent::connection is private instead of protected...
  34. */
  35. protected IDBConnection $db;
  36. public function __construct(
  37. IDBConnection $connection,
  38. ITimeFactory $timeFactory
  39. ) {
  40. parent::__construct($connection, $timeFactory);
  41. $this->db = $connection;
  42. }
  43. /** @inheritDoc */
  44. public function releaseLock(string $path, int $type): void {
  45. // we DONT keep shared locks till the end of the request
  46. if ($type === self::LOCK_SHARED) {
  47. $this->db->executeUpdate(
  48. 'UPDATE `*PREFIX*file_locks` SET `lock` = 0 WHERE `key` = ? AND `lock` = 1',
  49. [$path]
  50. );
  51. }
  52. parent::releaseLock($path, $type);
  53. }
  54. public function __destruct() {
  55. // Prevent cleaning up at the end of the live time.
  56. // parent::__destruct();
  57. }
  58. }