TYPO3 CMS  TYPO3_6-2
CachingFrameworkGarbageCollectionAdditionalFieldProvider.php
Go to the documentation of this file.
1 <?php
3 
23 
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';
40  }
41  } elseif ($parentObject->CMD == 'edit') {
42  // In case of editing the task, set to currently selected value
43  $taskInfo['scheduler_cachingFrameworkGarbageCollection_selectedBackends'] = $task->selectedBackends;
44  }
45  }
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(
51  'code' => $fieldHtml,
52  'label' => 'LLL:EXT:scheduler/mod1/locallang.xlf:label.cachingFrameworkGarbageCollection.selectBackends',
53  'cshKey' => '_MOD_system_txschedulerM1',
54  'cshLabel' => $fieldId
55  );
56  return $additionalFields;
57  }
58 
66  public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject) {
67  $validData = TRUE;
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);
73  $validData = FALSE;
74  }
75  } else {
76  $parentObject->addMessage($GLOBALS['LANG']->sL('LLL:EXT:scheduler/mod1/locallang.xlf:msg.noCacheBackendSelected'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
77  $validData = FALSE;
78  }
79  return $validData;
80  }
81 
89  public function saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task) {
90  $task->selectedBackends = $submittedData['scheduler_cachingFrameworkGarbageCollection_selectedBackends'];
91  }
92 
99  protected function getCacheBackendOptions(array $selectedBackends) {
100  $options = array();
101  $availableBackends = $this->getRegisteredBackends();
102  foreach ($availableBackends as $backendName) {
103  if (in_array($backendName, $selectedBackends)) {
104  $selected = ' selected="selected"';
105  } else {
106  $selected = '';
107  }
108  $options[] = '<option value="' . $backendName . '"' . $selected . '>' . $backendName . '</option>';
109  }
110  return implode('', $options);
111  }
112 
118  protected function getRegisteredBackends() {
119  $backends = array();
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;
126  }
127  }
128  }
129  return $backends;
130  }
131 
132 }
validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
getAdditionalFields(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]