/** * Function executed from the Scheduler. * * @return boolean */ public function execute() { $successfullyExecuted = TRUE; foreach ($this->tables as $table) { $where = 'hidden = 1 AND ' . $this->getWhereClause($table); if ($this->markAsDeleted && in_array($table, Tx_Tablecleaner_Utility_Base::getTablesWithDeletedAndTstamp())) { $fieldValues = array('tstamp' => $_SERVER['REQUEST_TIME'], 'deleted' => 1); $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, $where, $fieldValues); } else { $GLOBALS['TYPO3_DB']->exec_DELETEquery($table, $where); $error = $GLOBALS['TYPO3_DB']->sql_error(); if (!$error && $this->optimizeOption) { $GLOBALS['TYPO3_DB']->sql_query('OPTIMIZE TABLE ' . $table); } } if ($GLOBALS['TYPO3_DB']->sql_error()) { $successfullyExecuted = FALSE; } } return $successfullyExecuted; }
/** * This method checks any additional data that is relevant to the specific task. * If the task class is not relevant, the method is expected to return TRUE. * * @param array $submittedData : reference to the array containing the data * submitted by the user * @param \tx_scheduler_Module $schedulerModule : * reference to the calling object (BE module of the Scheduler) * * @return boolean True if validation was ok (or selected class is not * relevant), FALSE otherwise */ public function validateAdditionalFields(array &$submittedData, tx_scheduler_Module $schedulerModule) { $isValid = TRUE; if (is_array($submittedData['deletedTables'])) { $tables = Tx_Tablecleaner_Utility_Base::getTablesWithDeletedAndTstamp(); foreach ($submittedData['deletedTables'] as $table) { if (!in_array($table, $tables)) { $isValid = FALSE; $schedulerModule->addMessage($GLOBALS['LANG']->sL('LLL:EXT:tablecleaner/Resources/Private/Language/locallang.xml:tasks.general.invalidTables'), t3lib_FlashMessage::ERROR); } } } else { $isValid = FALSE; $schedulerModule->addMessage($GLOBALS['LANG']->sL('LLL:EXT:tablecleaner/Resources/Private/Language/locallang.xml:tasks.general.noTables'), t3lib_FlashMessage::ERROR); } if ($submittedData['deletedDayLimit'] <= 0) { $isValid = FALSE; $schedulerModule->addMessage($GLOBALS['LANG']->sL('LLL:EXT:tablecleaner/Resources/Private/Language/locallang.xml:tasks.general.invalidNumberOfDays'), t3lib_FlashMessage::ERROR); } return $isValid; }
/** * Get the where clause * * @param string $table The table for which to build the where clause. * @param string $stampField The name of the timesamp field. * * @return string */ public function getWhereClause($table, $stampField = 'tstamp') { $excludePages = Tx_Tablecleaner_Utility_Base::fetchExcludedPages(); $tablesWithPid = Tx_Tablecleaner_Utility_Base::getTablesWithPid(); $where = ' ' . $stampField . ' < ' . strtotime('-' . (int) $this->dayLimit . 'days'); if (!empty($excludePages) && in_array($table, $tablesWithPid)) { if ($table === 'pages') { $where .= ' AND NOT uid IN(' . implode(',', $excludePages) . ')'; } else { $where .= ' AND NOT pid IN(' . implode(',', $excludePages) . ')'; } } return $where; }
/** * Get tree data * * @param integer $uid * @param string $subLevelId * * @return array */ protected function getTreeData($uid, $subLevelId) { // Filter the results by preference and access $clauseExludePidList = ''; if ($pidList = $GLOBALS['BE_USER']->getTSConfigVal('options.hideRecords.pages')) { if ($pidList = $this->databaseHandle->cleanIntList($pidList)) { $clauseExludePidList = ' AND pages.uid NOT IN (' . $pidList . ')'; } } $clause = ' AND ' . $GLOBALS['BE_USER']->getPagePermsClause(1) . ' ' . $clauseExludePidList; /** * We want a page tree with all the excluded pages in there. This means * all pages that have the exclude flag set and also all pages that have the * excludeBranch flag set, including their children. * * 1). First fetch the page id's that have any exclusion options set */ $result = $this->databaseHandle->sql_query(' SELECT GROUP_CONCAT(uid) AS uids FROM pages WHERE tx_tablecleaner_exclude = 1 AND deleted = 0 ' . $clause . '; '); $row = $this->databaseHandle->sql_fetch_assoc($result); $excludePages = array(); if ($row['uids'] !== NULL) { $excludePages = explode(',', $row['uids']); } $this->databaseHandle->sql_free_result($result); $result = $this->databaseHandle->sql_query(' SELECT GROUP_CONCAT(uid) AS uids FROM pages WHERE tx_tablecleaner_exclude_branch = 1 AND deleted = 0 ' . $clause . '; '); $row = $this->databaseHandle->sql_fetch_assoc($result); $excludeBranchPages = array(); if ($row['uids'] !== NULL) { $excludeBranchPages = explode(',', $row['uids']); } $this->databaseHandle->sql_free_result($result); /** * 2). Fetch the id's up to the 'current root' page. * To build a complete page tree, we also need the parents of the * excluded pages. So we merge the found pages and fetch the rootlines for * all those pages. */ $allExcludedPages = array_merge($excludePages, $excludeBranchPages); $allExcludedPages = array_unique($allExcludedPages); $allUids = array(); foreach ($allExcludedPages as $pageId) { // Don't fetch the rootline if the pageId is already in the list if (!in_array($pageId, $allUids)) { // Get the rootline up to the starting uid $rootLine = t3lib_BEfunc::BEgetRootLine($pageId, ' AND NOT uid = ' . $uid . $clause); foreach ($rootLine as $record) { $allUids[] = $record['uid']; } } } /** * 3). Include self */ $allUids[] = $uid; /** * 4). Fetch all the children of the pages that have exclude_branch set. */ foreach ($excludeBranchPages as $pageId) { $allUids = array_merge($allUids, Tx_Tablecleaner_Utility_Base::fetchChildPages($pageId)); } $allUids = array_unique($allUids); $foundPages = $this->pageRepository->findByUids($allUids); $allPages = array(); foreach ($foundPages as $page) { $allPages[$page['uid']] = $page; } $tree = $this->reassembleTree($allPages, $uid, $subLevelId); $rootElement[$uid] = $allPages[$uid]; $rootElement[$uid][$subLevelId] = $tree; return $rootElement; }