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