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\InterruptedException; |
36
|
|
|
use OCA\FullTextSearch\ACommandBase; |
37
|
|
|
use OCA\FullTextSearch\Exceptions\TickDoesNotExistException; |
38
|
|
|
use OCA\FullTextSearch\Model\Runner; |
39
|
|
|
use OCA\FullTextSearch\Service\IndexService; |
40
|
|
|
use OCA\FullTextSearch\Service\MiscService; |
41
|
|
|
use OCA\FullTextSearch\Service\RunningService; |
42
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
43
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
44
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Class Reset |
49
|
|
|
* |
50
|
|
|
* @package OCA\FullTextSearch\Command |
51
|
|
|
*/ |
52
|
|
|
class Reset extends ACommandBase { |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
/** @var IndexService */ |
56
|
|
|
private $indexService; |
57
|
|
|
|
58
|
|
|
/** @var MiscService */ |
59
|
|
|
private $miscService; |
60
|
|
|
|
61
|
|
|
/** @var Runner */ |
62
|
|
|
private $runner; |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Index constructor. |
67
|
|
|
* |
68
|
|
|
* @param RunningService $runningService |
69
|
|
|
* @param IndexService $indexService |
70
|
|
|
* @param MiscService $miscService |
71
|
|
|
*/ |
72
|
|
|
public function __construct( |
73
|
|
|
RunningService $runningService, IndexService $indexService, MiscService $miscService |
74
|
|
|
) { |
75
|
|
|
parent::__construct(); |
76
|
|
|
$this->indexService = $indexService; |
77
|
|
|
|
78
|
|
|
$this->runner = new Runner($runningService, 'commandReset'); |
79
|
|
|
$this->miscService = $miscService; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* |
85
|
|
|
*/ |
86
|
|
|
protected function configure() { |
87
|
|
|
parent::configure(); |
88
|
|
|
$this->setName('fulltextsearch:reset') |
89
|
|
|
->setDescription('reset index') |
90
|
|
|
->addArgument('provider', InputArgument::OPTIONAL, 'provider'); |
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
|
|
|
|
102
|
|
|
try { |
103
|
|
|
$this->runner->sourceIsCommandLine($this, $output); |
104
|
|
|
$this->runner->start(); |
105
|
|
|
$this->runner->output('reset.'); |
106
|
|
|
|
107
|
|
|
} catch (Exception $e) { |
108
|
|
|
$this->runner->exception($e->getMessage(), true); |
|
|
|
|
109
|
|
|
throw $e; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
$this->indexService->setRunner($this->runner); |
113
|
|
|
try { |
114
|
|
|
$this->indexService->resetIndex($this->getProviderIdFromArgument($input)); |
115
|
|
|
|
116
|
|
|
} catch (Exception $e) { |
117
|
|
|
throw $e; |
118
|
|
|
} finally { |
119
|
|
|
$this->runner->stop(); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @param InputInterface $input |
126
|
|
|
* |
127
|
|
|
* @return string |
128
|
|
|
*/ |
129
|
|
|
private function getProviderIdFromArgument(InputInterface $input): string { |
130
|
|
|
$providerId = $input->getArgument('provider'); |
131
|
|
|
if ($providerId === null) { |
132
|
|
|
$providerId = ''; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
return $providerId; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @throws TickDoesNotExistException |
141
|
|
|
*/ |
142
|
|
|
public function abort() { |
143
|
|
|
try { |
144
|
|
|
$this->abortIfInterrupted(); |
145
|
|
|
} catch (InterruptedException $e) { |
|
|
|
|
146
|
|
|
$this->runner->stop(); |
147
|
|
|
exit(); |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
|
154
|
|
|
|
155
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.