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\Site; |
||||
33 | use TYPO3\CMS\Core\Page\PageRenderer; |
||||
34 | use TYPO3\CMS\Core\Utility\GeneralUtility; |
||||
35 | use TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface; |
||||
0 ignored issues
–
show
|
|||||
36 | use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController; |
||||
0 ignored issues
–
show
The type
TYPO3\CMS\Scheduler\Cont...hedulerModuleController was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||
37 | use TYPO3\CMS\Scheduler\Task\AbstractTask; |
||||
0 ignored issues
–
show
The type
TYPO3\CMS\Scheduler\Task\AbstractTask was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||
38 | |||||
39 | /** |
||||
40 | * Adds an additional field to specify the Solr server to initialize the index queue for |
||||
41 | * |
||||
42 | * @author Christoph Moeller <[email protected]> |
||||
43 | */ |
||||
44 | class ReIndexTaskAdditionalFieldProvider implements AdditionalFieldProviderInterface |
||||
45 | { |
||||
46 | |||||
47 | /** |
||||
48 | * Task information |
||||
49 | * |
||||
50 | * @var array |
||||
51 | */ |
||||
52 | protected $taskInformation; |
||||
53 | |||||
54 | /** |
||||
55 | * Scheduler task |
||||
56 | * |
||||
57 | * @var AbstractTask|ReIndexTask|NULL |
||||
58 | */ |
||||
59 | protected $task = null; |
||||
60 | |||||
61 | /** |
||||
62 | * Scheduler Module |
||||
63 | * |
||||
64 | * @var SchedulerModuleController |
||||
65 | */ |
||||
66 | protected $schedulerModule; |
||||
67 | |||||
68 | /** |
||||
69 | * Selected site |
||||
70 | * |
||||
71 | * @var Site |
||||
72 | */ |
||||
73 | protected $site = null; |
||||
74 | /** |
||||
75 | * SiteRepository |
||||
76 | * |
||||
77 | * @var SiteRepository |
||||
78 | */ |
||||
79 | protected $siteRepository; |
||||
80 | |||||
81 | /** |
||||
82 | * @var PageRenderer |
||||
83 | */ |
||||
84 | protected $pageRenderer = null; |
||||
85 | |||||
86 | /** |
||||
87 | * ReIndexTaskAdditionalFieldProvider constructor. |
||||
88 | */ |
||||
89 | public function __construct() |
||||
90 | { |
||||
91 | $this->siteRepository = GeneralUtility::makeInstance(SiteRepository::class); |
||||
92 | } |
||||
93 | |||||
94 | /** |
||||
95 | * @param array $taskInfo |
||||
96 | * @param \TYPO3\CMS\Scheduler\Task\AbstractTask|NULL $task |
||||
97 | * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule |
||||
98 | */ |
||||
99 | protected function initialize( |
||||
100 | array $taskInfo = [], |
||||
101 | AbstractTask $task = null, |
||||
102 | SchedulerModuleController $schedulerModule |
||||
103 | ) { |
||||
104 | /** @var $task ReIndexTask */ |
||||
105 | $this->taskInformation = $taskInfo; |
||||
106 | $this->task = $task; |
||||
107 | $this->schedulerModule = $schedulerModule; |
||||
108 | |||||
109 | if ($schedulerModule->CMD === 'edit') { |
||||
110 | $this->site = $this->siteRepository->getSiteByRootPageId($task->getRootPageId()); |
||||
111 | } |
||||
112 | } |
||||
113 | |||||
114 | /** |
||||
115 | * Used to define fields to provide the Solr server address when adding |
||||
116 | * or editing a task. |
||||
117 | * |
||||
118 | * @param array $taskInfo reference to the array containing the info used in the add/edit form |
||||
119 | * @param AbstractTask $task when editing, reference to the current task object. Null when adding. |
||||
120 | * @param SchedulerModuleController $schedulerModule reference to the calling object (Scheduler's BE module) |
||||
121 | * @return array Array containing all the information pertaining to the additional fields |
||||
122 | * The array is multidimensional, keyed to the task class name and each field's id |
||||
123 | * For each field it provides an associative sub-array with the following: |
||||
124 | */ |
||||
125 | public function getAdditionalFields( |
||||
126 | array &$taskInfo, |
||||
127 | $task, |
||||
128 | SchedulerModuleController $schedulerModule |
||||
129 | ) { |
||||
130 | $additionalFields = []; |
||||
131 | |||||
132 | if (!$this->isTaskInstanceofReIndexTask($task)) { |
||||
133 | return $additionalFields; |
||||
134 | } |
||||
135 | |||||
136 | $this->initialize($taskInfo, $task, $schedulerModule); |
||||
137 | $siteSelectorField = GeneralUtility::makeInstance(SiteSelectorField::class); |
||||
138 | |||||
139 | $additionalFields['site'] = [ |
||||
140 | 'code' => $siteSelectorField->getAvailableSitesSelector('tx_scheduler[site]', |
||||
141 | $this->site), |
||||
142 | 'label' => 'LLL:EXT:solr/Resources/Private/Language/locallang.xlf:field_site', |
||||
143 | 'cshKey' => '', |
||||
144 | 'cshLabel' => '' |
||||
145 | ]; |
||||
146 | |||||
147 | $additionalFields['indexingConfigurations'] = [ |
||||
148 | 'code' => $this->getIndexingConfigurationSelector(), |
||||
149 | 'label' => 'Index Queue configurations to re-index', |
||||
150 | 'cshKey' => '', |
||||
151 | 'cshLabel' => '' |
||||
152 | ]; |
||||
153 | |||||
154 | return $additionalFields; |
||||
155 | } |
||||
156 | |||||
157 | protected function getIndexingConfigurationSelector() |
||||
158 | { |
||||
159 | $selectorMarkup = 'Please select a site first.'; |
||||
160 | $this->getPageRenderer()->addCssFile('../typo3conf/ext/solr/Resources/Css/Backend/indexingconfigurationselectorfield.css'); |
||||
161 | |||||
162 | if (is_null($this->site)) { |
||||
163 | return $selectorMarkup; |
||||
164 | } |
||||
165 | |||||
166 | $selectorField = GeneralUtility::makeInstance(IndexingConfigurationSelectorField::class, $this->site); |
||||
167 | |||||
168 | $selectorField->setFormElementName('tx_scheduler[indexingConfigurations]'); |
||||
169 | $selectorField->setSelectedValues($this->task->getIndexingConfigurationsToReIndex()); |
||||
0 ignored issues
–
show
The method
getIndexingConfigurationsToReIndex() does not exist on null .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
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. ![]() |
|||||
170 | |||||
171 | $selectorMarkup = $selectorField->render(); |
||||
172 | |||||
173 | return $selectorMarkup; |
||||
174 | } |
||||
175 | |||||
176 | /** |
||||
177 | * Checks any additional data that is relevant to this task. If the task |
||||
178 | * class is not relevant, the method is expected to return TRUE |
||||
179 | * |
||||
180 | * @param array $submittedData reference to the array containing the data submitted by the user |
||||
181 | * @param SchedulerModuleController $schedulerModule reference to the calling object (Scheduler's BE module) |
||||
182 | * @return bool True if validation was ok (or selected class is not relevant), FALSE otherwise |
||||
183 | */ |
||||
184 | public function validateAdditionalFields( |
||||
185 | array &$submittedData, |
||||
186 | SchedulerModuleController $schedulerModule |
||||
187 | ) { |
||||
188 | $result = false; |
||||
189 | |||||
190 | // validate site |
||||
191 | $sites = $this->siteRepository->getAvailableSites(); |
||||
192 | if (array_key_exists($submittedData['site'], $sites)) { |
||||
193 | $result = true; |
||||
194 | } |
||||
195 | |||||
196 | return $result; |
||||
197 | } |
||||
198 | |||||
199 | /** |
||||
200 | * Saves any additional input into the current task object if the task |
||||
201 | * class matches. |
||||
202 | * |
||||
203 | * @param array $submittedData array containing the data submitted by the user |
||||
204 | * @param AbstractTask $task reference to the current task object |
||||
205 | */ |
||||
206 | public function saveAdditionalFields( |
||||
207 | array $submittedData, |
||||
208 | AbstractTask $task |
||||
209 | ) { |
||||
210 | /** @var $task ReIndexTask */ |
||||
211 | if (!$this->isTaskInstanceofReIndexTask($task)) { |
||||
212 | return; |
||||
213 | } |
||||
214 | |||||
215 | $task->setRootPageId($submittedData['site']); |
||||
216 | |||||
217 | $indexingConfigurations = []; |
||||
218 | if (!empty($submittedData['indexingConfigurations'])) { |
||||
219 | $indexingConfigurations = $submittedData['indexingConfigurations']; |
||||
220 | } |
||||
221 | $task->setIndexingConfigurationsToReIndex($indexingConfigurations); |
||||
222 | } |
||||
223 | |||||
224 | /** |
||||
225 | * @return PageRenderer |
||||
226 | */ |
||||
227 | protected function getPageRenderer() |
||||
228 | { |
||||
229 | if (!isset($this->pageRenderer)) { |
||||
230 | $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
||||
231 | } |
||||
232 | return $this->pageRenderer; |
||||
233 | } |
||||
234 | |||||
235 | /** |
||||
236 | * Check that a task is an instance of ReIndexTask |
||||
237 | * |
||||
238 | * @param AbstractTask $task |
||||
239 | * @return boolean |
||||
240 | * @throws \LogicException |
||||
241 | */ |
||||
242 | protected function isTaskInstanceofReIndexTask($task) |
||||
243 | { |
||||
244 | if ((!is_null($task)) && (!($task instanceof ReIndexTask))) { |
||||
245 | throw new \LogicException( |
||||
246 | '$task must be an instance of ReIndexTask, ' |
||||
247 | . 'other instances are not supported.', 1487500366 |
||||
248 | ); |
||||
249 | } |
||||
250 | return true; |
||||
251 | } |
||||
252 | } |
||||
253 |
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