|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* FullTextSearch - Full text search framework for Nextcloud |
|
4
|
|
|
* |
|
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
6
|
|
|
* later. See the COPYING file. |
|
7
|
|
|
* |
|
8
|
|
|
* @author Maxence Lange <[email protected]> |
|
9
|
|
|
* @copyright 2018 |
|
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
|
|
|
|
|
27
|
|
|
namespace OCA\FullTextSearch\Service; |
|
28
|
|
|
|
|
29
|
|
|
use OCA\FullTextSearch\AppInfo\Application; |
|
30
|
|
|
use OCA\FullTextSearch\Exceptions\ProviderOptionsDoesNotExistException; |
|
31
|
|
|
use OCA\FullTextSearch\Model\DocumentAccess; |
|
32
|
|
|
use OCA\FullTextSearch\Model\IndexDocument; |
|
33
|
|
|
use OCA\FullTextSearch\Model\IndexOptions; |
|
34
|
|
|
use OCA\FullTextSearch\Provider\TestProvider; |
|
35
|
|
|
use OCP\IConfig; |
|
36
|
|
|
use OCP\PreConditionNotMetException; |
|
37
|
|
|
use OCP\Util; |
|
38
|
|
|
|
|
39
|
|
|
class TestService { |
|
40
|
|
|
|
|
41
|
|
|
const DOCUMENT_USER1 = 'user1'; |
|
42
|
|
|
const DOCUMENT_USER2 = 'user2'; |
|
43
|
|
|
const DOCUMENT_USER3 = 'user3'; |
|
44
|
|
|
const DOCUMENT_NOTUSER = 'notuser'; |
|
45
|
|
|
|
|
46
|
|
|
const DOCUMENT_GROUP1 = 'group_1'; |
|
47
|
|
|
const DOCUMENT_GROUP2 = 'group_2'; |
|
48
|
|
|
const DOCUMENT_NOTGROUP = 'group_3'; |
|
49
|
|
|
|
|
50
|
|
|
const DOCUMENT_TYPE_LICENSE = 'license'; |
|
51
|
|
|
const DOCUMENT_TYPE_SIMPLE = 'simple'; |
|
52
|
|
|
|
|
53
|
|
|
const DOCUMENT_INDEXING_OPTION = 'indexing'; |
|
54
|
|
|
const DOCUMENT_INDEXING_ACCESS = 'access'; |
|
55
|
|
|
|
|
56
|
|
|
const LICENSE_HASH = '108322602bb857915803a84e23a2cc2f'; |
|
57
|
|
|
|
|
58
|
|
|
/** @var MiscService */ |
|
59
|
|
|
private $miscService; |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* TestService constructor. |
|
64
|
|
|
* |
|
65
|
|
|
* @param MiscService $miscService |
|
66
|
|
|
*/ |
|
67
|
|
|
public function __construct(MiscService $miscService) { |
|
68
|
|
|
$this->miscService = $miscService; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param IndexOptions $options |
|
|
|
|
|
|
74
|
|
|
* |
|
75
|
|
|
* @return IndexDocument |
|
76
|
|
|
*/ |
|
77
|
|
|
public function generateIndexDocumentContentLicense(IndexOptions $options = null) { |
|
78
|
|
|
$indexDocument = $this->generateIndexDocument(self::DOCUMENT_TYPE_LICENSE); |
|
79
|
|
|
|
|
80
|
|
|
$content = file_get_contents(__DIR__ . '/../../LICENSE'); |
|
81
|
|
|
$indexDocument->setContent($content); |
|
82
|
|
|
|
|
83
|
|
|
if ($options === null) { |
|
84
|
|
|
return $indexDocument; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
if ($options->getOption(self::DOCUMENT_INDEXING_OPTION, '') |
|
88
|
|
|
=== self::DOCUMENT_INDEXING_ACCESS) { |
|
89
|
|
|
$indexDocument->getAccess() |
|
90
|
|
|
->setGroups([self::DOCUMENT_GROUP1, self::DOCUMENT_GROUP2]); |
|
91
|
|
|
$indexDocument->getAccess() |
|
92
|
|
|
->setUsers([self::DOCUMENT_USER2, self::DOCUMENT_USER3]); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
return $indexDocument; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @param IndexOptions $options |
|
101
|
|
|
* |
|
102
|
|
|
* @return IndexDocument |
|
103
|
|
|
*/ |
|
104
|
|
|
public function generateIndexDocumentSimple(IndexOptions $options) { |
|
|
|
|
|
|
105
|
|
|
|
|
106
|
|
|
$indexDocument = $this->generateIndexDocument(self::DOCUMENT_TYPE_SIMPLE); |
|
107
|
|
|
$indexDocument->setContent('This is a test'); |
|
108
|
|
|
|
|
109
|
|
|
return $indexDocument; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @param IndexDocument $origIndex |
|
115
|
|
|
* @param IndexDocument $compareIndex |
|
116
|
|
|
* |
|
117
|
|
|
* @throws \Exception |
|
118
|
|
|
*/ |
|
119
|
|
|
public function compareIndexDocument(IndexDocument $origIndex, IndexDocument $compareIndex) { |
|
120
|
|
|
if ($origIndex->getAccess() |
|
121
|
|
|
->getOwnerId() !== $compareIndex->getAccess() |
|
122
|
|
|
->getOwnerId()) { |
|
123
|
|
|
throw new \Exception('issue with AccessDocument'); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
$methods = [ |
|
127
|
|
|
'getId', |
|
128
|
|
|
'getProviderId', |
|
129
|
|
|
'getTitle', |
|
130
|
|
|
'getSource' |
|
131
|
|
|
]; |
|
132
|
|
|
|
|
133
|
|
|
foreach ($methods as $method) { |
|
134
|
|
|
$orig = call_user_func([$origIndex, $method]); |
|
135
|
|
|
$compare = call_user_func([$compareIndex, $method]); |
|
136
|
|
|
if ($orig !== $compare) { |
|
137
|
|
|
throw new \Exception($method . '() orig:' . $orig . ' compare:' . $compare); |
|
138
|
|
|
|
|
139
|
|
|
}; |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* @param string $documentType |
|
146
|
|
|
* |
|
147
|
|
|
* @return IndexDocument |
|
148
|
|
|
*/ |
|
149
|
|
|
private function generateIndexDocument($documentType) { |
|
150
|
|
|
$indexDocument = new IndexDocument(TestProvider::TEST_PROVIDER_ID, $documentType); |
|
151
|
|
|
|
|
152
|
|
|
$access = new DocumentAccess(self::DOCUMENT_USER1); |
|
153
|
|
|
$indexDocument->setAccess($access); |
|
154
|
|
|
|
|
155
|
|
|
return $indexDocument; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
} |
|
159
|
|
|
|
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.