1 | <?php |
||
35 | class ProcessCleanUpHook |
||
36 | { |
||
37 | /** |
||
38 | * @var CrawlerController |
||
39 | */ |
||
40 | private $crawlerController; |
||
41 | |||
42 | /** |
||
43 | * @var array |
||
44 | */ |
||
45 | private $extensionSettings; |
||
46 | |||
47 | /** |
||
48 | * Main function of process CleanUp Hook. |
||
49 | * |
||
50 | * @param CrawlerController $crawlerController Crawler Lib class |
||
51 | * |
||
52 | * @return void |
||
53 | */ |
||
54 | public function crawler_init(CrawlerController $crawlerController) |
||
63 | |||
64 | /** |
||
65 | * Remove active processes older than one hour |
||
66 | * |
||
67 | * @return void |
||
68 | */ |
||
69 | private function removeActiveProcessesOlderThanOneHour() |
||
91 | |||
92 | /** |
||
93 | * Removes active orphan processes from process list |
||
94 | * |
||
95 | * @return void |
||
96 | */ |
||
97 | private function removeActiveOrphanProcesses() |
||
130 | |||
131 | /** |
||
132 | * Remove a process from processlist |
||
133 | * |
||
134 | * @param string $processId Unique process Id. |
||
135 | * |
||
136 | * @return void |
||
137 | */ |
||
138 | 3 | private function removeProcessFromProcesslist($processId) |
|
139 | { |
||
140 | 3 | $this->getDatabaseConnection()->exec_DELETEquery( |
|
141 | 3 | 'tx_crawler_process', |
|
142 | 3 | 'process_id = ' . $this->getDatabaseConnection()->fullQuoteStr($processId, 'tx_crawler_process') |
|
143 | ); |
||
144 | |||
145 | 3 | $this->getDatabaseConnection()->exec_UPDATEquery( |
|
146 | 3 | 'tx_crawler_queue', |
|
147 | 3 | 'process_id = ' . $this->getDatabaseConnection()->fullQuoteStr($processId, 'tx_crawler_queue'), |
|
148 | 3 | ['process_id' => ''] |
|
149 | ); |
||
150 | 3 | } |
|
151 | |||
152 | /** |
||
153 | * Create response array |
||
154 | * Convert string to array with space character as delimiter, |
||
155 | * removes all empty records to have a cleaner array |
||
156 | * |
||
157 | * @param string $string String to create array from |
||
158 | * |
||
159 | * @return array |
||
160 | * |
||
161 | */ |
||
162 | 2 | private function createResponseArray($string) |
|
163 | { |
||
164 | 2 | $responseArray = GeneralUtility::trimExplode(' ', $string, true); |
|
165 | 2 | $responseArray = array_values($responseArray); |
|
166 | 2 | return $responseArray; |
|
167 | } |
||
168 | |||
169 | /** |
||
170 | * Check if the process still exists |
||
171 | * |
||
172 | * @param int $pid Process id to be checked. |
||
173 | * |
||
174 | * @return bool |
||
175 | */ |
||
176 | private function doProcessStillExists($pid) |
||
193 | |||
194 | /** |
||
195 | * Kills a process |
||
196 | * |
||
197 | * @param int $pid Process id to kill |
||
198 | * |
||
199 | * @return void |
||
200 | */ |
||
201 | private function killProcess($pid) |
||
211 | |||
212 | /** |
||
213 | * Find dispatcher processes |
||
214 | * |
||
215 | * @return array |
||
216 | */ |
||
217 | private function findDispatcherProcesses() |
||
229 | |||
230 | /** |
||
231 | * Check if OS is Windows |
||
232 | * |
||
233 | * @return bool |
||
234 | */ |
||
235 | private function isOsWindows() |
||
242 | |||
243 | /** |
||
244 | * @return \TYPO3\CMS\Core\Database\DatabaseConnection |
||
245 | */ |
||
246 | 3 | private function getDatabaseConnection() |
|
250 | } |
||
251 |