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