|
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\Domain\Repository\QueueRepository; |
|
34
|
|
|
use AOE\Crawler\Service\ProcessService; |
|
35
|
|
|
use AOE\Crawler\Value\CrawlAction; |
|
36
|
|
|
use TYPO3\CMS\Backend\Utility\BackendUtility; |
|
37
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
|
38
|
|
|
use TYPO3\CMS\Core\Database\Query\QueryBuilder; |
|
39
|
|
|
use TYPO3\CMS\Core\Localization\LanguageService; |
|
40
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
41
|
|
|
use TYPO3\CMS\Extbase\Object\ObjectManager; |
|
42
|
|
|
use TYPO3\CMS\Fluid\View\StandaloneView; |
|
43
|
|
|
use TYPO3\CMS\Info\Controller\InfoModuleController; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Function for Info module, containing three main actions: |
|
47
|
|
|
* - List of all queued items |
|
48
|
|
|
* - Log functionality |
|
49
|
|
|
* - Process overview |
|
50
|
|
|
*/ |
|
51
|
|
|
class BackendModule |
|
52
|
|
|
{ |
|
53
|
|
|
/** |
|
54
|
|
|
* @var InfoModuleController Contains a reference to the parent calling object |
|
55
|
|
|
*/ |
|
56
|
|
|
protected $pObj; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* The current page ID |
|
60
|
|
|
* @var int |
|
61
|
|
|
*/ |
|
62
|
|
|
protected $id; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Holds the configuration from ext_conf_template loaded by getExtensionConfiguration() |
|
66
|
|
|
* |
|
67
|
|
|
* @var array |
|
68
|
|
|
*/ |
|
69
|
|
|
protected $extensionSettings = []; |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @var ProcessService |
|
73
|
|
|
*/ |
|
74
|
|
|
protected $processManager; |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @var QueryBuilder |
|
78
|
|
|
*/ |
|
79
|
|
|
protected $queryBuilder; |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @var QueueRepository |
|
83
|
|
|
*/ |
|
84
|
|
|
protected $queueRepository; |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @var StandaloneView |
|
88
|
|
|
*/ |
|
89
|
|
|
protected $view; |
|
90
|
|
|
|
|
91
|
|
|
public function __construct() |
|
92
|
|
|
{ |
|
93
|
|
|
$objectManger = GeneralUtility::makeInstance(ObjectManager::class); |
|
94
|
|
|
$this->processManager = $objectManger->get(ProcessService::class); |
|
95
|
|
|
$this->queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_crawler_queue'); |
|
96
|
|
|
$this->queueRepository = $objectManger->get(QueueRepository::class); |
|
97
|
|
|
$this->initializeView(); |
|
98
|
|
|
$this->extensionSettings = GeneralUtility::makeInstance(ExtensionConfigurationProvider::class)->getExtensionConfiguration(); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Called by the InfoModuleController |
|
103
|
|
|
*/ |
|
104
|
|
|
public function init(InfoModuleController $pObj): void |
|
105
|
|
|
{ |
|
106
|
|
|
$this->pObj = $pObj; |
|
107
|
|
|
$this->id = (int) GeneralUtility::_GP('id'); |
|
108
|
|
|
// Setting MOD_MENU items as we need them for logging: |
|
109
|
|
|
$this->pObj->MOD_MENU = array_merge($this->pObj->MOD_MENU, $this->getModuleMenu()); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Additions to the function menu array |
|
114
|
|
|
* |
|
115
|
|
|
* @return array Menu array |
|
116
|
|
|
* @deprecated Using BackendModule->modMenu() is deprecated since 9.1.3 and will be removed in v11.x |
|
117
|
|
|
*/ |
|
118
|
|
|
public function modMenu(): array |
|
119
|
|
|
{ |
|
120
|
|
|
return $this->getModuleMenu(); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
public function main(): string |
|
124
|
|
|
{ |
|
125
|
|
|
if (empty($this->pObj->MOD_SETTINGS['processListMode'])) { |
|
126
|
|
|
$this->pObj->MOD_SETTINGS['processListMode'] = 'simple'; |
|
127
|
|
|
} |
|
128
|
|
|
$this->view->assign('currentPageId', $this->id); |
|
129
|
|
|
|
|
130
|
|
|
$selectedAction = new CrawlAction($this->pObj->MOD_SETTINGS['crawlaction'] ?? 'start'); |
|
131
|
|
|
|
|
132
|
|
|
// Type function menu: |
|
133
|
|
|
$actionDropdown = BackendUtility::getFuncMenu( |
|
134
|
|
|
$this->id, |
|
135
|
|
|
'SET[crawlaction]', |
|
136
|
|
|
$selectedAction->__toString(), |
|
137
|
|
|
$this->pObj->MOD_MENU['crawlaction'] |
|
138
|
|
|
); |
|
139
|
|
|
|
|
140
|
|
|
$theOutput = '<h2>' . htmlspecialchars($this->getLanguageService()->getLL('title'), ENT_QUOTES | ENT_HTML5) . '</h2>' . $actionDropdown; |
|
141
|
|
|
|
|
142
|
|
|
return $theOutput . $this->renderForm($selectedAction); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
private function getLanguageService(): LanguageService |
|
146
|
|
|
{ |
|
147
|
|
|
return $GLOBALS['LANG']; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/***************************** |
|
151
|
|
|
* |
|
152
|
|
|
* General Helper Functions |
|
153
|
|
|
* |
|
154
|
|
|
*****************************/ |
|
155
|
|
|
|
|
156
|
|
|
private function initializeView(): void |
|
157
|
|
|
{ |
|
158
|
|
|
$view = GeneralUtility::makeInstance(StandaloneView::class); |
|
159
|
|
|
$view->setLayoutRootPaths(['EXT:crawler/Resources/Private/Layouts']); |
|
160
|
|
|
$view->setPartialRootPaths(['EXT:crawler/Resources/Private/Partials']); |
|
161
|
|
|
$view->setTemplateRootPaths(['EXT:crawler/Resources/Private/Templates/Backend']); |
|
162
|
|
|
$view->getRequest()->setControllerExtensionName('Crawler'); |
|
163
|
|
|
$this->view = $view; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
private function getModuleMenu(): array |
|
167
|
|
|
{ |
|
168
|
|
|
return [ |
|
169
|
|
|
'depth' => [ |
|
170
|
|
|
0 => $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_0'), |
|
171
|
|
|
1 => $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_1'), |
|
172
|
|
|
2 => $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_2'), |
|
173
|
|
|
3 => $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_3'), |
|
174
|
|
|
4 => $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_4'), |
|
175
|
|
|
99 => $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_infi'), |
|
176
|
|
|
], |
|
177
|
|
|
'crawlaction' => [ |
|
178
|
|
|
'start' => $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.start'), |
|
179
|
|
|
'log' => $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.log'), |
|
180
|
|
|
'multiprocess' => $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.multiprocess'), |
|
181
|
|
|
], |
|
182
|
|
|
'log_resultLog' => '', |
|
183
|
|
|
'log_feVars' => '', |
|
184
|
|
|
'processListMode' => '', |
|
185
|
|
|
'log_display' => [ |
|
186
|
|
|
'all' => $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.all'), |
|
187
|
|
|
'pending' => $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.pending'), |
|
188
|
|
|
'finished' => $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.finished'), |
|
189
|
|
|
], |
|
190
|
|
|
'itemsPerPage' => [ |
|
191
|
|
|
'5' => $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.itemsPerPage.5'), |
|
192
|
|
|
'10' => $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.itemsPerPage.10'), |
|
193
|
|
|
'50' => $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.itemsPerPage.50'), |
|
194
|
|
|
'0' => $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.itemsPerPage.0'), |
|
195
|
|
|
], |
|
196
|
|
|
]; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
private function renderForm(CrawlAction $selectedAction): string |
|
200
|
|
|
{ |
|
201
|
|
|
$requestForm = RequestFormFactory::create($selectedAction, $this->view, $this->pObj, $this->extensionSettings); |
|
202
|
|
|
return $requestForm->render( |
|
203
|
|
|
$this->id, |
|
204
|
|
|
$this->pObj->MOD_SETTINGS['depth'], |
|
205
|
|
|
$this->pObj->MOD_MENU['depth'] |
|
206
|
|
|
); |
|
207
|
|
|
} |
|
208
|
|
|
} |
|
209
|
|
|
|