Completed
Push — master ( 8de354...4e0f9f )
by Maxence
01:38
created

Application::registerFilesSearch()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 9.488
c 0
b 0
f 0
cc 4
nc 2
nop 0
1
<?php
2
declare(strict_types=1);
3
4
5
/**
6
 * Files_FullTextSearch - Index the content of your files
7
 *
8
 * This file is licensed under the Affero General Public License version 3 or
9
 * later. See the COPYING file.
10
 *
11
 * @author Maxence Lange <[email protected]>
12
 * @copyright 2018
13
 * @license GNU AGPL version 3 or any later version
14
 *
15
 * This program is free software: you can redistribute it and/or modify
16
 * it under the terms of the GNU Affero General Public License as
17
 * published by the Free Software Foundation, either version 3 of the
18
 * License, or (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU Affero General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU Affero General Public License
26
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
27
 *
28
 */
29
30
31
namespace OCA\Files_FullTextSearch\AppInfo;
32
33
34
use OCA\Files_FullTextSearch\Hooks\FilesHooks;
35
use OCA\Files_FullTextSearch\Provider\FilesProvider;
36
use OCP\App\IAppManager;
37
use OCP\AppFramework\App;
38
use OCP\AppFramework\QueryException;
39
use OCP\FullTextSearch\IFullTextSearchManager;
40
use OCP\IUser;
41
use OCP\IUserSession;
42
use OCP\Util;
43
44
45
/**
46
 * Class Application
47
 *
48
 * @package OCA\Files_FullTextSearch\AppInfo
49
 */
50
class Application extends App {
51
52
	const APP_NAME = 'files_fulltextsearch';
53
54
55
	/** @var IAppManager */
56
	private $appManager;
57
58
	/** @var IFullTextSearchManager */
59
	private $fullTextSearchManager;
60
61
62
	/** @var IUser */
63
	private $user;
64
65
66
	/**
67
	 * Application constructor.
68
	 *
69
	 * @param array $params
70
	 */
71
	public function __construct(array $params = []) {
72
		parent::__construct(self::APP_NAME, $params);
73
74
		$c = $this->getContainer();
75
76
		try {
77
			$this->appManager = $c->query(IAppManager::class);
78
			$this->fullTextSearchManager = $c->query(IFullTextSearchManager::class);
79
		} catch (QueryException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
Bug introduced by
The class OCP\AppFramework\QueryException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
80
		}
81
82
		$this->registerHooks();
83
	}
84
85
86
	/**
87
	 * Register Hooks
88
	 */
89
	public function registerHooks() {
90
		Util::connectHook('OC_Filesystem', 'post_create', FilesHooks::class, 'onNewFile');
91
		Util::connectHook('OC_Filesystem', 'post_update', FilesHooks::class, 'onFileUpdate');
92
		Util::connectHook('OC_Filesystem', 'post_rename', FilesHooks::class, 'onFileRename');
93
		Util::connectHook('OC_Filesystem', 'delete', FilesHooks::class, 'onFileTrash');
94
		Util::connectHook(
95
			'\OCA\Files_Trashbin\Trashbin', 'post_restore', FilesHooks::class, 'onFileRestore'
96
		);
97
		Util::connectHook('\OCP\Trashbin', 'preDelete', FilesHooks::class, 'onFileDelete');
98
		Util::connectHook('OCP\Share', 'post_shared', FilesHooks::class, 'onFileShare');
99
		Util::connectHook('OCP\Share', 'post_unshare', FilesHooks::class, 'onFileUnshare');
100
101
//
102
//		Util::connectHook(
103
//			'\OC\Files\Cache\Scanner', 'post_scan_file', FilesHooks::class, 'onNewRemoteFile2'
104
//		);
105
//
106
//		Util::connectHook(
107
//			'Scanner', 'addToCache', FilesHooks::class, 'onNewRemoteFile'
108
//		);
109
//		Util::connectHook(
110
//			'Scanner', 'updateCache', FilesHooks::class, 'onRemoteFileUpdate'
111
//		);
112
//		Util::connectHook(
113
//			'\OC\Files\Cache\Scanner', 'updateCache', FilesHooks::class, 'onRemoteFileRename'
114
//		);
115
//		Util::connectHook(
116
//			'\OC\Files\Cache\Scanner', 'removeFromCache', FilesHooks::class, 'onRemoteFileDelete'
117
//		);
118
	}
119
120
121
	/**
122
	 * @throws QueryException
123
	 */
124
	public function registerFilesSearch() {
125
		$container = $this->getContainer();
126
127
		/** @var IUserSession $userSession */
128
		$userSession = $container->query(IUserSession::class);
129
130
		if (!$userSession->isLoggedIn()) {
131
			return;
132
		}
133
134
		$this->user = $userSession->getUser();
135
136
		\OC::$server->getEventDispatcher()
137
					->addListener(
138
						'OCA\Files::loadAdditionalScripts', function() {
139
140
						if ($this->appManager->isEnabledForUser('fulltextsearch', $this->user)
141
							&& $this->fullTextSearchManager->isProviderIndexed(
142
								FilesProvider::FILES_PROVIDER_ID
143
							)) {
144
							Util::addStyle(self::APP_NAME, 'fulltextsearch');
145
							$this->fullTextSearchManager->addJavascriptAPI();
146
							Util::addScript(self::APP_NAME, 'files');
147
						}
148
					}
149
					);
150
	}
151
152
}
153
154