TYPO3 CMS  TYPO3_7-6
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  {
113  $extractors = ExtractorRegistry::getInstance()->getExtractors();
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  } elseif (ResourceFactory::getInstance()->getStorageObject($submittedData['scheduler_fileStorageIndexing_storage']) === null) {
163  return false;
164  } elseif (!MathUtility::isIntegerInRange($submittedData['scheduler_fileStorageIndexing_fileCount'], 1, 9999)) {
165  return false;
166  }
167  return true;
168  }
169 
178  public function saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task)
179  {
180  if ($task !== null && !$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 }
saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task)
getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $parentObject)
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']