Completed
Push — master ( 62184d...de56a6 )
by Matias
04:19 queued 04:16
created

Application   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 37.04%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 56
ccs 10
cts 27
cp 0.3704
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A connectSearch() 0 4 1
A addServiceListeners() 0 4 1
A connectWatcher() 0 24 1
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, Roeland Jago Douma <[email protected]>
4
 * @copyright Copyright (c) 2017-2018, 2020 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 OCP\AppFramework\App;
28
use OCP\AppFramework\IAppContainer;
29
use OCP\EventDispatcher\IEventDispatcher;
30
use OCP\Files\IRootFolder;
31
use OCP\Files\Node;
32
use OCP\IUserManager;
33
34
use OCA\Files\Event\LoadSidebar;
0 ignored issues
show
Bug introduced by
The type OCA\Files\Event\LoadSidebar 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...
35
36
use OCA\FaceRecognition\Listener\LoadSidebarListener;
37
use OCA\FaceRecognition\Watcher;
38
39
class Application extends App {
40
41
	/** @var string */
42
	public const APP_NAME = 'facerecognition';
43
44
	/**
45
	 * Application constructor.
46
	 *
47
	 * @param array $urlParams
48
	 */
49
	public function __construct(array $urlParams = []) {
50
		parent::__construct(self::APP_NAME, $urlParams);
51
52
		$this->connectWatcher();
53
		$this->connectSearch();
54
		$this->addServiceListeners();
55
	}
56
57 28
	private function connectWatcher() {
58
		/** @var IRootFolder $root */
59
		$root = $this->getContainer()->query(IRootFolder::class);
60
61
		$root->listen('\OC\Files', 'postWrite', function (Node $node) {
62
			/** @var Watcher $watcher */
63 28
			$watcher = \OC::$server->query(Watcher::class);
64 28
			$watcher->postWrite($node);
65 28
		});
66
67
		// We want to react on postDelete and not preDelete as in preDelete we don't know if
68
		// file actually got deleted (locked, other errors...)
69
		$root->listen('\OC\Files', 'postDelete', function (Node $node) {
70
			/** @var Watcher $watcher */
71 28
			$watcher = \OC::$server->query(Watcher::class);
72 28
			$watcher->postDelete($node);
73 28
		});
74
75
		// Watch for user deletion, so we clean up user data, after user gets deleted
76
		$userManager = $this->getContainer()->query(IUserManager::class);
77
		$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...
78
			/** @var Watcher $watcher */
79 28
			$watcher = \OC::$server->query(Watcher::class);
80 28
			$watcher->postUserDelete($user);
81 28
		});
82
	}
83
84
	private function connectSearch() {
85
		$this->getContainer()->getServer()->getSearch()->registerProvider(
86
			'OCA\FaceRecognition\Search\Provider',
87
			array('app'=>'facerecognition', 'apps' => array('files'))
88
		);
89
	}
90
91
	private function addServiceListeners() {
92
		/** @var IEventDispatcher $dispatcher */
93
		$dispatcher = \OC::$server->query(IEventDispatcher::class);
94
		$dispatcher->addServiceListener(LoadSidebar::class, LoadSidebarListener::class);
95
	}
96
97
}
98