1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace AOE\Crawler\Backend\RequestForm; |
5
|
|
|
|
6
|
|
|
use AOE\Crawler\Controller\CrawlerController; |
7
|
|
|
use AOE\Crawler\Csv\CsvWriter; |
|
|
|
|
8
|
|
|
use AOE\Crawler\Utility\MessageUtility; |
9
|
|
|
use TYPO3\CMS\Backend\Tree\View\PageTreeView; |
10
|
|
|
use TYPO3\CMS\Backend\Utility\BackendUtility; |
11
|
|
|
use TYPO3\CMS\Core\Imaging\Icon; |
12
|
|
|
use TYPO3\CMS\Core\Localization\LanguageService; |
13
|
|
|
use TYPO3\CMS\Core\Utility\DebugUtility; |
14
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
15
|
|
|
use TYPO3\CMS\Fluid\View\StandaloneView; |
16
|
|
|
|
17
|
|
|
final class LogRequestForm implements RequestForm |
18
|
|
|
{ |
19
|
|
|
/** @var StandaloneView */ |
20
|
|
|
private $view; |
21
|
|
|
|
22
|
|
|
public function __construct(StandaloneView $view) |
23
|
|
|
{ |
24
|
|
|
$this->view = $view; |
25
|
|
|
// TODO: Implement CSV Writer |
26
|
|
|
|
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function render($id, string $currentValue, array $menuItems): string |
30
|
|
|
{ |
31
|
|
|
$quiPart = GeneralUtility::_GP('qid_details') ? '&qid_details=' . (int)GeneralUtility::_GP('qid_details') : ''; |
32
|
|
|
$setId = (int)GeneralUtility::_GP('setID'); |
33
|
|
|
|
34
|
|
|
return $this->getDepthDropDownHtml($id, $currentValue, $menuItems) |
35
|
|
|
. $this->showLogAction($setId, $quiPart); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
private function getDepthDropDownHtml($id, string $currentValue, array $menuItems): string |
39
|
|
|
{ |
40
|
|
|
return BackendUtility::getFuncMenu( |
41
|
|
|
$id, |
42
|
|
|
'SET[depth]', |
43
|
|
|
$currentValue, |
44
|
|
|
$menuItems |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/******************************* |
49
|
|
|
* |
50
|
|
|
* Shows log of indexed URLs |
51
|
|
|
* |
52
|
|
|
******************************/ |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @throws \TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException |
56
|
|
|
*/ |
57
|
|
|
private function showLogAction(int $setId, string $quiPath): string |
58
|
|
|
{ |
59
|
|
|
$this->view->setTemplate('ShowLog'); |
60
|
|
|
if (empty($this->id)) { |
61
|
|
|
$this->isErrorDetected = true; |
|
|
|
|
62
|
|
|
MessageUtility::addErrorMessage($this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.noPageSelected')); |
63
|
|
|
} else { |
64
|
|
|
$this->crawlerController = GeneralUtility::makeInstance(CrawlerController::class); |
|
|
|
|
65
|
|
|
$this->crawlerController->setAccessMode('gui'); |
66
|
|
|
$this->crawlerController->setID = GeneralUtility::md5int(microtime()); |
67
|
|
|
|
68
|
|
|
$csvExport = GeneralUtility::_POST('_csv'); |
69
|
|
|
$this->CSVExport = isset($csvExport); |
|
|
|
|
70
|
|
|
|
71
|
|
|
// Read URL: |
72
|
|
|
if (GeneralUtility::_GP('qid_read')) { |
73
|
|
|
$this->crawlerController->readUrl((int) GeneralUtility::_GP('qid_read'), true); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
// Look for set ID sent - if it is, we will display contents of that set: |
77
|
|
|
$showSetId = (int) GeneralUtility::_GP('setID'); |
78
|
|
|
|
79
|
|
|
$queueId = GeneralUtility::_GP('qid_details'); |
80
|
|
|
$this->view->assign('queueId', $queueId); |
81
|
|
|
$this->view->assign('setId', $showSetId); |
82
|
|
|
// Show details: |
83
|
|
|
if ($queueId) { |
84
|
|
|
// Get entry record: |
85
|
|
|
$q_entry = $this->queryBuilder |
|
|
|
|
86
|
|
|
->from('tx_crawler_queue') |
87
|
|
|
->select('*') |
88
|
|
|
->where( |
89
|
|
|
$this->queryBuilder->expr()->eq('qid', $this->queryBuilder->createNamedParameter($queueId)) |
90
|
|
|
) |
91
|
|
|
->execute() |
92
|
|
|
->fetch(); |
93
|
|
|
|
94
|
|
|
// Explode values |
95
|
|
|
$q_entry['parameters'] = $this->jsonCompatibilityConverter->convert($q_entry['parameters']); |
|
|
|
|
96
|
|
|
$q_entry['result_data'] = $this->jsonCompatibilityConverter->convert($q_entry['result_data']); |
97
|
|
|
$resStatus = $this->getResStatus($q_entry['result_data']); |
|
|
|
|
98
|
|
|
if (is_array($q_entry['result_data'])) { |
99
|
|
|
$q_entry['result_data']['content'] = $this->jsonCompatibilityConverter->convert($q_entry['result_data']['content']); |
100
|
|
|
if (! $this->pObj->MOD_SETTINGS['log_resultLog']) { |
|
|
|
|
101
|
|
|
unset($q_entry['result_data']['content']['log']); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
$this->view->assign('queueStatus', $resStatus); |
106
|
|
|
$this->view->assign('queueDetails', DebugUtility::viewArray($q_entry)); |
107
|
|
|
} else { |
108
|
|
|
// Show list |
109
|
|
|
// Drawing tree: |
110
|
|
|
$tree = GeneralUtility::makeInstance(PageTreeView::class); |
111
|
|
|
$perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1); |
112
|
|
|
$tree->init('AND ' . $perms_clause); |
113
|
|
|
|
114
|
|
|
// Set root row: |
115
|
|
|
$pageinfo = BackendUtility::readPageAccess( |
116
|
|
|
$this->id, |
|
|
|
|
117
|
|
|
$perms_clause |
118
|
|
|
); |
119
|
|
|
$HTML = $this->iconFactory->getIconForRecord('pages', $pageinfo, Icon::SIZE_SMALL)->render(); |
|
|
|
|
120
|
|
|
$tree->tree[] = [ |
121
|
|
|
'row' => $pageinfo, |
122
|
|
|
'HTML' => $HTML, |
123
|
|
|
]; |
124
|
|
|
|
125
|
|
|
// Get branch beneath: |
126
|
|
|
if ($this->pObj->MOD_SETTINGS['depth']) { |
127
|
|
|
$tree->getTree($this->id, $this->pObj->MOD_SETTINGS['depth']); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
// If Flush button is pressed, flush tables instead of selecting entries: |
131
|
|
|
if (GeneralUtility::_POST('_flush')) { |
132
|
|
|
$doFlush = true; |
133
|
|
|
$doFullFlush = false; |
134
|
|
|
} elseif (GeneralUtility::_POST('_flush_all')) { |
135
|
|
|
$doFlush = true; |
136
|
|
|
$doFullFlush = true; |
137
|
|
|
} else { |
138
|
|
|
$doFlush = false; |
139
|
|
|
$doFullFlush = false; |
140
|
|
|
} |
141
|
|
|
$itemsPerPage = (int) $this->pObj->MOD_SETTINGS['itemsPerPage']; |
142
|
|
|
// Traverse page tree: |
143
|
|
|
$code = ''; |
144
|
|
|
$count = 0; |
145
|
|
|
foreach ($tree->tree as $data) { |
146
|
|
|
// Get result: |
147
|
|
|
$logEntriesOfPage = $this->crawlerController->getLogEntriesForPageId( |
148
|
|
|
(int) $data['row']['uid'], |
149
|
|
|
$this->pObj->MOD_SETTINGS['log_display'], |
150
|
|
|
$doFlush, |
151
|
|
|
$doFullFlush, |
152
|
|
|
$itemsPerPage |
153
|
|
|
); |
154
|
|
|
|
155
|
|
|
$code .= $this->drawLog_addRows( |
|
|
|
|
156
|
|
|
$logEntriesOfPage, |
157
|
|
|
$data['HTML'] . BackendUtility::getRecordTitle('pages', $data['row'], true) |
158
|
|
|
); |
159
|
|
|
if (++$count === 1000) { |
160
|
|
|
break; |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
$this->view->assign('code', $code); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
if ($this->CSVExport) { |
167
|
|
|
$this->outputCsvFile(); |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
$this->view->assign('showResultLog', (bool) $this->pObj->MOD_SETTINGS['log_resultLog']); |
171
|
|
|
$this->view->assign('showFeVars', (bool) $this->pObj->MOD_SETTINGS['log_feVars']); |
172
|
|
|
$this->view->assign('displayActions', 1); |
173
|
|
|
$this->view->assign('displayLogFilterHtml', $this->getDisplayLogFilterHtml($setId)); |
174
|
|
|
$this->view->assign('itemPerPageHtml', $this->getItemsPerPageDropDownHtml()); |
175
|
|
|
$this->view->assign('showResultLogHtml', $this->getShowResultLogCheckBoxHtml($setId, $quiPath)); |
176
|
|
|
$this->view->assign('showFeVarsHtml', $this->getShowFeVarsCheckBoxHtml($setId, $quiPath)); |
177
|
|
|
return $this->view->render(); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Outputs the CSV file and sets the correct headers |
182
|
|
|
*/ |
183
|
|
|
private function outputCsvFile(): void |
184
|
|
|
{ |
185
|
|
|
if (! count($this->CSVaccu)) { |
|
|
|
|
186
|
|
|
MessageUtility::addWarningMessage($this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:message.canNotExportEmptyQueueToCsvText')); |
187
|
|
|
return; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
$csvString = $this->csvWriter->arrayToCsv($this->CSVaccu); |
|
|
|
|
191
|
|
|
|
192
|
|
|
header('Content-Type: application/octet-stream'); |
193
|
|
|
header('Content-Disposition: attachment; filename=CrawlerLog.csv'); |
194
|
|
|
echo $csvString; |
195
|
|
|
|
196
|
|
|
exit; |
|
|
|
|
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @return LanguageService |
201
|
|
|
*/ |
202
|
|
|
private function getLanguageService(): LanguageService |
203
|
|
|
{ |
204
|
|
|
return $GLOBALS['LANG']; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
private function getDisplayLogFilterHtml(int $setId): string |
208
|
|
|
{ |
209
|
|
|
return $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.display') . ': ' . BackendUtility::getFuncMenu( |
210
|
|
|
$this->id, |
|
|
|
|
211
|
|
|
'SET[log_display]', |
212
|
|
|
$this->pObj->MOD_SETTINGS['log_display'], |
|
|
|
|
213
|
|
|
$this->pObj->MOD_MENU['log_display'], |
214
|
|
|
'index.php', |
215
|
|
|
'&setID=' . $setId |
216
|
|
|
); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
private function getItemsPerPageDropDownHtml(): string |
220
|
|
|
{ |
221
|
|
|
return $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.itemsPerPage') . ': ' . |
222
|
|
|
BackendUtility::getFuncMenu( |
223
|
|
|
$this->id, |
|
|
|
|
224
|
|
|
'SET[itemsPerPage]', |
225
|
|
|
$this->pObj->MOD_SETTINGS['itemsPerPage'], |
|
|
|
|
226
|
|
|
$this->pObj->MOD_MENU['itemsPerPage'] |
227
|
|
|
); |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
private function getShowResultLogCheckBoxHtml(int $setId, string $quiPart): string |
231
|
|
|
{ |
232
|
|
|
return BackendUtility::getFuncCheck( |
233
|
|
|
$this->id, |
|
|
|
|
234
|
|
|
'SET[log_resultLog]', |
235
|
|
|
$this->pObj->MOD_SETTINGS['log_resultLog'], |
|
|
|
|
236
|
|
|
'index.php', |
237
|
|
|
'&setID=' . $setId . $quiPart |
238
|
|
|
) . ' ' . $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.showresultlog'); |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
private function getShowFeVarsCheckBoxHtml(int $setId, string $quiPart): string |
242
|
|
|
{ |
243
|
|
|
return BackendUtility::getFuncCheck( |
244
|
|
|
$this->id, |
|
|
|
|
245
|
|
|
'SET[log_feVars]', |
246
|
|
|
$this->pObj->MOD_SETTINGS['log_feVars'], |
|
|
|
|
247
|
|
|
'index.php', |
248
|
|
|
'&setID=' . $setId . $quiPart |
249
|
|
|
) . ' ' . $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.showfevars'); |
250
|
|
|
} |
251
|
|
|
} |
252
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths