Passed
Push — user-enable-settings ( 42437f...3f14b4 )
by Matias
03:52
created

Application   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 37.5%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 44
ccs 9
cts 24
cp 0.375
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 24 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
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
	/**
38
	 * Application constructor.
39
	 *
40
	 * @param array $urlParams
41
	 */
42
	public function __construct(array $urlParams = []) {
43
		parent::__construct('facerecognition', $urlParams);
44
45
		$this->connectWatcher();
46
		$this->connectSearch();
47
	}
48
49 8
	private function connectWatcher() {
50
		/** @var IRootFolder $root */
51
		$root = $this->getContainer()->query(IRootFolder::class);
52
53 8
		$root->listen('\OC\Files', 'postWrite', function (Node $node) {
54
			/** @var Watcher $watcher */
55 8
			$watcher = \OC::$server->query(Watcher::class);
56 8
			$watcher->postWrite($node);
57 8
		});
58
59
		// We want to react on postDelete and not preDelete as in preDelete we don't know if
60
		// file actually got deleted (locked, other errors...)
61
		$root->listen('\OC\Files', 'postDelete', function (Node $node) {
62
			/** @var Watcher $watcher */
63
			$watcher = \OC::$server->query(Watcher::class);
64
			$watcher->postDelete($node);
65
		});
66
67
		// Watch for user deletion, so we clean up user data, after user gets deleted
68
		$userManager = $this->getContainer()->query(IUserManager::class);
69 8
		$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...
70
			/** @var Watcher $watcher */
71 8
			$watcher = \OC::$server->query(Watcher::class);
72 8
			$watcher->postUserDelete($user);
73 8
		});
74
	}
75
76
	private function connectSearch() {
77
		$this->getContainer()->getServer()->getSearch()->registerProvider(
78
			'OCA\FaceRecognition\Search\Provider', array('app'=>'facerecognition', 'apps' => array('files')));
79
	}
80
81
}
82