‪TYPO3CMS  9.5
FileStorageExtractionAdditionalFieldProvider.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
24 
30 {
40  public function ‪getAdditionalFields(array &$taskInfo, $task, ‪SchedulerModuleController $parentObject)
41  {
42  if ($task !== null && !$task instanceof ‪FileStorageExtractionTask) {
43  throw new \InvalidArgumentException('Task not of type FileStorageExtractionTask', 1384275695);
44  }
45  $additionalFields['scheduler_fileStorageIndexing_storage'] = $this->‪getAllStoragesField($task);
46  $additionalFields['scheduler_fileStorageIndexing_fileCount'] = $this->‪getFileCountField($task);
47  $additionalFields['scheduler_fileStorageIndexing_registeredExtractors'] = $this->‪getRegisteredExtractorsField($task);
48  return $additionalFields;
49  }
50 
57  protected function ‪getAllStoragesField(‪FileStorageExtractionTask $task = null)
58  {
60  $storages = GeneralUtility::makeInstance(\‪TYPO3\CMS\Core\Resource\StorageRepository::class)->findAll();
61  $options = [];
62  foreach ($storages as $storage) {
63  if ($task !== null && $task->storageUid === $storage->getUid()) {
64  $options[] = '<option value="' . $storage->getUid() . '" selected="selected">' . $storage->getName() . '</option>';
65  } else {
66  $options[] = '<option value="' . $storage->getUid() . '">' . $storage->getName() . '</option>';
67  }
68  }
69 
70  $fieldName = 'tx_scheduler[scheduler_fileStorageIndexing_storage]';
71  $fieldId = 'scheduler_fileStorageIndexing_storage';
72  $fieldHtml = '<select class="form-control" name="' . $fieldName . '" id="' . $fieldId . '">' . implode("\n", $options) . '</select>';
73 
74  $fieldConfiguration = [
75  'code' => $fieldHtml,
76  'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.fileStorageIndexing.storage',
77  'cshKey' => '_MOD_system_txschedulerM1',
78  'cshLabel' => $fieldId
79  ];
80  return $fieldConfiguration;
81  }
82 
89  protected function ‪getFileCountField(‪FileStorageExtractionTask $task = null)
90  {
91  $fieldName = 'tx_scheduler[scheduler_fileStorageIndexing_fileCount]';
92  $fieldId = 'scheduler_fileStorageIndexing_fileCount';
93  $fieldValue = $task !== null ? (int)$task->maxFileCount : 100;
94  $fieldHtml = '<input type="text" class="form-control" name="' . $fieldName . '" id="' . $fieldId . '" value="' . htmlspecialchars($fieldValue) . '">';
95 
96  $fieldConfiguration = [
97  'code' => $fieldHtml,
98  'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.fileStorageExtraction.fileCount',
99  'cshKey' => '_MOD_system_txschedulerM1',
100  'cshLabel' => $fieldId
101  ];
102  return $fieldConfiguration;
103  }
104 
112  {
114 
115  if (empty($extractors)) {
116  $labelKey = 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.fileStorageExtraction.registeredExtractors.without_extractors';
117  $content = '<span class="label label-warning">'
118  . htmlspecialchars($this->‪getLanguageService()->sL($labelKey))
119  . '</span>';
120  } else {
121  // Assemble the extractor bullet list first.
122  $labelKey = 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.fileStorageExtraction.registeredExtractors.extractor';
123  $bullets = [];
124  foreach ($extractors as $extractor) {
125  $bullets[] = sprintf(
126  '<li title="%s">%s</li>',
127  get_class($extractor),
128  sprintf($this->‪getLanguageService()->sL($labelKey), $this->‪formatExtractorClassName($extractor), $extractor->getPriority())
129  );
130  }
131 
132  // Finalize content assembling.
133  $labelKey = 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.fileStorageExtraction.registeredExtractors.with_extractors';
134  $title = $this->‪getLanguageService()->‪sL($labelKey);
135  $content = '<p>' . htmlspecialchars($title) . '</p>';
136  $content .= '<ul>' . implode(LF, $bullets) . '</ul>';
137  }
138 
139  $fieldConfiguration = [
140  'code' => $content,
141  'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.fileStorageExtraction.registeredExtractors',
142  'cshKey' => '_MOD_system_txschedulerM1',
143  'cshLabel' => 'scheduler_fileStorageIndexing_registeredExtractors'
144  ];
145  return $fieldConfiguration;
146  }
147 
155  public function ‪validateAdditionalFields(array &$submittedData, ‪SchedulerModuleController $parentObject)
156  {
157  if (
158  !‪MathUtility::canBeInterpretedAsInteger($submittedData['scheduler_fileStorageIndexing_storage'])
159  || !‪MathUtility::canBeInterpretedAsInteger($submittedData['scheduler_fileStorageIndexing_fileCount'])
160  ) {
161  return false;
162  }
163  if (‪ResourceFactory::getInstance()->getStorageObject($submittedData['scheduler_fileStorageIndexing_storage']) === null) {
164  return false;
165  }
166  if (!‪MathUtility::isIntegerInRange($submittedData['scheduler_fileStorageIndexing_fileCount'], 1, 9999)) {
167  return false;
168  }
169  return true;
170  }
171 
179  public function ‪saveAdditionalFields(array $submittedData, ‪AbstractTask $task)
180  {
181  if (!$task instanceof ‪FileStorageExtractionTask) {
182  throw new \InvalidArgumentException('Task not of type FileStorageExtractionTask', 1384275698);
183  }
184  $task->storageUid = (int)$submittedData['scheduler_fileStorageIndexing_storage'];
185  $task->maxFileCount = (int)$submittedData['scheduler_fileStorageIndexing_fileCount'];
186  }
187 
195  protected function ‪formatExtractorClassName(‪ExtractorInterface $extractor)
196  {
197  $extractorParts = explode('\\', get_class($extractor));
198  return array_pop($extractorParts);
199  }
200 
204  protected function ‪getLanguageService()
205  {
206  return ‪$GLOBALS['LANG'];
207  }
208 }
‪TYPO3\CMS\Scheduler\Task\FileStorageExtractionAdditionalFieldProvider\getAdditionalFields
‪array getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $parentObject)
Definition: FileStorageExtractionAdditionalFieldProvider.php:40
‪TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger
‪static bool canBeInterpretedAsInteger($var)
Definition: MathUtility.php:73
‪TYPO3\CMS\Scheduler\Task\FileStorageExtractionTask
Definition: FileStorageExtractionTask.php:22
‪TYPO3
‪TYPO3\CMS\Core\Resource\Index\ExtractorInterface
Definition: ExtractorInterface.php:23
‪TYPO3\CMS\Core\Resource\Index\ExtractorRegistry
Definition: ExtractorRegistry.php:24
‪TYPO3\CMS\Scheduler\Task
Definition: AbstractTask.php:2
‪TYPO3\CMS\Core\Utility\MathUtility\isIntegerInRange
‪static bool isIntegerInRange($value, $minimum, $maximum)
Definition: MathUtility.php:200
‪TYPO3\CMS\Scheduler\Task\FileStorageExtractionAdditionalFieldProvider\validateAdditionalFields
‪bool validateAdditionalFields(array &$submittedData, SchedulerModuleController $parentObject)
Definition: FileStorageExtractionAdditionalFieldProvider.php:155
‪TYPO3\CMS\Scheduler\Task\FileStorageExtractionAdditionalFieldProvider\formatExtractorClassName
‪string formatExtractorClassName(ExtractorInterface $extractor)
Definition: FileStorageExtractionAdditionalFieldProvider.php:195
‪TYPO3\CMS\Core\Resource\ResourceFactory\getInstance
‪static ResourceFactory getInstance()
Definition: ResourceFactory.php:39
‪TYPO3\CMS\Core\Localization\LanguageService\sL
‪string sL($input)
Definition: LanguageService.php:158
‪TYPO3\CMS\Core\Resource\Index\ExtractorRegistry\getInstance
‪static ExtractorRegistry getInstance()
Definition: ExtractorRegistry.php:41
‪TYPO3\CMS\Scheduler\Task\FileStorageExtractionAdditionalFieldProvider\getFileCountField
‪array getFileCountField(FileStorageExtractionTask $task=null)
Definition: FileStorageExtractionAdditionalFieldProvider.php:89
‪TYPO3\CMS\Core\Resource\Index\ExtractorRegistry\getExtractors
‪ExtractorInterface[] getExtractors()
Definition: ExtractorRegistry.php:68
‪TYPO3\CMS\Scheduler\Task\FileStorageExtractionAdditionalFieldProvider\getRegisteredExtractorsField
‪array getRegisteredExtractorsField(FileStorageExtractionTask $task=null)
Definition: FileStorageExtractionAdditionalFieldProvider.php:111
‪TYPO3\CMS\Scheduler\Task\AbstractTask
Definition: AbstractTask.php:32
‪TYPO3\CMS\Scheduler\Task\FileStorageExtractionAdditionalFieldProvider\getAllStoragesField
‪array getAllStoragesField(FileStorageExtractionTask $task=null)
Definition: FileStorageExtractionAdditionalFieldProvider.php:57
‪TYPO3\CMS\Scheduler\Controller\SchedulerModuleController
Definition: SchedulerModuleController.php:53
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:33
‪TYPO3\CMS\Scheduler\Task\FileStorageExtractionAdditionalFieldProvider\getLanguageService
‪TYPO3 CMS Core Localization LanguageService getLanguageService()
Definition: FileStorageExtractionAdditionalFieldProvider.php:204
‪TYPO3\CMS\Scheduler\Task\FileStorageExtractionAdditionalFieldProvider
Definition: FileStorageExtractionAdditionalFieldProvider.php:30
‪TYPO3\CMS\Scheduler\Task\FileStorageExtractionAdditionalFieldProvider\saveAdditionalFields
‪saveAdditionalFields(array $submittedData, AbstractTask $task)
Definition: FileStorageExtractionAdditionalFieldProvider.php:179
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:21
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface
Definition: AdditionalFieldProviderInterface.php:21