2 namespace TYPO3\CMS\Scheduler\Task
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 * Additional BE fields for caching framework garbage collection task.
18 * Creates a multi selectbox with all available cache backends to select from.
20 * @author Christian Kuhn <lolli@schwarzbu.ch>
22 class CachingFrameworkGarbageCollectionAdditionalFieldProvider
implements \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface
{
25 * Add a multi select box with all available cache backends.
27 * @param array $taskInfo Reference to the array containing the info used in the add/edit form
28 * @param object $task When editing, reference to the current task object. Null when adding.
29 * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject Reference to the calling object (Scheduler's BE module)
30 * @return array Array containing all the information pertaining to the additional fields
32 public function getAdditionalFields(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController
$parentObject) {
33 // Initialize selected fields
34 if (empty($taskInfo['scheduler_cachingFrameworkGarbageCollection_selectedBackends'])) {
35 $taskInfo['scheduler_cachingFrameworkGarbageCollection_selectedBackends'] = array();
36 if ($parentObject->CMD
== 'add') {
37 // In case of new task, set to dbBackend if it's available
38 if (in_array('TYPO3\\CMS\\Core\\Cache\\Backend\\Typo3DatabaseBackend', $this->getRegisteredBackends())) {
39 $taskInfo['scheduler_cachingFrameworkGarbageCollection_selectedBackends'][] = 'TYPO3\\CMS\\Core\\Cache\\Backend\\Typo3DatabaseBackend';
41 } elseif ($parentObject->CMD
== 'edit') {
42 // In case of editing the task, set to currently selected value
43 $taskInfo['scheduler_cachingFrameworkGarbageCollection_selectedBackends'] = $task->selectedBackends
;
46 $fieldName = 'tx_scheduler[scheduler_cachingFrameworkGarbageCollection_selectedBackends][]';
47 $fieldId = 'task_cachingFrameworkGarbageCollection_selectedBackends';
48 $fieldOptions = $this->getCacheBackendOptions($taskInfo['scheduler_cachingFrameworkGarbageCollection_selectedBackends']);
49 $fieldHtml = '<select name="' . $fieldName . '" id="' . $fieldId . '" class="wide" size="10" multiple="multiple">' . $fieldOptions . '</select>';
50 $additionalFields[$fieldId] = array(
52 'label' => 'LLL:EXT:scheduler/mod1/locallang.xlf:label.cachingFrameworkGarbageCollection.selectBackends',
53 'cshKey' => '_MOD_system_txschedulerM1',
54 'cshLabel' => $fieldId
56 return $additionalFields;
60 * Checks that all selected backends exist in available backend list
62 * @param array $submittedData Reference to the array containing the data submitted by the user
63 * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject Reference to the calling object (Scheduler's BE module)
64 * @return boolean TRUE if validation was ok (or selected class is not relevant), FALSE otherwise
66 public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController
$parentObject) {
68 $availableBackends = $this->getRegisteredBackends();
69 if (is_array($submittedData['scheduler_cachingFrameworkGarbageCollection_selectedBackends'])) {
70 $invalidBackends = array_diff($submittedData['scheduler_cachingFrameworkGarbageCollection_selectedBackends'], $availableBackends);
71 if (!empty($invalidBackends)) {
72 $parentObject->addMessage($GLOBALS['LANG']->sL('LLL:EXT:scheduler/mod1/locallang.xlf:msg.selectionOfNonExistingCacheBackends'), \TYPO3\CMS\Core\Messaging\FlashMessage
::ERROR
);
76 $parentObject->addMessage($GLOBALS['LANG']->sL('LLL:EXT:scheduler/mod1/locallang.xlf:msg.noCacheBackendSelected'), \TYPO3\CMS\Core\Messaging\FlashMessage
::ERROR
);
83 * Save selected backends in task object
85 * @param array $submittedData Contains data submitted by the user
86 * @param \TYPO3\CMS\Scheduler\Task\AbstractTask $task Reference to the current task object
89 public function saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask
$task) {
90 $task->selectedBackends
= $submittedData['scheduler_cachingFrameworkGarbageCollection_selectedBackends'];
94 * Build select options of available backends and set currently selected backends
96 * @param array $selectedBackends Selected backends
97 * @return string HTML of selectbox options
99 protected function getCacheBackendOptions(array $selectedBackends) {
101 $availableBackends = $this->getRegisteredBackends();
102 foreach ($availableBackends as $backendName) {
103 if (in_array($backendName, $selectedBackends)) {
104 $selected = ' selected="selected"';
108 $options[] = '<option value="' . $backendName . '"' . $selected . '>' . $backendName . '</option>';
110 return implode('', $options);
114 * Get all registered caching framework backends
116 * @return array Registered backends
118 protected function getRegisteredBackends() {
120 $cacheConfigurations = $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'];
121 if (is_array($cacheConfigurations)) {
122 foreach ($cacheConfigurations as $cacheConfiguration) {
123 $backend = $cacheConfiguration['backend'];
124 if (!in_array($backend, $backends)) {
125 $backends[] = $backend;