1 | <?php |
||||
2 | namespace ApacheSolrForTypo3\Solr\Task; |
||||
3 | |||||
4 | /*************************************************************** |
||||
5 | * Copyright notice |
||||
6 | * |
||||
7 | * (c) 2011-2015 Christoph Moeller <[email protected]> |
||||
8 | * (c) 2012-2015 Ingo Renner <[email protected]> |
||||
9 | * |
||||
10 | * All rights reserved |
||||
11 | * |
||||
12 | * This script is part of the TYPO3 project. The TYPO3 project is |
||||
13 | * free software; you can redistribute it and/or modify |
||||
14 | * it under the terms of the GNU General Public License as published by |
||||
15 | * the Free Software Foundation; either version 3 of the License, or |
||||
16 | * (at your option) any later version. |
||||
17 | * |
||||
18 | * The GNU General Public License can be found at |
||||
19 | * http://www.gnu.org/copyleft/gpl.html. |
||||
20 | * |
||||
21 | * This script is distributed in the hope that it will be useful, |
||||
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
24 | * GNU General Public License for more details. |
||||
25 | * |
||||
26 | * This copyright notice MUST APPEAR in all copies of the script! |
||||
27 | ***************************************************************/ |
||||
28 | |||||
29 | use ApacheSolrForTypo3\Solr\Backend\IndexingConfigurationSelectorField; |
||||
30 | use ApacheSolrForTypo3\Solr\Backend\SiteSelectorField; |
||||
31 | use ApacheSolrForTypo3\Solr\Domain\Site\SiteRepository; |
||||
32 | use ApacheSolrForTypo3\Solr\Domain\Site\Site; |
||||
33 | use TYPO3\CMS\Core\Page\PageRenderer; |
||||
34 | use TYPO3\CMS\Core\Utility\GeneralUtility; |
||||
35 | use TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface; |
||||
36 | use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController; |
||||
37 | use TYPO3\CMS\Scheduler\Task\AbstractTask; |
||||
38 | use TYPO3\CMS\Scheduler\Task\Enumeration\Action; |
||||
39 | |||||
40 | /** |
||||
41 | * Adds an additional field to specify the Solr server to initialize the index queue for |
||||
42 | * |
||||
43 | * @author Christoph Moeller <[email protected]> |
||||
44 | */ |
||||
45 | class ReIndexTaskAdditionalFieldProvider implements AdditionalFieldProviderInterface |
||||
46 | { |
||||
47 | |||||
48 | /** |
||||
49 | * Task information |
||||
50 | * |
||||
51 | * @var array |
||||
52 | */ |
||||
53 | protected $taskInformation; |
||||
54 | |||||
55 | /** |
||||
56 | * Scheduler task |
||||
57 | * |
||||
58 | * @var AbstractTask|ReIndexTask|NULL |
||||
59 | */ |
||||
60 | protected $task = null; |
||||
61 | |||||
62 | /** |
||||
63 | * Scheduler Module |
||||
64 | * |
||||
65 | * @var SchedulerModuleController |
||||
66 | */ |
||||
67 | protected $schedulerModule; |
||||
68 | |||||
69 | /** |
||||
70 | * Selected site |
||||
71 | * |
||||
72 | * @var Site |
||||
73 | */ |
||||
74 | protected $site = null; |
||||
75 | /** |
||||
76 | * SiteRepository |
||||
77 | * |
||||
78 | * @var SiteRepository |
||||
79 | */ |
||||
80 | protected $siteRepository; |
||||
81 | |||||
82 | /** |
||||
83 | * @var PageRenderer |
||||
84 | */ |
||||
85 | protected $pageRenderer = null; |
||||
86 | |||||
87 | /** |
||||
88 | * ReIndexTaskAdditionalFieldProvider constructor. |
||||
89 | */ |
||||
90 | public function __construct() |
||||
91 | { |
||||
92 | $this->siteRepository = GeneralUtility::makeInstance(SiteRepository::class); |
||||
93 | } |
||||
94 | |||||
95 | /** |
||||
96 | * @param array $taskInfo |
||||
97 | * @param \TYPO3\CMS\Scheduler\Task\AbstractTask|NULL $task |
||||
98 | * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule |
||||
99 | */ |
||||
100 | protected function initialize( |
||||
101 | array $taskInfo = [], |
||||
102 | AbstractTask $task = null, |
||||
103 | SchedulerModuleController $schedulerModule |
||||
104 | ) { |
||||
105 | /** @var $task ReIndexTask */ |
||||
106 | $this->taskInformation = $taskInfo; |
||||
107 | $this->task = $task; |
||||
108 | $this->schedulerModule = $schedulerModule; |
||||
109 | |||||
110 | $currentAction = $schedulerModule->getCurrentAction(); |
||||
111 | |||||
112 | if ($currentAction->equals(Action::EDIT)) { |
||||
113 | $this->site = $this->siteRepository->getSiteByRootPageId($task->getRootPageId()); |
||||
114 | } |
||||
115 | } |
||||
116 | |||||
117 | /** |
||||
118 | * Used to define fields to provide the Solr server address when adding |
||||
119 | * or editing a task. |
||||
120 | * |
||||
121 | * @param array $taskInfo reference to the array containing the info used in the add/edit form |
||||
122 | * @param AbstractTask $task when editing, reference to the current task object. Null when adding. |
||||
123 | * @param SchedulerModuleController $schedulerModule reference to the calling object (Scheduler's BE module) |
||||
124 | * @return array Array containing all the information pertaining to the additional fields |
||||
125 | * The array is multidimensional, keyed to the task class name and each field's id |
||||
126 | * For each field it provides an associative sub-array with the following: |
||||
127 | */ |
||||
128 | public function getAdditionalFields( |
||||
129 | array &$taskInfo, |
||||
130 | $task, |
||||
131 | SchedulerModuleController $schedulerModule |
||||
132 | ) { |
||||
133 | $additionalFields = []; |
||||
134 | |||||
135 | if (!$this->isTaskInstanceofReIndexTask($task)) { |
||||
136 | return $additionalFields; |
||||
137 | } |
||||
138 | |||||
139 | $this->initialize($taskInfo, $task, $schedulerModule); |
||||
140 | $siteSelectorField = GeneralUtility::makeInstance(SiteSelectorField::class); |
||||
141 | |||||
142 | $additionalFields['site'] = [ |
||||
143 | 'code' => $siteSelectorField->getAvailableSitesSelector('tx_scheduler[site]', |
||||
144 | $this->site), |
||||
145 | 'label' => 'LLL:EXT:solr/Resources/Private/Language/locallang.xlf:field_site', |
||||
146 | 'cshKey' => '', |
||||
147 | 'cshLabel' => '' |
||||
148 | ]; |
||||
149 | |||||
150 | $additionalFields['indexingConfigurations'] = [ |
||||
151 | 'code' => $this->getIndexingConfigurationSelector(), |
||||
152 | 'label' => 'Index Queue configurations to re-index', |
||||
153 | 'cshKey' => '', |
||||
154 | 'cshLabel' => '' |
||||
155 | ]; |
||||
156 | |||||
157 | return $additionalFields; |
||||
158 | } |
||||
159 | |||||
160 | protected function getIndexingConfigurationSelector() |
||||
161 | { |
||||
162 | $selectorMarkup = 'Please select a site first.'; |
||||
163 | $this->getPageRenderer()->addCssFile('../typo3conf/ext/solr/Resources/Css/Backend/indexingconfigurationselectorfield.css'); |
||||
164 | |||||
165 | if (is_null($this->site)) { |
||||
166 | return $selectorMarkup; |
||||
167 | } |
||||
168 | |||||
169 | $selectorField = GeneralUtility::makeInstance(IndexingConfigurationSelectorField::class, /** @scrutinizer ignore-type */ $this->site); |
||||
170 | |||||
171 | $selectorField->setFormElementName('tx_scheduler[indexingConfigurations]'); |
||||
172 | $selectorField->setSelectedValues($this->task->getIndexingConfigurationsToReIndex()); |
||||
0 ignored issues
–
show
The method
getIndexingConfigurationsToReIndex() 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\ReIndexTask .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
173 | |||||
174 | $selectorMarkup = $selectorField->render(); |
||||
175 | |||||
176 | return $selectorMarkup; |
||||
177 | } |
||||
178 | |||||
179 | /** |
||||
180 | * Checks any additional data that is relevant to this task. If the task |
||||
181 | * class is not relevant, the method is expected to return TRUE |
||||
182 | * |
||||
183 | * @param array $submittedData reference to the array containing the data submitted by the user |
||||
184 | * @param SchedulerModuleController $schedulerModule reference to the calling object (Scheduler's BE module) |
||||
185 | * @return bool True if validation was ok (or selected class is not relevant), FALSE otherwise |
||||
186 | */ |
||||
187 | public function validateAdditionalFields( |
||||
188 | array &$submittedData, |
||||
189 | SchedulerModuleController $schedulerModule |
||||
190 | ) { |
||||
191 | $result = false; |
||||
192 | |||||
193 | // validate site |
||||
194 | $sites = $this->siteRepository->getAvailableSites(); |
||||
195 | if (array_key_exists($submittedData['site'], $sites)) { |
||||
196 | $result = true; |
||||
197 | } |
||||
198 | |||||
199 | return $result; |
||||
200 | } |
||||
201 | |||||
202 | /** |
||||
203 | * Saves any additional input into the current task object if the task |
||||
204 | * class matches. |
||||
205 | * |
||||
206 | * @param array $submittedData array containing the data submitted by the user |
||||
207 | * @param AbstractTask $task reference to the current task object |
||||
208 | */ |
||||
209 | public function saveAdditionalFields( |
||||
210 | array $submittedData, |
||||
211 | AbstractTask $task |
||||
212 | ) { |
||||
213 | /** @var $task ReIndexTask */ |
||||
214 | if (!$this->isTaskInstanceofReIndexTask($task)) { |
||||
215 | return; |
||||
216 | } |
||||
217 | |||||
218 | $task->setRootPageId($submittedData['site']); |
||||
219 | |||||
220 | $indexingConfigurations = []; |
||||
221 | if (!empty($submittedData['indexingConfigurations'])) { |
||||
222 | $indexingConfigurations = $submittedData['indexingConfigurations']; |
||||
223 | } |
||||
224 | $task->setIndexingConfigurationsToReIndex($indexingConfigurations); |
||||
225 | } |
||||
226 | |||||
227 | /** |
||||
228 | * @return PageRenderer |
||||
229 | */ |
||||
230 | protected function getPageRenderer() |
||||
231 | { |
||||
232 | if (!isset($this->pageRenderer)) { |
||||
233 | $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
||||
234 | } |
||||
235 | return $this->pageRenderer; |
||||
236 | } |
||||
237 | |||||
238 | /** |
||||
239 | * Check that a task is an instance of ReIndexTask |
||||
240 | * |
||||
241 | * @param AbstractTask $task |
||||
242 | * @return boolean |
||||
243 | * @throws \LogicException |
||||
244 | */ |
||||
245 | protected function isTaskInstanceofReIndexTask($task) |
||||
246 | { |
||||
247 | if ((!is_null($task)) && (!($task instanceof ReIndexTask))) { |
||||
248 | throw new \LogicException( |
||||
249 | '$task must be an instance of ReIndexTask, ' |
||||
250 | . 'other instances are not supported.', 1487500366 |
||||
251 | ); |
||||
252 | } |
||||
253 | return true; |
||||
254 | } |
||||
255 | } |
||||
256 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.