$configuration) { if ($this->allTables || $tableName === $this->table) { $this->handleTable($tableName, $configuration); $tableHandled = true; } } if (!$tableHandled) { throw new \RuntimeException(self::class . ' misconfiguration: ' . $this->table . ' does not exist in configuration', 1308354399); } return true; } /** * Execute clean up of a specific table * * @throws \RuntimeException If table configuration is broken * @param string $table The table to handle * @param array $configuration Clean up configuration * @return bool TRUE if cleanup was successful */ protected function handleTable($table, array $configuration) { $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table); $queryBuilder->delete($table); if (!empty($configuration['expireField'])) { $field = $configuration['expireField']; $dateLimit = $GLOBALS['EXEC_TIME']; // If expire field value is 0, do not delete // Expire field = 0 means no expiration $queryBuilder->where( $queryBuilder->expr()->lte($field, $queryBuilder->createNamedParameter($dateLimit, \PDO::PARAM_INT)), $queryBuilder->expr()->gt($field, $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)) ); } elseif (!empty($configuration['dateField'])) { if (!$this->allTables) { $deleteTimestamp = strtotime('-' . $this->numberOfDays . 'days'); } else { if (!isset($configuration['expirePeriod'])) { throw new \RuntimeException(self::class . ' misconfiguration: No expirePeriod defined for table ' . $table, 1308355095); } $deleteTimestamp = strtotime('-' . $configuration['expirePeriod'] . 'days'); } $queryBuilder->where( $queryBuilder->expr()->lt( $configuration['dateField'], $queryBuilder->createNamedParameter($deleteTimestamp, \PDO::PARAM_INT) ) ); } else { throw new \RuntimeException(self::class . ' misconfiguration: Either expireField or dateField must be defined for table ' . $table, 1308355268); } try { $queryBuilder->execute(); } catch (DBALException $e) { throw new \RuntimeException(self::class . ' failed for table ' . $this->table . ' with error: ' . $e->getMessage(), 1308255491); } return true; } /** * This method returns the selected table as additional information * * @return string Information to display */ public function getAdditionalInformation() { if ($this->allTables) { $message = $GLOBALS['LANG']->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.tableGarbageCollection.additionalInformationAllTables'); } else { $message = sprintf($GLOBALS['LANG']->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.tableGarbageCollection.additionalInformationTable'), $this->table); } return $message; } }