Failed Conditions
Pull Request — release-11.2.x (#3154)
by Markus
64:06 queued 19:01
created

EventQueueWorkerTaskAdditionalFieldProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 16
dl 0
loc 69
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getAdditionalFields() 0 24 3
A validateAdditionalFields() 0 9 1
A saveAdditionalFields() 0 5 1
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) {
0 ignored issues
show
introduced by
$task is always a sub-type of ApacheSolrForTypo3\Solr\Task\EventQueueWorkerTask.
Loading history...
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
        $task->setLimit($submittedData['solr_eventqueueworkertask_limit']);
0 ignored issues
show
Bug introduced by
The method setLimit() does not exist on TYPO3\CMS\Scheduler\Task\AbstractTask. It seems like you code against a sub-type of TYPO3\CMS\Scheduler\Task\AbstractTask such as ApacheSolrForTypo3\Solr\Task\EventQueueWorkerTask. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

106
        $task->/** @scrutinizer ignore-call */ 
107
               setLimit($submittedData['solr_eventqueueworkertask_limit']);
Loading history...
107
    }
108
}
109