Passed
Push — nc21sidebar ( a11006...67b2b6 )
by Matias
05:56
created

Application::addServiceListeners()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, Roeland Jago Douma <[email protected]>
4
 * @copyright Copyright (c) 2017-2021 Matias De lellis <[email protected]>
5
 * @copyright Copyright (c) 2020 Xiangbin Li >[email protected]>
6
 *
7
 * @author Roeland Jago Douma <[email protected]>
8
 * @author Matias De lellis <[email protected]>
9
 *
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
namespace OCA\FaceRecognition\AppInfo;
27
28
use OCP\AppFramework\App;
29
use OCP\AppFramework\Bootstrap\IBootstrap;
30
use OCP\AppFramework\Bootstrap\IRegistrationContext;
31
use OCP\AppFramework\Bootstrap\IBootContext;
32
use OCP\AppFramework\IAppContainer;
33
34
use OCP\EventDispatcher\IEventDispatcher;
35
36
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...
37
use OCP\Files\IRootFolder;
38
use OCP\Files\Node;
39
40
use OCP\IUserManager;
41
42
use OCA\FaceRecognition\Listener\LoadSidebarListener;
43
use OCA\FaceRecognition\Search\PersonSearchProvider;
44
use OCA\FaceRecognition\Watcher;
45
46
class Application extends App implements IBootstrap {
47
48
	/** @var string */
49
	public const APP_NAME = 'facerecognition';
50
51
	/**
52
	 * Application constructor.
53
	 *
54
	 * @param array $urlParams
55
	 */
56
	public function __construct(array $urlParams = []) {
57
		parent::__construct(self::APP_NAME, $urlParams);
58
59
		$this->connectWatcher();
60
	}
61
62
	public function register(IRegistrationContext $context): void {
63
		$context->registerSearchProvider(PersonSearchProvider::class);
64
		$context->registerEventListener(LoadSidebar::class, LoadSidebarListener::class);
65
	}
66
67
	public function boot(IBootContext $context): void {
68
	}
69
70 28
	private function connectWatcher() {
71
		/** @var IRootFolder $root */
72
		$root = $this->getContainer()->query(IRootFolder::class);
0 ignored issues
show
Deprecated Code introduced by
The function OCP\IContainer::query() has been deprecated: 20.0.0 use \Psr\Container\ContainerInterface::get ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

72
		$root = /** @scrutinizer ignore-deprecated */ $this->getContainer()->query(IRootFolder::class);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
73
74
		$root->listen('\OC\Files', 'postWrite', function (Node $node) {
75
			/** @var Watcher $watcher */
76 28
			$watcher = \OC::$server->query(Watcher::class);
77 28
			$watcher->postWrite($node);
78 28
		});
79
80
		// We want to react on postDelete and not preDelete as in preDelete we don't know if
81
		// file actually got deleted (locked, other errors...)
82
		$root->listen('\OC\Files', 'postDelete', function (Node $node) {
83
			/** @var Watcher $watcher */
84 28
			$watcher = \OC::$server->query(Watcher::class);
85 28
			$watcher->postDelete($node);
86 28
		});
87
88
		// Watch for user deletion, so we clean up user data, after user gets deleted
89
		$userManager = $this->getContainer()->query(IUserManager::class);
0 ignored issues
show
Deprecated Code introduced by
The function OCP\IContainer::query() has been deprecated: 20.0.0 use \Psr\Container\ContainerInterface::get ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

89
		$userManager = /** @scrutinizer ignore-deprecated */ $this->getContainer()->query(IUserManager::class);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
90
		$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...
91
			/** @var Watcher $watcher */
92 28
			$watcher = \OC::$server->query(Watcher::class);
93 28
			$watcher->postUserDelete($user);
94 28
		});
95
	}
96
97
}
98