1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* FullTextSearch - Full text search framework for Nextcloud |
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\FullTextSearch\Command; |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
use Exception; |
35
|
|
|
use OC\Core\Command\Base; |
36
|
|
|
use OCA\FullTextSearch\Model\Index; |
|
|
|
|
37
|
|
|
use OCA\FullTextSearch\Service\MiscService; |
38
|
|
|
use OCA\FullTextSearch\Service\PlatformService; |
39
|
|
|
use OCA\FullTextSearch\Service\ProviderService; |
40
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
41
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
42
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Class DocumentIndex |
47
|
|
|
* |
48
|
|
|
* @package OCA\FullTextSearch\Command |
49
|
|
|
*/ |
50
|
|
|
class DocumentIndex extends Base { |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
/** @var ProviderService */ |
54
|
|
|
private $providerService; |
55
|
|
|
|
56
|
|
|
/** @var PlatformService */ |
57
|
|
|
private $platformService; |
58
|
|
|
|
59
|
|
|
/** @var MiscService */ |
60
|
|
|
private $miscService; |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* DocumentIndex constructor. |
65
|
|
|
* |
66
|
|
|
* @param ProviderService $providerService |
67
|
|
|
* @param PlatformService $platformService |
68
|
|
|
* @param MiscService $miscService |
69
|
|
|
*/ |
70
|
|
View Code Duplication |
public function __construct( |
|
|
|
|
71
|
|
|
ProviderService $providerService, PlatformService $platformService, MiscService $miscService |
72
|
|
|
) { |
73
|
|
|
parent::__construct(); |
74
|
|
|
|
75
|
|
|
$this->providerService = $providerService; |
76
|
|
|
$this->platformService = $platformService; |
77
|
|
|
$this->miscService = $miscService; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* |
83
|
|
|
*/ |
84
|
|
View Code Duplication |
protected function configure() { |
|
|
|
|
85
|
|
|
parent::configure(); |
86
|
|
|
$this->setName('fulltextsearch:document:index') |
87
|
|
|
->setDescription('index one specific document') |
88
|
|
|
->addArgument('userId', InputArgument::REQUIRED, 'userId') |
89
|
|
|
->addArgument('providerId', InputArgument::REQUIRED, 'providerId') |
90
|
|
|
->addArgument('documentId', InputArgument::REQUIRED, 'documentId'); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param InputInterface $input |
96
|
|
|
* @param OutputInterface $output |
97
|
|
|
* |
98
|
|
|
* @throws Exception |
99
|
|
|
*/ |
100
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) { |
101
|
|
|
$providerId = $input->getArgument('providerId'); |
102
|
|
|
$documentId = $input->getArgument('documentId'); |
103
|
|
|
$userId = $input->getArgument('userId'); |
104
|
|
|
|
105
|
|
|
$providerWrapper = $this->providerService->getProvider($providerId); |
106
|
|
|
$provider = $providerWrapper->getProvider(); |
107
|
|
|
|
108
|
|
|
$index = new Index($providerId, $documentId); |
109
|
|
|
$index->setOwnerId($userId); |
110
|
|
|
$index->setStatus(Index::INDEX_FULL); |
111
|
|
|
$indexDocument = $provider->updateDocument($index); |
112
|
|
|
if (!$indexDocument->hasIndex()) { |
113
|
|
|
$indexDocument->setIndex($index); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
if ($indexDocument->getIndex() |
117
|
|
|
->isStatus(Index::INDEX_REMOVE)) { |
118
|
|
|
throw new Exception('Unknown document'); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
$platformWrapper = $this->platformService->getPlatform(); |
122
|
|
|
$platform = $platformWrapper->getPlatform(); |
123
|
|
|
|
124
|
|
|
$indexDocument->getIndex() |
125
|
|
|
->setStatus(Index::INDEX_FULL); |
126
|
|
|
$platform->indexDocument($indexDocument); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
|
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
|
133
|
|
|
|
134
|
|
|
|
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: