Passed
Push — settings-service ( 3fd917...8895a7 )
by Matias
03:54
created

Application::connectWatcher()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 24
ccs 0
cts 14
cp 0
crap 2
rs 9.9
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
29
use OCP\AppFramework\App;
30
use OCP\AppFramework\IAppContainer;
31
use OCP\Files\IRootFolder;
32
use OCP\Files\Node;
33
use OCP\IUserManager;
34
35
class Application extends App {
36
37
	/** @var string */
38
	public const APP_NAME = 'facerecognition';
39
40
	/**
41
	 * Application constructor.
42
	 *
43
	 * @param array $urlParams
44
	 */
45
	public function __construct(array $urlParams = []) {
46
		parent::__construct(self::APP_NAME, $urlParams);
47
48
		$this->connectWatcher();
49
		$this->connectSearch();
50
	}
51
52
	private function connectWatcher() {
53
		/** @var IRootFolder $root */
54
		$root = $this->getContainer()->query(IRootFolder::class);
55
56
		$root->listen('\OC\Files', 'postWrite', function (Node $node) {
57
			/** @var Watcher $watcher */
58
			$watcher = \OC::$server->query(Watcher::class);
59
			$watcher->postWrite($node);
60
		});
61
62
		// We want to react on postDelete and not preDelete as in preDelete we don't know if
63
		// file actually got deleted (locked, other errors...)
64
		$root->listen('\OC\Files', 'postDelete', function (Node $node) {
65
			/** @var Watcher $watcher */
66
			$watcher = \OC::$server->query(Watcher::class);
67
			$watcher->postDelete($node);
68
		});
69
70
		// Watch for user deletion, so we clean up user data, after user gets deleted
71
		$userManager = $this->getContainer()->query(IUserManager::class);
72
		$userManager->listen('\OC\User', 'postDelete', function (\OC\User\User $user) {
0 ignored issues
show
Bug introduced by
The type OC\User\User was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
73
			/** @var Watcher $watcher */
74
			$watcher = \OC::$server->query(Watcher::class);
75
			$watcher->postUserDelete($user);
76
		});
77
	}
78
79
	private function connectSearch() {
80
		$this->getContainer()->getServer()->getSearch()->registerProvider(
81
			'OCA\FaceRecognition\Search\Provider', array('app'=>'facerecognition', 'apps' => array('files')));
82
	}
83
84
}
85