1
|
|
|
<?php |
2
|
|
|
namespace AOE\Crawler\Task; |
3
|
|
|
|
4
|
|
|
/*************************************************************** |
5
|
|
|
* Copyright notice |
6
|
|
|
* |
7
|
|
|
* (c) 2016 AOE GmbH <[email protected]> |
8
|
|
|
* |
9
|
|
|
* All rights reserved |
10
|
|
|
* |
11
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
12
|
|
|
* free software; you can redistribute it and/or modify |
13
|
|
|
* it under the terms of the GNU General Public License as published by |
14
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
15
|
|
|
* (at your option) any later version. |
16
|
|
|
* |
17
|
|
|
* The GNU General Public License can be found at |
18
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
19
|
|
|
* |
20
|
|
|
* This script is distributed in the hope that it will be useful, |
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23
|
|
|
* GNU General Public License for more details. |
24
|
|
|
* |
25
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
26
|
|
|
***************************************************************/ |
27
|
|
|
|
28
|
|
|
use TYPO3\CMS\Backend\Utility\BackendUtility; |
|
|
|
|
29
|
|
|
use TYPO3\CMS\Core\Messaging\FlashMessage; |
|
|
|
|
30
|
|
|
use TYPO3\CMS\Core\Utility\MathUtility; |
|
|
|
|
31
|
|
|
use TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface; |
|
|
|
|
32
|
|
|
use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController; |
|
|
|
|
33
|
|
|
use TYPO3\CMS\Scheduler\Task\AbstractTask; |
|
|
|
|
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Class CrawlerQueueTaskAdditionalFieldProvider |
37
|
|
|
* |
38
|
|
|
* @package AOE\Crawler\Task |
39
|
|
|
* @codeCoverageIgnore |
40
|
|
|
*/ |
41
|
|
|
class CrawlerQueueTaskAdditionalFieldProvider implements AdditionalFieldProviderInterface |
42
|
|
|
{ |
43
|
|
|
/** |
44
|
|
|
* Gets additional fields to render in the form to add/edit a task |
45
|
|
|
* |
46
|
|
|
* @param array $taskInfo |
47
|
|
|
* @param AbstractTask $task |
48
|
|
|
* @param SchedulerModuleController $schedulerModule |
49
|
|
|
* |
50
|
|
|
* @return array |
51
|
|
|
*/ |
52
|
|
|
public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule) |
53
|
|
|
{ |
54
|
|
|
$additionalFields = []; |
55
|
|
|
|
56
|
|
|
if (empty($taskInfo['configuration'])) { |
57
|
|
|
if ($schedulerModule->CMD == 'add') { |
58
|
|
|
$taskInfo['configuration'] = []; |
59
|
|
|
} elseif ($schedulerModule->CMD == 'edit') { |
60
|
|
|
$taskInfo['configuration'] = $task->configuration; |
61
|
|
|
} else { |
62
|
|
|
$taskInfo['configuration'] = $task->configuration; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
if (empty($taskInfo['startPage'])) { |
67
|
|
|
if ($schedulerModule->CMD == 'add') { |
68
|
|
|
$taskInfo['startPage'] = 0; |
69
|
|
|
if ($task instanceof \TYPO3\CMS\Scheduler\Task\AbstractTask) { |
70
|
|
|
$task->startPage = 0; |
71
|
|
|
} |
72
|
|
|
} elseif ($schedulerModule->CMD == 'edit') { |
73
|
|
|
$taskInfo['startPage'] = $task->startPage; |
74
|
|
|
} else { |
75
|
|
|
$taskInfo['startPage'] = $task->startPage; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
if (empty($taskInfo['depth'])) { |
80
|
|
|
if ($schedulerModule->CMD == 'add') { |
81
|
|
|
$taskInfo['depth'] = []; |
82
|
|
|
} elseif ($schedulerModule->CMD == 'edit') { |
83
|
|
|
$taskInfo['depth'] = $task->depth; |
84
|
|
|
} else { |
85
|
|
|
$taskInfo['depth'] = $task->depth; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
// input for startPage |
90
|
|
|
$fieldId = 'task_startPage'; |
91
|
|
|
$fieldCode = '<input name="tx_scheduler[startPage]" type="text" id="' . $fieldId . '" value="' . $task->startPage . '" class="form-control" />'; |
92
|
|
|
$additionalFields[$fieldId] = [ |
93
|
|
|
'code' => $fieldCode, |
94
|
|
|
'label' => 'LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:crawler_im.startPage' |
95
|
|
|
]; |
96
|
|
|
|
97
|
|
|
// input for depth |
98
|
|
|
$fieldId = 'task_depth'; |
99
|
|
|
$fieldValueArray = [ |
100
|
|
|
'0' => $GLOBALS['LANG']->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_0'), |
101
|
|
|
'1' => $GLOBALS['LANG']->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_1'), |
102
|
|
|
'2' => $GLOBALS['LANG']->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_2'), |
103
|
|
|
'3' => $GLOBALS['LANG']->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_3'), |
104
|
|
|
'4' => $GLOBALS['LANG']->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_4'), |
105
|
|
|
'99' => $GLOBALS['LANG']->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_infi'), |
106
|
|
|
]; |
107
|
|
|
$fieldCode = '<select name="tx_scheduler[depth]" id="' . $fieldId . '" class="form-control">'; |
108
|
|
|
|
109
|
|
|
foreach ($fieldValueArray as $key => $label) { |
110
|
|
|
$fieldCode .= "\t" . '<option value="' . $key . '"' . (($key == $task->depth) ? ' selected="selected"' : '') . '>' . $label . '</option>'; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
$fieldCode .= '</select>'; |
114
|
|
|
$additionalFields[$fieldId] = [ |
115
|
|
|
'code' => $fieldCode, |
116
|
|
|
'label' => 'LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:crawler_im.depth' |
117
|
|
|
]; |
118
|
|
|
|
119
|
|
|
// combobox for configuration records |
120
|
|
|
$recordsArray = $this->getCrawlerConfigurationRecords(); |
121
|
|
|
$fieldId = 'task_configuration'; |
122
|
|
|
$fieldCode = '<select name="tx_scheduler[configuration][]" multiple="multiple" id="' . $fieldId . '" class="form-control">'; |
123
|
|
|
$fieldCode .= "\t" . '<option value=""></option>'; |
124
|
|
|
for ($i = 0; $i < count($recordsArray); $i++) { |
|
|
|
|
125
|
|
|
$fieldCode .= "\t" . '<option ' . $this->getSelectedState($task->configuration, $recordsArray[$i]['name']) . 'value="' . $recordsArray[$i]['name'] . '">' . $recordsArray[$i]['name'] . '</option>'; |
126
|
|
|
} |
127
|
|
|
$fieldCode .= '</select>'; |
128
|
|
|
|
129
|
|
|
$additionalFields[$fieldId] = [ |
130
|
|
|
'code' => $fieldCode, |
131
|
|
|
'label' => 'LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:crawler_im.conf' |
132
|
|
|
]; |
133
|
|
|
|
134
|
|
|
return $additionalFields; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Mark current value as selected by returning the "selected" attribute |
139
|
|
|
* |
140
|
|
|
* @param $configurationArray |
141
|
|
|
* @param $currentValue |
142
|
|
|
* |
143
|
|
|
* @return string |
144
|
|
|
*/ |
145
|
|
|
protected function getSelectedState($configurationArray, $currentValue) |
146
|
|
|
{ |
147
|
|
|
$selected = ''; |
148
|
|
|
for ($i = 0; $i < count($configurationArray); $i++) { |
|
|
|
|
149
|
|
|
if (strcmp($configurationArray[$i], $currentValue) === 0) { |
150
|
|
|
$selected = 'selected="selected" '; |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
return $selected; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Get all available configuration records. |
159
|
|
|
* |
160
|
|
|
* @return array which contains the available configuration records. |
161
|
|
|
*/ |
162
|
|
|
protected function getCrawlerConfigurationRecords() |
163
|
|
|
{ |
164
|
|
|
$records = []; |
165
|
|
|
$result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
166
|
|
|
'*', |
167
|
|
|
'tx_crawler_configuration', |
168
|
|
|
'1=1' . BackendUtility::deleteClause('tx_crawler_configuration') |
169
|
|
|
); |
170
|
|
|
|
171
|
|
|
while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) { |
172
|
|
|
$records[] = $row; |
173
|
|
|
} |
174
|
|
|
$GLOBALS['TYPO3_DB']->sql_free_result($result); |
175
|
|
|
|
176
|
|
|
return $records; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Validates the additional fields' values |
181
|
|
|
* |
182
|
|
|
* @param array $submittedData |
183
|
|
|
* @param SchedulerModuleController $schedulerModule |
184
|
|
|
* @return bool |
185
|
|
|
*/ |
186
|
|
|
public function validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule) |
187
|
|
|
{ |
188
|
|
|
$isValid = false; |
189
|
|
|
|
190
|
|
|
//!TODO add validation to validate the $submittedData['configuration'] which is normally a comma separated string |
191
|
|
|
if (is_array($submittedData['configuration'])) { |
192
|
|
|
$isValid = true; |
193
|
|
|
} else { |
194
|
|
|
$schedulerModule->addMessage($GLOBALS['LANG']->sL('LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:crawler_im.invalidConfiguration'), FlashMessage::ERROR); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
if ($submittedData['depth'] < 0) { |
198
|
|
|
$isValid = false; |
199
|
|
|
$schedulerModule->addMessage($GLOBALS['LANG']->sL('LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:crawler_im.invalidDepth'), FlashMessage::ERROR); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
if (!MathUtility::canBeInterpretedAsInteger($submittedData['startPage']) || $submittedData['startPage'] < 0) { |
203
|
|
|
$isValid = false; |
204
|
|
|
$schedulerModule->addMessage($GLOBALS['LANG']->sL('LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:crawler_im.invalidStartPage'), FlashMessage::ERROR); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
return $isValid; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Takes care of saving the additional fields' values in the task's object |
212
|
|
|
* |
213
|
|
|
* @param array $submittedData |
214
|
|
|
* @param AbstractTask $task |
215
|
|
|
* @return void |
216
|
|
|
*/ |
217
|
|
|
public function saveAdditionalFields(array $submittedData, AbstractTask $task) |
218
|
|
|
{ |
219
|
|
|
$task->depth = intval($submittedData['depth']); |
220
|
|
|
$task->configuration = $submittedData['configuration']; |
221
|
|
|
$task->startPage = intval($submittedData['startPage']); |
222
|
|
|
} |
223
|
|
|
} |
224
|
|
|
|
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