TYPO3 CMS  TYPO3_7-6
OptimizeDatabaseTableAdditionalFieldProvider.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 
21 {
30  public function getAdditionalFields(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
31  {
32  // Initialize selected fields
33  if (empty($taskInfo['scheduler_optimizeDatabaseTables_selectedTables'])) {
34  $taskInfo['scheduler_optimizeDatabaseTables_selectedTables'] = [];
35  if ($parentObject->CMD === 'add') {
36  // In case of new task, select no tables by default
37  $taskInfo['scheduler_optimizeDatabaseTables_selectedTables'] = [];
38  } elseif ($parentObject->CMD === 'edit') {
39  // In case of editing the task, set to currently selected value
40  $taskInfo['scheduler_optimizeDatabaseTables_selectedTables'] = $task->selectedTables;
41  }
42  }
43  $fieldName = 'tx_scheduler[scheduler_optimizeDatabaseTables_selectedTables][]';
44  $fieldId = 'scheduler_optimizeDatabaseTables_selectedTables';
45  $fieldOptions = $this->getDatabaseTableOptions($taskInfo['scheduler_optimizeDatabaseTables_selectedTables']);
46  $fieldHtml = '<select class="form-control" name="' . $fieldName . '" id="' . $fieldId . '" class="from-control" size="10" multiple="multiple">' . $fieldOptions . '</select>';
47  $additionalFields[$fieldId] = [
48  'code' => $fieldHtml,
49  'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.optimizeDatabaseTables.selectTables',
50  'cshKey' => '_MOD_system_txschedulerM1',
51  'cshLabel' => $fieldId
52  ];
53  return $additionalFields;
54  }
55 
63  public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
64  {
65  $validData = true;
66  $availableTables = array_keys($this->getDatabaseTables());
67  if (is_array($submittedData['scheduler_optimizeDatabaseTables_selectedTables'])) {
68  $invalidTables = array_diff($submittedData['scheduler_optimizeDatabaseTables_selectedTables'], $availableTables);
69  if (!empty($invalidTables)) {
70  $parentObject->addMessage($GLOBALS['LANG']->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.selectionOfNonExistingDatabaseTables'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
71  $validData = false;
72  }
73  } else {
74  $parentObject->addMessage($GLOBALS['LANG']->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.noDatabaseTablesSelected'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
75  $validData = false;
76  }
77  return $validData;
78  }
79 
87  public function saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task)
88  {
89  $task->selectedTables = $submittedData['scheduler_optimizeDatabaseTables_selectedTables'];
90  }
91 
98  protected function getDatabaseTableOptions(array $selectedTables)
99  {
100  $options = [];
101  $availableTables = $this->getDatabaseTables();
102  foreach ($availableTables as $tableName => $tableInformation) {
103  $selected = in_array($tableName, $selectedTables, true) ? ' selected="selected"' : '';
104  $options[] = '<option value="' . $tableName . '"' . $selected . '>' . $tableName . '</option>';
105  }
106  return implode('', $options);
107  }
108 
114  protected function getDatabaseTables()
115  {
116  $tables = $this->getDatabaseConnection()->admin_get_tables();
117  $tables = array_filter(
118  $tables,
119  function ($table) {
120  return !empty($table['Engine']) && in_array($table['Engine'], ['MyISAM', 'InnoDB', 'ARCHIVE']);
121  }
122  );
123  return $tables;
124  }
125 
129  protected function getDatabaseConnection()
130  {
131  return $GLOBALS['TYPO3_DB'];
132  }
133 }
saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task)
validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
getAdditionalFields(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)