1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace AOE\Crawler\Backend; |
6
|
|
|
|
7
|
|
|
/*************************************************************** |
8
|
|
|
* Copyright notice |
9
|
|
|
* |
10
|
|
|
* (c) 2020 AOE GmbH <[email protected]> |
11
|
|
|
* |
12
|
|
|
* All rights reserved |
13
|
|
|
* |
14
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
15
|
|
|
* free software; you can redistribute it and/or modify |
16
|
|
|
* it under the terms of the GNU General Public License as published by |
17
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
18
|
|
|
* (at your option) any later version. |
19
|
|
|
* |
20
|
|
|
* The GNU General Public License can be found at |
21
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
22
|
|
|
* |
23
|
|
|
* This script is distributed in the hope that it will be useful, |
24
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
25
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
26
|
|
|
* GNU General Public License for more details. |
27
|
|
|
* |
28
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
29
|
|
|
***************************************************************/ |
30
|
|
|
|
31
|
|
|
use AOE\Crawler\Backend\RequestForm\RequestFormFactory; |
32
|
|
|
use AOE\Crawler\Configuration\ExtensionConfigurationProvider; |
33
|
|
|
use AOE\Crawler\Controller\CrawlerController; |
34
|
|
|
use AOE\Crawler\Converter\JsonCompatibilityConverter; |
35
|
|
|
use AOE\Crawler\Domain\Repository\QueueRepository; |
36
|
|
|
use AOE\Crawler\Service\ProcessService; |
37
|
|
|
use AOE\Crawler\Value\CrawlAction; |
38
|
|
|
use TYPO3\CMS\Backend\Utility\BackendUtility; |
39
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
40
|
|
|
use TYPO3\CMS\Core\Database\Query\QueryBuilder; |
41
|
|
|
use TYPO3\CMS\Core\Imaging\IconFactory; |
42
|
|
|
use TYPO3\CMS\Core\Localization\LanguageService; |
43
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
44
|
|
|
use TYPO3\CMS\Extbase\Object\ObjectManager; |
45
|
|
|
use TYPO3\CMS\Fluid\View\StandaloneView; |
46
|
|
|
use TYPO3\CMS\Info\Controller\InfoModuleController; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Function for Info module, containing three main actions: |
50
|
|
|
* - List of all queued items |
51
|
|
|
* - Log functionality |
52
|
|
|
* - Process overview |
53
|
|
|
*/ |
54
|
|
|
class BackendModule |
55
|
|
|
{ |
56
|
|
|
/** |
57
|
|
|
* @var InfoModuleController Contains a reference to the parent calling object |
58
|
|
|
*/ |
59
|
|
|
protected $pObj; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* The current page ID |
63
|
|
|
* @var int |
64
|
|
|
*/ |
65
|
|
|
protected $id; |
66
|
|
|
|
67
|
|
|
// Internal, dynamic: |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @var array |
71
|
|
|
*/ |
72
|
|
|
protected $duplicateTrack = []; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @var bool |
76
|
|
|
*/ |
77
|
|
|
protected $downloadCrawlUrls = false; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @var int |
81
|
|
|
*/ |
82
|
|
|
protected $scheduledTime = 0; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @var array holds the selection of configuration from the configuration selector box |
86
|
|
|
*/ |
87
|
|
|
protected $incomingConfigurationSelection = []; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @var CrawlerController |
91
|
|
|
*/ |
92
|
|
|
protected $crawlerController; |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @var array |
96
|
|
|
*/ |
97
|
|
|
protected $CSVaccu = []; |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* If true the user requested a CSV export of the queue |
101
|
|
|
* |
102
|
|
|
* @var boolean |
103
|
|
|
*/ |
104
|
|
|
protected $CSVExport = false; |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @var array |
108
|
|
|
*/ |
109
|
|
|
protected $downloadUrls = []; |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Holds the configuration from ext_conf_template loaded by getExtensionConfiguration() |
113
|
|
|
* |
114
|
|
|
* @var array |
115
|
|
|
*/ |
116
|
|
|
protected $extensionSettings = []; |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Indicate that an flash message with an error is present. |
120
|
|
|
* |
121
|
|
|
* @var boolean |
122
|
|
|
*/ |
123
|
|
|
protected $isErrorDetected = false; |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @var ProcessService |
127
|
|
|
*/ |
128
|
|
|
protected $processManager; |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @var QueryBuilder |
132
|
|
|
*/ |
133
|
|
|
protected $queryBuilder; |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @var QueueRepository |
137
|
|
|
*/ |
138
|
|
|
protected $queueRepository; |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @var StandaloneView |
142
|
|
|
*/ |
143
|
|
|
protected $view; |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @var IconFactory |
147
|
|
|
*/ |
148
|
|
|
protected $iconFactory; |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @var JsonCompatibilityConverter |
152
|
|
|
*/ |
153
|
|
|
protected $jsonCompatibilityConverter; |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @var LanguageService |
157
|
|
|
*/ |
158
|
|
|
private $languageService; |
159
|
|
|
|
160
|
|
|
public function __construct() |
161
|
|
|
{ |
162
|
|
|
$this->languageService = $GLOBALS['LANG']; |
163
|
|
|
$objectManger = GeneralUtility::makeInstance(ObjectManager::class); |
164
|
|
|
$this->processManager = $objectManger->get(ProcessService::class); |
165
|
|
|
$this->queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_crawler_queue'); |
166
|
|
|
$this->queueRepository = $objectManger->get(QueueRepository::class); |
167
|
|
|
$this->initializeView(); |
168
|
|
|
$this->extensionSettings = GeneralUtility::makeInstance(ExtensionConfigurationProvider::class)->getExtensionConfiguration(); |
169
|
|
|
$this->iconFactory = GeneralUtility::makeInstance(IconFactory::class); |
170
|
|
|
$this->jsonCompatibilityConverter = GeneralUtility::makeInstance(JsonCompatibilityConverter::class); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Called by the InfoModuleController |
175
|
|
|
*/ |
176
|
|
|
public function init(InfoModuleController $pObj): void |
177
|
|
|
{ |
178
|
|
|
$this->pObj = $pObj; |
179
|
|
|
$this->id = (int) GeneralUtility::_GP('id'); |
180
|
|
|
// Setting MOD_MENU items as we need them for logging: |
181
|
|
|
$this->pObj->MOD_MENU = array_merge($this->pObj->MOD_MENU, $this->getModuleMenu()); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Additions to the function menu array |
186
|
|
|
* |
187
|
|
|
* @return array Menu array |
188
|
|
|
* @deprecated Using BackendModule->modMenu() is deprecated since 9.1.1 and will be removed in v11.x |
189
|
|
|
*/ |
190
|
1 |
|
public function modMenu(): array |
191
|
|
|
{ |
192
|
1 |
|
return $this->getModuleMenu(); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
public function main(): string |
196
|
|
|
{ |
197
|
|
|
if (empty($this->pObj->MOD_SETTINGS['processListMode'])) { |
198
|
|
|
$this->pObj->MOD_SETTINGS['processListMode'] = 'simple'; |
199
|
|
|
} |
200
|
|
|
$this->view->assign('currentPageId', $this->id); |
201
|
|
|
|
202
|
|
|
$selectedAction = new CrawlAction($this->pObj->MOD_SETTINGS['crawlaction'] ?? 'start'); |
203
|
|
|
|
204
|
|
|
// Type function menu: |
205
|
|
|
$actionDropdown = BackendUtility::getFuncMenu( |
206
|
|
|
$this->id, |
207
|
|
|
'SET[crawlaction]', |
208
|
|
|
$selectedAction, |
209
|
|
|
$this->pObj->MOD_MENU['crawlaction'] |
210
|
|
|
); |
211
|
|
|
|
212
|
|
|
$theOutput = '<h2>' . htmlspecialchars($this->getLanguageService()->getLL('title'), ENT_QUOTES | ENT_HTML5) . '</h2>' . $actionDropdown; |
213
|
|
|
$theOutput .= $this->renderForm($selectedAction); |
214
|
|
|
|
215
|
|
|
return $theOutput; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/***************************** |
219
|
|
|
* |
220
|
|
|
* General Helper Functions |
221
|
|
|
* |
222
|
|
|
*****************************/ |
223
|
|
|
|
224
|
|
|
private function initializeView(): void |
225
|
|
|
{ |
226
|
|
|
$view = GeneralUtility::makeInstance(StandaloneView::class); |
227
|
|
|
$view->setLayoutRootPaths(['EXT:crawler/Resources/Private/Layouts']); |
228
|
|
|
$view->setPartialRootPaths(['EXT:crawler/Resources/Private/Partials']); |
229
|
|
|
$view->setTemplateRootPaths(['EXT:crawler/Resources/Private/Templates/Backend']); |
230
|
|
|
$view->getRequest()->setControllerExtensionName('Crawler'); |
231
|
|
|
$this->view = $view; |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
public function getLanguageService(): LanguageService |
235
|
|
|
{ |
236
|
|
|
return $GLOBALS['LANG']; |
237
|
|
|
} |
238
|
|
|
|
239
|
1 |
|
private function getModuleMenu(): array |
240
|
|
|
{ |
241
|
|
|
return [ |
242
|
|
|
'depth' => [ |
243
|
1 |
|
0 => $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_0'), |
244
|
1 |
|
1 => $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_1'), |
245
|
1 |
|
2 => $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_2'), |
246
|
1 |
|
3 => $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_3'), |
247
|
1 |
|
4 => $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_4'), |
248
|
1 |
|
99 => $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_infi'), |
249
|
|
|
], |
250
|
|
|
'crawlaction' => [ |
251
|
1 |
|
'start' => $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.start'), |
252
|
1 |
|
'log' => $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.log'), |
253
|
1 |
|
'multiprocess' => $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.multiprocess'), |
254
|
|
|
], |
255
|
1 |
|
'log_resultLog' => '', |
256
|
1 |
|
'log_feVars' => '', |
257
|
1 |
|
'processListMode' => '', |
258
|
|
|
'log_display' => [ |
259
|
1 |
|
'all' => $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.all'), |
260
|
1 |
|
'pending' => $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.pending'), |
261
|
1 |
|
'finished' => $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.finished'), |
262
|
|
|
], |
263
|
|
|
'itemsPerPage' => [ |
264
|
1 |
|
'5' => $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.itemsPerPage.5'), |
265
|
1 |
|
'10' => $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.itemsPerPage.10'), |
266
|
1 |
|
'50' => $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.itemsPerPage.50'), |
267
|
1 |
|
'0' => $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.itemsPerPage.0'), |
268
|
|
|
], |
269
|
|
|
]; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
private function renderForm(CrawlAction $selectedAction): string |
273
|
|
|
{ |
274
|
|
|
$requestForm = RequestFormFactory::create($selectedAction, $this->view, $this->pObj); |
275
|
|
|
return $requestForm->render( |
276
|
|
|
$this->id, |
277
|
|
|
$this->pObj->MOD_SETTINGS['depth'], |
278
|
|
|
$this->pObj->MOD_MENU['depth'] |
279
|
|
|
); |
280
|
|
|
} |
281
|
|
|
} |
282
|
|
|
|