fakedblockingprovider.php 2.0 KB

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