TYPO3 CMS  TYPO3_8-7
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 
29 {
39  public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $parentObject)
40  {
41  if ($task !== null && !$task instanceof FileStorageExtractionTask) {
42  throw new \InvalidArgumentException('Task not of type FileStorageExtractionTask', 1384275695);
43  }
44  $additionalFields['scheduler_fileStorageIndexing_storage'] = $this->getAllStoragesField($task);
45  $additionalFields['scheduler_fileStorageIndexing_fileCount'] = $this->getFileCountField($task);
46  $additionalFields['scheduler_fileStorageIndexing_registeredExtractors'] = $this->getRegisteredExtractorsField($task);
47  return $additionalFields;
48  }
49 
56  protected function getAllStoragesField(FileStorageExtractionTask $task = null)
57  {
59  $storages = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class)->findAll();
60  $options = [];
61  foreach ($storages as $storage) {
62  if ($task !== null && $task->storageUid === $storage->getUid()) {
63  $options[] = '<option value="' . $storage->getUid() . '" selected="selected">' . $storage->getName() . '</option>';
64  } else {
65  $options[] = '<option value="' . $storage->getUid() . '">' . $storage->getName() . '</option>';
66  }
67  }
68 
69  $fieldName = 'tx_scheduler[scheduler_fileStorageIndexing_storage]';
70  $fieldId = 'scheduler_fileStorageIndexing_storage';
71  $fieldHtml = '<select class="form-control" name="' . $fieldName . '" id="' . $fieldId . '">' . implode("\n", $options) . '</select>';
72 
73  $fieldConfiguration = [
74  'code' => $fieldHtml,
75  'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.fileStorageIndexing.storage',
76  'cshKey' => '_MOD_system_txschedulerM1',
77  'cshLabel' => $fieldId
78  ];
79  return $fieldConfiguration;
80  }
81 
88  protected function getFileCountField(FileStorageExtractionTask $task = null)
89  {
90  $fieldName = 'tx_scheduler[scheduler_fileStorageIndexing_fileCount]';
91  $fieldId = 'scheduler_fileStorageIndexing_fileCount';
92  $fieldValue = $task !== null ? (int)$task->maxFileCount : 100;
93  $fieldHtml = '<input type="text" class="form-control" name="' . $fieldName . '" id="' . $fieldId . '" value="' . htmlspecialchars($fieldValue) . '">';
94 
95  $fieldConfiguration = [
96  'code' => $fieldHtml,
97  'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.fileStorageExtraction.fileCount',
98  'cshKey' => '_MOD_system_txschedulerM1',
99  'cshLabel' => $fieldId
100  ];
101  return $fieldConfiguration;
102  }
103 
111  {
112  $extractors = ExtractorRegistry::getInstance()->getExtractors();
113 
114  if (empty($extractors)) {
115  $labelKey = 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.fileStorageExtraction.registeredExtractors.without_extractors';
116  $content = '<span class="label label-warning">'
117  . htmlspecialchars($this->getLanguageService()->sL($labelKey))
118  . '</span>';
119  } else {
120  // Assemble the extractor bullet list first.
121  $labelKey = 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.fileStorageExtraction.registeredExtractors.extractor';
122  $bullets = [];
123  foreach ($extractors as $extractor) {
124  $bullets[] = sprintf(
125  '<li title="%s">%s</li>',
126  get_class($extractor),
127  sprintf($this->getLanguageService()->sL($labelKey), $this->formatExtractorClassName($extractor), $extractor->getPriority())
128  );
129  }
130 
131  // Finalize content assembling.
132  $labelKey = 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.fileStorageExtraction.registeredExtractors.with_extractors';
133  $title = $this->getLanguageService()->sL($labelKey);
134  $content = '<p>' . htmlspecialchars($title) . '</p>';
135  $content .= '<ul>' . implode(LF, $bullets) . '</ul>';
136  }
137 
138  $fieldConfiguration = [
139  'code' => $content,
140  'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.fileStorageExtraction.registeredExtractors',
141  'cshKey' => '_MOD_system_txschedulerM1',
142  'cshLabel' => 'scheduler_fileStorageIndexing_registeredExtractors'
143  ];
144  return $fieldConfiguration;
145  }
146 
154  public function validateAdditionalFields(array &$submittedData, SchedulerModuleController $parentObject)
155  {
156  if (
157  !MathUtility::canBeInterpretedAsInteger($submittedData['scheduler_fileStorageIndexing_storage'])
158  || !MathUtility::canBeInterpretedAsInteger($submittedData['scheduler_fileStorageIndexing_fileCount'])
159  ) {
160  return false;
161  }
162  if (ResourceFactory::getInstance()->getStorageObject($submittedData['scheduler_fileStorageIndexing_storage']) === null) {
163  return false;
164  }
165  if (!MathUtility::isIntegerInRange($submittedData['scheduler_fileStorageIndexing_fileCount'], 1, 9999)) {
166  return false;
167  }
168  return true;
169  }
170 
178  public function saveAdditionalFields(array $submittedData, AbstractTask $task)
179  {
180  if (!$task instanceof FileStorageExtractionTask) {
181  throw new \InvalidArgumentException('Task not of type FileStorageExtractionTask', 1384275698);
182  }
183  $task->storageUid = (int)$submittedData['scheduler_fileStorageIndexing_storage'];
184  $task->maxFileCount = (int)$submittedData['scheduler_fileStorageIndexing_fileCount'];
185  }
186 
194  protected function formatExtractorClassName(ExtractorInterface $extractor)
195  {
196  $extractorParts = explode('\\', get_class($extractor));
197  return array_pop($extractorParts);
198  }
199 
203  protected function getLanguageService()
204  {
205  return $GLOBALS['LANG'];
206  }
207 }
getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $parentObject)
static makeInstance($className,... $constructorArguments)
validateAdditionalFields(array &$submittedData, SchedulerModuleController $parentObject)
static isIntegerInRange($value, $minimum, $maximum)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']