Completed
Push — master ( 8bf574...c0bbae )
by Lukas
28:01 queued 15:22
created

WatcherConnector   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getWatcher() 0 3 1
A connectWatcher() 0 16 2
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, Roeland Jago Douma <[email protected]>
4
 *
5
 * @author Roeland Jago Douma <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 * This program is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License as
11
 * published by the Free Software Foundation, either version 3 of the
12
 * License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU Affero General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public License
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
namespace OC\Preview;
24
25
use OC\SystemConfig;
26
use OCP\Files\Node;
27
use OCP\Files\IRootFolder;
28
29
class WatcherConnector {
30
31
	/** @var IRootFolder */
32
	private $root;
33
34
	/** @var SystemConfig */
35
	private $config;
36
37
	/**
38
	 * WatcherConnector constructor.
39
	 *
40
	 * @param IRootFolder $root
41
	 * @param SystemConfig $config
42
	 */
43
	public function __construct(IRootFolder $root,
44
								SystemConfig $config) {
45
		$this->root = $root;
46
		$this->config = $config;
47
	}
48
49
	/**
50
	 * @return Watcher
51
	 */
52
	private function getWatcher() {
53
		return \OC::$server->query(Watcher::class);
54
	}
55
56
	public function connectWatcher() {
57
		// Do not connect if we are not setup yet!
58
		if ($this->config->getValue('instanceid', null) !== null) {
59
			$this->root->listen('\OC\Files', 'postWrite', function (Node $node) {
60
				$this->getWatcher()->postWrite($node);
61
			});
62
63
			$this->root->listen('\OC\Files', 'preDelete', function (Node $node) {
64
				$this->getWatcher()->preDelete($node);
65
			});
66
67
			$this->root->listen('\OC\Files', 'postDelete', function (Node $node) {
68
				$this->getWatcher()->postDelete($node);
69
			});
70
		}
71
	}
72
}
73