‪TYPO3CMS  10.4
CachingFrameworkGarbageCollectionAdditionalFieldProvider.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 
24 
31 {
40  public function ‪getAdditionalFields(array &$taskInfo, $task, ‪SchedulerModuleController $schedulerModule)
41  {
42  $currentSchedulerModuleAction = $schedulerModule->‪getCurrentAction();
43 
44  // Initialize selected fields
45  if (empty($taskInfo['scheduler_cachingFrameworkGarbageCollection_selectedBackends'])) {
46  $taskInfo['scheduler_cachingFrameworkGarbageCollection_selectedBackends'] = [];
47  if ($currentSchedulerModuleAction->equals(‪Action::ADD)) {
48  // In case of new task, set to dbBackend if it's available
49  if (in_array(Typo3DatabaseBackend::class, $this->‪getRegisteredBackends())) {
50  $taskInfo['scheduler_cachingFrameworkGarbageCollection_selectedBackends'][] = Typo3DatabaseBackend::class;
51  }
52  } elseif ($currentSchedulerModuleAction->equals(‪Action::EDIT)) {
53  // In case of editing the task, set to currently selected value
54  $taskInfo['scheduler_cachingFrameworkGarbageCollection_selectedBackends'] = $task->selectedBackends;
55  }
56  }
57  $fieldName = 'tx_scheduler[scheduler_cachingFrameworkGarbageCollection_selectedBackends][]';
58  $fieldId = 'task_cachingFrameworkGarbageCollection_selectedBackends';
59  $fieldOptions = $this->‪getCacheBackendOptions($taskInfo['scheduler_cachingFrameworkGarbageCollection_selectedBackends']);
60  $fieldHtml = '<select class="form-control" name="' . $fieldName . '" id="' . $fieldId . '" class="from-control" size="10" multiple="multiple">' . $fieldOptions . '</select>';
61  $additionalFields = [];
62  $additionalFields[$fieldId] = [
63  'code' => $fieldHtml,
64  'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.cachingFrameworkGarbageCollection.selectBackends',
65  'cshKey' => '_MOD_system_txschedulerM1',
66  'cshLabel' => $fieldId
67  ];
68  return $additionalFields;
69  }
70 
78  public function ‪validateAdditionalFields(array &$submittedData, ‪SchedulerModuleController $schedulerModule)
79  {
80  $validData = true;
81  $availableBackends = $this->‪getRegisteredBackends();
82  if (is_array($submittedData['scheduler_cachingFrameworkGarbageCollection_selectedBackends'])) {
83  $invalidBackends = array_diff($submittedData['scheduler_cachingFrameworkGarbageCollection_selectedBackends'], $availableBackends);
84  if (!empty($invalidBackends)) {
85  $this->‪addMessage($this->‪getLanguageService()->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.selectionOfNonExistingCacheBackends'), ‪FlashMessage::ERROR);
86  $validData = false;
87  }
88  } else {
89  $this->‪addMessage($this->‪getLanguageService()->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.noCacheBackendSelected'), ‪FlashMessage::ERROR);
90  $validData = false;
91  }
92  return $validData;
93  }
94 
101  public function ‪saveAdditionalFields(array $submittedData, ‪AbstractTask $task)
102  {
103  $task->selectedBackends = $submittedData['scheduler_cachingFrameworkGarbageCollection_selectedBackends'];
104  }
105 
112  protected function ‪getCacheBackendOptions(array $selectedBackends)
113  {
114  $options = [];
115  $availableBackends = $this->‪getRegisteredBackends();
116  foreach ($availableBackends as $backendName) {
117  if (in_array($backendName, $selectedBackends)) {
118  $selected = ' selected="selected"';
119  } else {
120  $selected = '';
121  }
122  $options[] = '<option value="' . $backendName . '"' . $selected . '>' . $backendName . '</option>';
123  }
124  return implode('', $options);
125  }
126 
132  protected function ‪getRegisteredBackends()
133  {
134  $backends = [];
135  $cacheConfigurations = ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'];
136  if (is_array($cacheConfigurations)) {
137  foreach ($cacheConfigurations as $cacheConfiguration) {
138  $backend = $cacheConfiguration['backend'];
139  if (!in_array($backend, $backends)) {
140  $backends[] = $backend;
141  }
142  }
143  }
144  return $backends;
145  }
146 
151  {
152  return ‪$GLOBALS['LANG'] ?? null;
153  }
154 }
‪TYPO3\CMS\Scheduler\Task\Enumeration\Action\ADD
‪const ADD
Definition: Action.php:28
‪TYPO3\CMS\Scheduler\Task\CachingFrameworkGarbageCollectionAdditionalFieldProvider\saveAdditionalFields
‪saveAdditionalFields(array $submittedData, AbstractTask $task)
Definition: CachingFrameworkGarbageCollectionAdditionalFieldProvider.php:101
‪TYPO3\CMS\Scheduler\Task\CachingFrameworkGarbageCollectionAdditionalFieldProvider
Definition: CachingFrameworkGarbageCollectionAdditionalFieldProvider.php:31
‪TYPO3\CMS\Scheduler\Task
Definition: AbstractTask.php:16
‪TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend
Definition: Typo3DatabaseBackend.php:31
‪TYPO3\CMS\Scheduler\Task\CachingFrameworkGarbageCollectionAdditionalFieldProvider\getRegisteredBackends
‪array getRegisteredBackends()
Definition: CachingFrameworkGarbageCollectionAdditionalFieldProvider.php:132
‪TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider
Definition: AbstractAdditionalFieldProvider.php:28
‪TYPO3\CMS\Scheduler\Task\CachingFrameworkGarbageCollectionAdditionalFieldProvider\getAdditionalFields
‪array getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule)
Definition: CachingFrameworkGarbageCollectionAdditionalFieldProvider.php:40
‪TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider\addMessage
‪addMessage(string $message, int $severity=FlashMessage::OK)
Definition: AbstractAdditionalFieldProvider.php:35
‪TYPO3\CMS\Scheduler\Task\AbstractTask
Definition: AbstractTask.php:35
‪TYPO3\CMS\Scheduler\Task\CachingFrameworkGarbageCollectionAdditionalFieldProvider\validateAdditionalFields
‪bool validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule)
Definition: CachingFrameworkGarbageCollectionAdditionalFieldProvider.php:78
‪TYPO3\CMS\Scheduler\Controller\SchedulerModuleController
Definition: SchedulerModuleController.php:56
‪TYPO3\CMS\Scheduler\Task\Enumeration\Action\EDIT
‪const EDIT
Definition: Action.php:30
‪TYPO3\CMS\Scheduler\Controller\SchedulerModuleController\getCurrentAction
‪Action getCurrentAction()
Definition: SchedulerModuleController.php:181
‪TYPO3\CMS\Scheduler\Task\CachingFrameworkGarbageCollectionAdditionalFieldProvider\getLanguageService
‪LanguageService null getLanguageService()
Definition: CachingFrameworkGarbageCollectionAdditionalFieldProvider.php:150
‪TYPO3\CMS\Scheduler\Task\CachingFrameworkGarbageCollectionAdditionalFieldProvider\getCacheBackendOptions
‪string getCacheBackendOptions(array $selectedBackends)
Definition: CachingFrameworkGarbageCollectionAdditionalFieldProvider.php:112
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:24
‪TYPO3\CMS\Scheduler\Task\Enumeration\Action
Definition: Action.php:26
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:31