TYPO3 CMS  TYPO3_6-2
TableGarbageCollectionTask.php
Go to the documentation of this file.
1 <?php
3 
29 
33  public $allTables = FALSE;
34 
38  public $numberOfDays = 180;
39 
43  public $table = '';
44 
51  public function execute() {
52  $tableConfigurations = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks']['TYPO3\\CMS\\Scheduler\\Task\\TableGarbageCollectionTask']['options']['tables'];
53  $tableHandled = FALSE;
54  foreach ($tableConfigurations as $tableName => $configuration) {
55  if ($this->allTables || $tableName === $this->table) {
56  $this->handleTable($tableName, $configuration);
57  $tableHandled = TRUE;
58  }
59  }
60  if (!$tableHandled) {
61  throw new \RuntimeException('TYPO3\\CMS\\Scheduler\\Task\\TableGarbageCollectionTask misconfiguration: ' . $this->table . ' does not exist in configuration', 1308354399);
62  }
63  return TRUE;
64  }
65 
74  protected function handleTable($table, array $configuration) {
75  if (!empty($configuration['expireField'])) {
76  $field = $configuration['expireField'];
77  $dateLimit = $GLOBALS['EXEC_TIME'];
78  // If expire field value is 0, do not delete
79  // Expire field = 0 means no expiration
80  $where = $field . ' <= \'' . $dateLimit . '\' AND ' . $field . ' > \'0\'';
81  } elseif (!empty($configuration['dateField'])) {
82  if (!$this->allTables) {
83  $deleteTimestamp = strtotime('-' . $this->numberOfDays . 'days');
84  } else {
85  if (!isset($configuration['expirePeriod'])) {
86  throw new \RuntimeException('TYPO3\\CMS\\Scheduler\\Task\\TableGarbageCollectionTask misconfiguration: No expirePeriod defined for table ' . $table, 1308355095);
87  }
88  $deleteTimestamp = strtotime('-' . $configuration['expirePeriod'] . 'days');
89  }
90  $where = $configuration['dateField'] . ' < ' . $deleteTimestamp;
91  } else {
92  throw new \RuntimeException('TYPO3\\CMS\\Scheduler\\Task\\TableGarbageCollectionTask misconfiguration: Either expireField or dateField must be defined for table ' . $table, 1308355268);
93  }
94  $GLOBALS['TYPO3_DB']->exec_DELETEquery($table, $where);
95  $error = $GLOBALS['TYPO3_DB']->sql_error();
96  if ($error) {
97  throw new \RuntimeException('TYPO3\\CMS\\Scheduler\\Task\\TableGarbageCollectionTask failed for table ' . $this->table . ' with error: ' . $error, 1308255491);
98  }
99  return TRUE;
100  }
101 
107  public function getAdditionalInformation() {
108  if ($this->allTables) {
109  $message = $GLOBALS['LANG']->sL('LLL:EXT:scheduler/mod1/locallang.xlf:label.tableGarbageCollection.additionalInformationAllTables');
110  } else {
111  $message = sprintf($GLOBALS['LANG']->sL('LLL:EXT:scheduler/mod1/locallang.xlf:label.tableGarbageCollection.additionalInformationTable'), $this->table);
112  }
113  return $message;
114  }
115 
116 }
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]