|
1
|
|
|
<?php |
|
2
|
|
|
namespace ApacheSolrForTypo3\Solr\Task; |
|
3
|
|
|
|
|
4
|
|
|
/*************************************************************** |
|
5
|
|
|
* Copyright notice |
|
6
|
|
|
* |
|
7
|
|
|
* (c) 2021 Markus Friedrich <[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\Scheduler\AdditionalFieldProviderInterface; |
|
29
|
|
|
use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController; |
|
30
|
|
|
use TYPO3\CMS\Scheduler\Task\AbstractTask; |
|
31
|
|
|
use TYPO3\CMS\Scheduler\Task\Enumeration\Action; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Additional field provider for the index queue worker task |
|
35
|
|
|
* |
|
36
|
|
|
* @author Markus Friedrich <[email protected]> |
|
37
|
|
|
*/ |
|
38
|
|
|
class EventQueueWorkerTaskAdditionalFieldProvider implements AdditionalFieldProviderInterface |
|
39
|
|
|
{ |
|
40
|
|
|
/** |
|
41
|
|
|
* Used to define fields to provide the TYPO3 site to index and number of |
|
42
|
|
|
* items to index per run when adding or editing a task. |
|
43
|
|
|
* |
|
44
|
|
|
* @param array $taskInfo reference to the array containing the info used in the add/edit form |
|
45
|
|
|
* @param AbstractTask $task when editing, reference to the current task object. Null when adding. |
|
46
|
|
|
* @param SchedulerModuleController $schedulerModule : reference to the calling object (Scheduler's BE module) |
|
47
|
|
|
* @return array Array containing all the information pertaining to the additional fields |
|
48
|
|
|
* The array is multidimensional, keyed to the task class name and each field's id |
|
49
|
|
|
* For each field it provides an associative sub-array with the following: |
|
50
|
|
|
*/ |
|
51
|
|
|
public function getAdditionalFields( |
|
52
|
|
|
array &$taskInfo, |
|
53
|
|
|
$task, |
|
54
|
|
|
SchedulerModuleController $schedulerModule |
|
55
|
|
|
): array { |
|
56
|
|
|
/** @var $task EventQueueWorkerTask */ |
|
57
|
|
|
$additionalFields = []; |
|
58
|
|
|
|
|
59
|
|
|
if (!$task instanceof EventQueueWorkerTask) { |
|
|
|
|
|
|
60
|
|
|
return $additionalFields; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
if ($schedulerModule->getCurrentAction()->equals(Action::EDIT)) { |
|
64
|
|
|
$taskInfo['solr_eventqueueworkertask_limit'] = $task->getLimit(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
$additionalFields['limit'] = [ |
|
68
|
|
|
'code' => '<input type="number" class="form-control" name="tx_scheduler[solr_eventqueueworkertask_limit]" value="' . (int)$taskInfo['solr_eventqueueworkertask_limit'] . '" />', |
|
69
|
|
|
'label' => 'LLL:EXT:solr/Resources/Private/Language/locallang_be.xlf:task.eventQueueWorkerTask.limit', |
|
70
|
|
|
'cshKey' => '', |
|
71
|
|
|
'cshLabel' => '' |
|
72
|
|
|
]; |
|
73
|
|
|
|
|
74
|
|
|
return $additionalFields; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Checks any additional data that is relevant to this task. If the task |
|
79
|
|
|
* class is not relevant, the method is expected to return TRUE |
|
80
|
|
|
* |
|
81
|
|
|
* @param array $submittedData reference to the array containing the data submitted by the user |
|
82
|
|
|
* @param SchedulerModuleController $schedulerModule reference to the calling object (Scheduler's BE module) |
|
83
|
|
|
* @return bool True if validation was ok (or selected class is not relevant), FALSE otherwise |
|
84
|
|
|
*/ |
|
85
|
|
|
public function validateAdditionalFields( |
|
86
|
|
|
array &$submittedData, |
|
87
|
|
|
SchedulerModuleController $schedulerModule |
|
88
|
|
|
): bool { |
|
89
|
|
|
$submittedData['solr_eventqueueworkertask_limit'] = max( |
|
90
|
|
|
(int)($submittedData['solr_eventqueueworkertask_limit'] ?? EventQueueWorkerTask::DEFAULT_PROCESSING_LIMIT), |
|
91
|
|
|
1 |
|
92
|
|
|
); |
|
93
|
|
|
return true; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Saves the custom limit |
|
98
|
|
|
* |
|
99
|
|
|
* @param array $submittedData array containing the data submitted by the user |
|
100
|
|
|
* @param AbstractTask $task reference to the current task object |
|
101
|
|
|
*/ |
|
102
|
|
|
public function saveAdditionalFields( |
|
103
|
|
|
array $submittedData, |
|
104
|
|
|
AbstractTask $task |
|
105
|
|
|
): void { |
|
106
|
|
|
if (!$task instanceof EventQueueWorkerTask) { |
|
107
|
|
|
return; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
$task->setLimit($submittedData['solr_eventqueueworkertask_limit']); |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|