Completed
Push — master ( ee8a58...dc88a3 )
by Individual IT
08:28
created

FakeDBLockingProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author Joas Schilling <[email protected]>
4
 *
5
 * @copyright Copyright (c) 2018, ownCloud GmbH
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
22
namespace OCA\Testing\Locking;
23
24
use OCP\AppFramework\Utility\ITimeFactory;
25
use OCP\IDBConnection;
26
use OCP\ILogger;
27
28
class FakeDBLockingProvider extends \OC\Lock\DBLockingProvider {
29
	// Lock for 10 hours just to be sure
30
	const TTL = 36000;
31
32
	/**
33
	 * Need a new child, because parent::connection is private instead of protected...
34
	 * @var IDBConnection
35
	 */
36
	protected $db;
37
38
	/**
39
	 * @param \OCP\IDBConnection $connection
40
	 * @param \OCP\ILogger $logger
41
	 * @param \OCP\AppFramework\Utility\ITimeFactory $timeFactory
42
	 */
43
	public function __construct(IDBConnection $connection, ILogger $logger, ITimeFactory $timeFactory) {
44
		parent::__construct($connection, $logger, $timeFactory);
45
		$this->db = $connection;
46
	}
47
48
49
	/**
50
	 * @param string $path
51
	 * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE
52
	 */
53
	public function releaseLock($path, $type) {
54
		// we DONT keep shared locks till the end of the request
55
		if ($type === self::LOCK_SHARED) {
56
			$this->db->executeUpdate(
57
				'UPDATE `*PREFIX*file_locks` SET `lock` = 0 WHERE `key` = ? AND `lock` = 1',
58
				[$path]
59
			);
60
		}
61
62
		parent::releaseLock($path, $type);
63
	}
64
65
	/**
66
	 * sets all locks in the file_locks table to "0"
67
	 * @return void
68
	 */
69
	public function releaseAllGlobally() {
70
		$this->db->executeUpdate(
71
			'UPDATE `*PREFIX*file_locks` SET `lock` = 0'
72
		);
73
	}
74
75
	public function __destruct() {
76
		// Prevent cleaning up at the end of the live time.
77
		// parent::__destruct();
78
	}
79
}
80