Passed
Push — new-admin-page ( 30dc11...e562a3 )
by Matias
01:38
created

Application   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 25%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 40
ccs 6
cts 24
cp 0.25
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A connectSearch() 0 3 1
A connectWatcher() 0 20 1
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, Roeland Jago Douma <[email protected]>
4
 * @copyright Copyright (c) 2017, Matias De lellis <[email protected]>
5
 *
6
 * @author Roeland Jago Douma <[email protected]>
7
 * @author Matias De lellis <[email protected]>
8
 *
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
namespace OCA\FaceRecognition\AppInfo;
26
27
use OCA\FaceRecognition\Watcher;
28
use OCP\AppFramework\App;
29
use OCP\AppFramework\IAppContainer;
30
use OCP\Files\IRootFolder;
31
use OCP\Files\Node;
32
33
class Application extends App {
34
35
	/**
36
	 * Application constructor.
37
	 *
38
	 * @param array $urlParams
39
	 */
40
	public function __construct(array $urlParams = []) {
41
		parent::__construct('facerecognition', $urlParams);
42
43
		$this->connectWatcher();
44
		$this->connectSearch();
45
	}
46
47 4
	private function connectWatcher() {
48
		/** @var IRootFolder $root */
49
		$root = $this->getContainer()->query(IRootFolder::class);
50 4
		$root->listen('\OC\Files', 'postWrite', function (Node $node) {
51
			/** @var Watcher $watcher */
52 4
			$watcher = \OC::$server->query(Watcher::class);
53 4
			$watcher->postWrite($node);
54 4
			$watcher->postWritev2($node);
55 4
		});
56
		$root->listen('\OC\Files', 'preDelete', function (Node $node) {
57
			/** @var Watcher $watcher */
58
			$watcher = \OC::$server->query(Watcher::class);
59
			$watcher->preDelete($node);
60
		});
61
		// We want to react on postDelete and not preDelete as in preDelete we don't know if
62
		// file actually got deleted (locked, other errors...)
63
		$root->listen('\OC\Files', 'postDelete', function (Node $node) {
64
			/** @var Watcher $watcher */
65
			$watcher = \OC::$server->query(Watcher::class);
66
			$watcher->postDeletev2($node);
67
		});
68
	}
69
70
	private function connectSearch() {
71
		$this->getContainer()->getServer()->getSearch()->registerProvider(
72
			'OCA\FaceRecognition\Search\Provider', array('app'=>'facerecognition', 'apps' => array('files')));
73
	}
74
75
}
76