Completed
Push — master ( 3c9d9d...966334 )
by Maxence
01:27
created

FilesEvents::onFileShare()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.8666
c 0
b 0
f 0
cc 4
nc 3
nop 1
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\Events;
32
33
34
use daita\MySmallPhpTools\Traits\TArrayTools;
35
use OC\AppFramework\Bootstrap\Coordinator;
36
use OCA\Files_FullTextSearch\Service\ConfigService;
37
use OCA\Files_FullTextSearch\Service\FilesService;
38
use OCA\Files_FullTextSearch\Service\MiscService;
39
use OCP\App\IAppManager;
40
use OCP\FullTextSearch\IFullTextSearchManager;
41
use OCP\FullTextSearch\Model\IIndex;
42
43
44
/**
45
 * Class FilesEvents
46
 *
47
 * @package OCA\Files_FullTextSearch\Events
48
 */
49
class FilesEvents {
50
51
52
	use TArrayTools;
53
54
55
	/** @var string */
56
	private $userId;
57
58
	/** @var IAppManager */
59
	private $appManager;
60
61
	/** @var Coordinator */
62
	private $coordinator;
63
64
	/** @var IFullTextSearchManager */
65
	private $fullTextSearchManager;
66
67
	/** @var FilesService */
68
	private $filesService;
69
70
	/** @var ConfigService */
71
	private $configService;
72
73
	/** @var MiscService */
74
	private $miscService;
75
76
77
	/**
78
	 * FilesEvents constructor.
79
	 *
80
	 * @param string $userId
81
	 * @param IAppManager $appManager
82
	 * @param Coordinator $coordinator
83
	 * @param IFullTextSearchManager $fullTextSearchManager
84
	 * @param FilesService $filesService
85
	 * @param ConfigService $configService
86
	 * @param MiscService $miscService
87
	 */
88
	public function __construct(
89
		$userId, IAppManager $appManager, Coordinator $coordinator,
90
		IFullTextSearchManager $fullTextSearchManager,
91
		FilesService $filesService, ConfigService $configService, MiscService $miscService
92
	) {
93
		$this->userId = $userId;
94
		$this->appManager = $appManager;
95
		$this->coordinator = $coordinator;
96
		$this->fullTextSearchManager = $fullTextSearchManager;
97
		$this->filesService = $filesService;
98
		$this->configService = $configService;
99
		$this->miscService = $miscService;
100
	}
101
102
103
	/**
104
	 * @return bool
105
	 */
106
	private function registerFullTextSearchServices() {
107
		$this->coordinator->bootApp('fulltextsearch');
108
109
		return $this->fullTextSearchManager->isAvailable();
110
	}
111
112
113
	/**
114
	 * @param array $params
115
	 */
116
	public function onFileUnshare(array $params) {
117
		if (!$this->registerFullTextSearchServices()) {
118
			return;
119
		}
120
121
		$fileId = $this->get('itemSource', $params, '');
122
		if ($fileId === '' || $this->userId === null) {
123
			return;
124
		}
125
126
		$this->fullTextSearchManager->updateIndexStatus('files', $fileId, IIndex::INDEX_META);
127
	}
128
129
130
}
131
132