1
0

fakedblockingprovider.php 2.0 KB

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