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\Core\Messaging\FlashMessage; |
|
|
|
|
29
|
|
|
use TYPO3\CMS\Core\Utility\MathUtility; |
|
|
|
|
30
|
|
|
use TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface; |
|
|
|
|
31
|
|
|
use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController; |
|
|
|
|
32
|
|
|
use TYPO3\CMS\Scheduler\Task\AbstractTask; |
|
|
|
|
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Class CrawlerTaskAdditionalFieldProvider |
36
|
|
|
* |
37
|
|
|
* @package AOE\Crawler\Task |
38
|
|
|
* @codeCoverageIgnore |
39
|
|
|
*/ |
40
|
|
|
class CrawlerTaskAdditionalFieldProvider implements AdditionalFieldProviderInterface |
41
|
|
|
{ |
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
|
|
|
* @return array |
50
|
|
|
*/ |
51
|
|
|
public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule) |
52
|
|
|
{ |
53
|
|
|
$additionalFields = []; |
54
|
|
|
|
55
|
|
|
if (empty($taskInfo['sleepTime'])) { |
56
|
|
|
if ($schedulerModule->CMD == 'add') { |
57
|
|
|
$taskInfo['sleepTime'] = 1000; |
58
|
|
|
} elseif ($schedulerModule->CMD == 'edit') { |
59
|
|
|
$taskInfo['sleepTime'] = $task->sleepTime; |
60
|
|
|
} else { |
61
|
|
|
$taskInfo['sleepTime'] = $task->sleepTime; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
if (empty($taskInfo['sleepAfterFinish'])) { |
66
|
|
|
if ($schedulerModule->CMD == 'add') { |
67
|
|
|
$taskInfo['sleepAfterFinish'] = 10; |
68
|
|
|
} elseif ($schedulerModule->CMD == 'edit') { |
69
|
|
|
$taskInfo['sleepAfterFinish'] = $task->sleepAfterFinish; |
70
|
|
|
} else { |
71
|
|
|
$taskInfo['sleepAfterFinish'] = $task->sleepAfterFinish; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
if (empty($taskInfo['countInARun'])) { |
75
|
|
|
if ($schedulerModule->CMD == 'add') { |
76
|
|
|
$taskInfo['countInARun'] = 100; |
77
|
|
|
} elseif ($schedulerModule->CMD == 'edit') { |
78
|
|
|
$taskInfo['countInARun'] = $task->countInARun; |
79
|
|
|
} else { |
80
|
|
|
$taskInfo['countInARun'] = $task->countInARun; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
// input for sleepTime |
85
|
|
|
$fieldId = 'task_sleepTime'; |
86
|
|
|
$fieldCode = '<input type="text" name="tx_scheduler[sleepTime]" id="' . $fieldId . '" value="' . htmlentities($taskInfo['sleepTime']) . '" class="form-control" />'; |
87
|
|
|
$additionalFields[$fieldId] = [ |
88
|
|
|
'code' => $fieldCode, |
89
|
|
|
'label' => 'LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:crawler_im.sleepTime' |
90
|
|
|
]; |
91
|
|
|
// input for sleepAfterFinish |
92
|
|
|
$fieldId = 'task_sleepAfterFinish'; |
93
|
|
|
$fieldCode = '<input type="text" name="tx_scheduler[sleepAfterFinish]" id="' . $fieldId . '" value="' . htmlentities($taskInfo['sleepAfterFinish']) . '" class="form-control" />'; |
94
|
|
|
$additionalFields[$fieldId] = [ |
95
|
|
|
'code' => $fieldCode, |
96
|
|
|
'label' => 'LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:crawler_im.sleepAfterFinish' |
97
|
|
|
]; |
98
|
|
|
// input for countInARun |
99
|
|
|
$fieldId = 'task_countInARun'; |
100
|
|
|
$fieldCode = '<input type="text" name="tx_scheduler[countInARun]" id="' . $fieldId . '" value="' . htmlentities($taskInfo['countInARun']) . '" class="form-control" />'; |
101
|
|
|
$additionalFields[$fieldId] = [ |
102
|
|
|
'code' => $fieldCode, |
103
|
|
|
'label' => 'LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:crawler_im.countInARun' |
104
|
|
|
]; |
105
|
|
|
|
106
|
|
|
return $additionalFields; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Validates the additional fields' values |
111
|
|
|
* |
112
|
|
|
* @param array $submittedData |
113
|
|
|
* @param SchedulerModuleController $schedulerModule |
114
|
|
|
* @return bool |
115
|
|
|
*/ |
116
|
|
|
public function validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule) |
117
|
|
|
{ |
118
|
|
|
$isValid = false; |
119
|
|
|
|
120
|
|
|
if (MathUtility::convertToPositiveInteger($submittedData['sleepTime']) > 0) { |
121
|
|
|
$isValid = true; |
122
|
|
|
} else { |
123
|
|
|
$schedulerModule->addMessage($GLOBALS['LANG']->sL('LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:crawler_im.invalidSleepTime'), FlashMessage::ERROR); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
if (MathUtility::convertToPositiveInteger($submittedData['sleepAfterFinish']) === 0) { |
127
|
|
|
$isValid = false; |
128
|
|
|
$schedulerModule->addMessage($GLOBALS['LANG']->sL('LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:crawler_im.invalidSleepAfterFinish'), FlashMessage::ERROR); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
if (MathUtility::convertToPositiveInteger($submittedData['countInARun']) === 0) { |
132
|
|
|
$isValid = false; |
133
|
|
|
$schedulerModule->addMessage($GLOBALS['LANG']->sL('LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:crawler_im.invalidCountInARun'), FlashMessage::ERROR); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
return $isValid; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Takes care of saving the additional fields' values in the task's object |
141
|
|
|
* |
142
|
|
|
* @param array $submittedData |
143
|
|
|
* @param AbstractTask $task |
144
|
|
|
* @return void |
145
|
|
|
*/ |
146
|
|
|
public function saveAdditionalFields(array $submittedData, AbstractTask $task) |
147
|
|
|
{ |
148
|
|
|
$task->sleepTime = intval($submittedData['sleepTime']); |
149
|
|
|
$task->sleepAfterFinish = intval($submittedData['sleepAfterFinish']); |
150
|
|
|
$task->countInARun = intval($submittedData['countInARun']); |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|
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