|
17 | 17 |
|
18 | 18 | namespace ApacheSolrForTypo3\Tika\Service\Tika; |
19 | 19 |
|
20 | | -use ApacheSolrForTypo3\Tika\Process; |
21 | | -use ApacheSolrForTypo3\Tika\Utility\FileUtility; |
22 | 20 | use GuzzleHttp\Exception\BadResponseException; |
23 | 21 | use Psr\Container\ContainerExceptionInterface; |
24 | 22 | use Psr\Container\NotFoundExceptionInterface; |
|
31 | 29 | use TYPO3\CMS\Core\Http\RequestFactory; |
32 | 30 | use TYPO3\CMS\Core\Http\Stream; |
33 | 31 | use TYPO3\CMS\Core\Http\Uri; |
34 | | -use TYPO3\CMS\Core\Registry; |
35 | 32 | use TYPO3\CMS\Core\Resource\FileInterface; |
36 | | -use TYPO3\CMS\Core\Utility\CommandUtility; |
37 | 33 | use TYPO3\CMS\Core\Utility\GeneralUtility; |
38 | 34 |
|
39 | 35 | use function str_starts_with; |
@@ -84,97 +80,6 @@ protected function initializeService(): void |
84 | 80 | } |
85 | 81 | } |
86 | 82 |
|
87 | | - /** |
88 | | - * Initializes a Tika server process. |
89 | | - */ |
90 | | - protected function getProcess(string $arguments = ''): Process |
91 | | - { |
92 | | - $arguments = trim($this->getAdditionalCommandOptions() . ' ' . $arguments); |
93 | | - |
94 | | - return GeneralUtility::makeInstance(Process::class, (string)CommandUtility::getCommand('java'), $arguments); |
95 | | - } |
96 | | - |
97 | | - /** |
98 | | - * Creates the command to start the Tika server. |
99 | | - */ |
100 | | - protected function getStartCommand(): string |
101 | | - { |
102 | | - $tikaJar = FileUtility::getAbsoluteFilePath($this->configuration['tikaServerPath']); |
103 | | - $command = '-jar ' . escapeshellarg($tikaJar); |
104 | | - $command .= ' -p ' . escapeshellarg($this->configuration['tikaServerPort']); |
105 | | - |
106 | | - return escapeshellcmd($command); |
107 | | - } |
108 | | - |
109 | | - /** |
110 | | - * Starts the Tika server |
111 | | - */ |
112 | | - public function startServer(): void |
113 | | - { |
114 | | - $process = $this->getProcess($this->getStartCommand()); |
115 | | - $process->start(); |
116 | | - $pid = $process->getPid(); |
117 | | - |
118 | | - /** @var Registry $registry */ |
119 | | - $registry = GeneralUtility::makeInstance(Registry::class); |
120 | | - $registry->set('tx_tika', 'server.pid', $pid); |
121 | | - } |
122 | | - |
123 | | - /** |
124 | | - * Stops the Tika server |
125 | | - */ |
126 | | - public function stopServer(): void |
127 | | - { |
128 | | - $pid = $this->getServerPid(); |
129 | | - if ($pid === null) { |
130 | | - return; |
131 | | - } |
132 | | - |
133 | | - $process = $this->getProcess(); |
134 | | - $process->setPid($pid); |
135 | | - $process->stop(); |
136 | | - |
137 | | - // unset pid in registry |
138 | | - /** @var Registry $registry */ |
139 | | - $registry = GeneralUtility::makeInstance(Registry::class); |
140 | | - $registry->remove('tx_tika', 'server.pid'); |
141 | | - } |
142 | | - |
143 | | - /** |
144 | | - * Gets the Tika server pid. |
145 | | - * |
146 | | - * Tries to retrieve the pid from the TYPO3 registry first, then using ps. |
147 | | - * |
148 | | - * @return int|null Null if the pid can't be found, otherwise the pid |
149 | | - */ |
150 | | - public function getServerPid(): ?int |
151 | | - { |
152 | | - /** @var Registry $registry */ |
153 | | - $registry = GeneralUtility::makeInstance(Registry::class); |
154 | | - $pid = $registry->get('tx_tika', 'server.pid'); |
155 | | - |
156 | | - if (empty($pid)) { |
157 | | - $process = $this->getProcess($this->getStartCommand()); |
158 | | - $pid = $process->findPid(); |
159 | | - } |
160 | | - |
161 | | - if (empty($pid)) { |
162 | | - return null; |
163 | | - } |
164 | | - |
165 | | - return (int)$pid; |
166 | | - } |
167 | | - |
168 | | - /** |
169 | | - * Check if the Tika server is running |
170 | | - */ |
171 | | - public function isServerRunning(): bool |
172 | | - { |
173 | | - $pid = $this->getServerPid(); |
174 | | - |
175 | | - return !empty($pid); |
176 | | - } |
177 | | - |
178 | 83 | /** |
179 | 84 | * Ping the Tika server |
180 | 85 | * |
@@ -226,7 +131,7 @@ public function getTikaVersion(): string |
226 | 131 | { |
227 | 132 | $version = 'unknown'; |
228 | 133 |
|
229 | | - if ($this->isAvailable() || $this->isServerRunning()) { |
| 134 | + if ($this->isAvailable()) { |
230 | 135 | $version = $this->queryTika($this->createRequestForEndpoint('/version')); |
231 | 136 | } |
232 | 137 |
|
|
0 commit comments