‪TYPO3CMS  ‪main
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 
27 
33 {
43  public function ‪getAdditionalFields(array &$taskInfo, $task, ‪SchedulerModuleController $parentObject)
44  {
45  if ($task !== null && !$task instanceof ‪FileStorageExtractionTask) {
46  throw new \InvalidArgumentException('Task not of type FileStorageExtractionTask', 1384275695);
47  }
48  $additionalFields = [];
49  $additionalFields['scheduler_fileStorageIndexing_storage'] = $this->‪getAllStoragesField($task);
50  $additionalFields['scheduler_fileStorageIndexing_fileCount'] = $this->‪getFileCountField($task);
51  $additionalFields['scheduler_fileStorageIndexing_registeredExtractors'] = $this->‪getRegisteredExtractorsField($task);
52  return $additionalFields;
53  }
54 
61  protected function ‪getAllStoragesField(‪FileStorageExtractionTask $task = null)
62  {
64  $storages = GeneralUtility::makeInstance(StorageRepository::class)->findAll();
65  $options = [];
66  foreach ($storages as $storage) {
67  if ($task !== null && $task->storageUid === $storage->getUid()) {
68  $options[] = '<option value="' . $storage->getUid() . '" selected="selected">' . $storage->getName() . '</option>';
69  } else {
70  $options[] = '<option value="' . $storage->getUid() . '">' . $storage->getName() . '</option>';
71  }
72  }
73 
74  $fieldName = 'tx_scheduler[scheduler_fileStorageIndexing_storage]';
75  $fieldId = 'scheduler_fileStorageIndexing_storage';
76  $fieldHtml = '<select class="form-select" name="' . $fieldName . '" id="' . $fieldId . '">'
77  . implode("\n", $options) . '</select>';
78 
79  $fieldConfiguration = [
80  'code' => $fieldHtml,
81  'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.fileStorageIndexing.storage',
82  'cshKey' => '_MOD_system_txschedulerM1',
83  'cshLabel' => $fieldId,
84  'type' => 'select',
85  ];
86  return $fieldConfiguration;
87  }
88 
95  protected function ‪getFileCountField(‪FileStorageExtractionTask $task = null)
96  {
97  $fieldName = 'tx_scheduler[scheduler_fileStorageIndexing_fileCount]';
98  $fieldId = 'scheduler_fileStorageIndexing_fileCount';
99  $fieldValue = (string)($task !== null ? (int)$task->maxFileCount : 100);
100  $fieldHtml = '<input type="text" class="form-control form-control-clearable t3js-clearable" name="' . $fieldName . '" id="' . $fieldId
101  . '" value="' . htmlspecialchars($fieldValue) . '">';
102 
103  $fieldConfiguration = [
104  'code' => $fieldHtml,
105  'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.fileStorageExtraction.fileCount',
106  'cshKey' => '_MOD_system_txschedulerM1',
107  'cshLabel' => $fieldId,
108  'type' => 'input',
109  ];
110  return $fieldConfiguration;
111  }
112 
120  {
121  $extractors = GeneralUtility::makeInstance(ExtractorRegistry::class)->getExtractors();
122 
123  if (empty($extractors)) {
124  $labelKey = 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.fileStorageExtraction.registeredExtractors.without_extractors';
125  $content = '<span class="badge badge-warning">'
126  . htmlspecialchars($this->‪getLanguageService()->sL($labelKey))
127  . '</span>';
128  } else {
129  // Assemble the extractor bullet list first.
130  $labelKey = 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.fileStorageExtraction.registeredExtractors.extractor';
131  $bullets = [];
132  foreach ($extractors as $extractor) {
133  $bullets[] = sprintf(
134  '<li title="%s">%s</li>',
135  get_class($extractor),
136  sprintf($this->‪getLanguageService()->sL($labelKey), $this->‪formatExtractorClassName($extractor), $extractor->getPriority())
137  );
138  }
139 
140  // Finalize content assembling.
141  $labelKey = 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.fileStorageExtraction.registeredExtractors.with_extractors';
142  $title = $this->‪getLanguageService()->sL($labelKey);
143  $content = '<p>' . htmlspecialchars($title) . '</p>';
144  $content .= '<ul>' . implode(LF, $bullets) . '</ul>';
145  }
146 
147  $fieldConfiguration = [
148  'code' => $content,
149  'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.fileStorageExtraction.registeredExtractors',
150  'cshKey' => '_MOD_system_txschedulerM1',
151  'cshLabel' => 'scheduler_fileStorageIndexing_registeredExtractors',
152  ];
153  return $fieldConfiguration;
154  }
155 
163  public function ‪validateAdditionalFields(array &$submittedData, ‪SchedulerModuleController $parentObject)
164  {
165  if (
166  !‪MathUtility::canBeInterpretedAsInteger($submittedData['scheduler_fileStorageIndexing_storage'])
167  || !‪MathUtility::canBeInterpretedAsInteger($submittedData['scheduler_fileStorageIndexing_fileCount'])
168  ) {
169  return false;
170  }
171  if (GeneralUtility::makeInstance(StorageRepository::class)->findByUid($submittedData['scheduler_fileStorageIndexing_storage']) === null) {
172  return false;
173  }
174  if (!‪MathUtility::isIntegerInRange($submittedData['scheduler_fileStorageIndexing_fileCount'], 1, 9999)) {
175  return false;
176  }
177  return true;
178  }
179 
187  public function ‪saveAdditionalFields(array $submittedData, ‪AbstractTask $task)
188  {
189  if (!$task instanceof ‪FileStorageExtractionTask) {
190  throw new \InvalidArgumentException('Task not of type FileStorageExtractionTask', 1384275698);
191  }
192  $task->storageUid = (int)$submittedData['scheduler_fileStorageIndexing_storage'];
193  $task->maxFileCount = (int)$submittedData['scheduler_fileStorageIndexing_fileCount'];
194  }
195 
202  protected function ‪formatExtractorClassName(‪ExtractorInterface $extractor)
203  {
204  $extractorParts = explode('\\', get_class($extractor));
205  return array_pop($extractorParts);
206  }
207 
209  {
210  return ‪$GLOBALS['LANG'];
211  }
212 }
‪TYPO3\CMS\Scheduler\Task\FileStorageExtractionAdditionalFieldProvider\getAdditionalFields
‪array getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $parentObject)
Definition: FileStorageExtractionAdditionalFieldProvider.php:43
‪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\Scheduler\Task\FileStorageExtractionAdditionalFieldProvider\validateAdditionalFields
‪bool validateAdditionalFields(array &$submittedData, SchedulerModuleController $parentObject)
Definition: FileStorageExtractionAdditionalFieldProvider.php:163
‪TYPO3\CMS\Scheduler\Task\FileStorageExtractionAdditionalFieldProvider\formatExtractorClassName
‪string formatExtractorClassName(ExtractorInterface $extractor)
Definition: FileStorageExtractionAdditionalFieldProvider.php:202
‪TYPO3\CMS\Scheduler\Task\FileStorageExtractionAdditionalFieldProvider\getFileCountField
‪array getFileCountField(FileStorageExtractionTask $task=null)
Definition: FileStorageExtractionAdditionalFieldProvider.php:95
‪TYPO3\CMS\Scheduler\Task\FileStorageExtractionAdditionalFieldProvider\getRegisteredExtractorsField
‪array getRegisteredExtractorsField(FileStorageExtractionTask $task=null)
Definition: FileStorageExtractionAdditionalFieldProvider.php:119
‪TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger
‪static bool canBeInterpretedAsInteger(mixed $var)
Definition: MathUtility.php:69
‪TYPO3\CMS\Scheduler\Task\AbstractTask
Definition: AbstractTask.php:33
‪TYPO3\CMS\Scheduler\Task\FileStorageExtractionAdditionalFieldProvider\getAllStoragesField
‪array getAllStoragesField(FileStorageExtractionTask $task=null)
Definition: FileStorageExtractionAdditionalFieldProvider.php:61
‪TYPO3\CMS\Scheduler\Controller\SchedulerModuleController
Definition: SchedulerModuleController.php:61
‪TYPO3\CMS\Core\Resource\StorageRepository
Definition: StorageRepository.php:38
‪TYPO3\CMS\Scheduler\Task\FileStorageExtractionAdditionalFieldProvider\getLanguageService
‪getLanguageService()
Definition: FileStorageExtractionAdditionalFieldProvider.php:208
‪TYPO3\CMS\Core\Utility\MathUtility\isIntegerInRange
‪static isIntegerInRange(mixed $value, int $minimum, int $maximum)
Definition: MathUtility.php:196
‪TYPO3\CMS\Scheduler\Task\FileStorageExtractionAdditionalFieldProvider
Definition: FileStorageExtractionAdditionalFieldProvider.php:33
‪TYPO3\CMS\Scheduler\Task\FileStorageExtractionAdditionalFieldProvider\saveAdditionalFields
‪saveAdditionalFields(array $submittedData, AbstractTask $task)
Definition: FileStorageExtractionAdditionalFieldProvider.php:187
‪TYPO3\CMS\Core\Resource\ResourceStorage
Definition: ResourceStorage.php:129
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:24
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface
Definition: AdditionalFieldProviderInterface.php:25