* The TYPO3 project - inspiring people to share!
*/
+use TYPO3\CMS\Core\Log\LogManager;
use TYPO3\CMS\Core\Utility;
/**
*
* @var string
*/
- protected $objectType = \TYPO3\CMS\Core\Resource\ProcessedFile::class;
+ protected $objectType = ProcessedFile::class;
/**
* Main File object storage table. Note that this repository also works on
* Creates this object.
*/
public function __construct() {
- $this->resourceFactory = Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\ResourceFactory::class);
+ $this->resourceFactory = Utility\GeneralUtility::makeInstance(ResourceFactory::class);
$this->databaseConnection = $GLOBALS['TYPO3_DB'];
}
return $itemList;
}
+ /**
+ * Removes all processed files and also deletes the associated physical files
+ *
+ * @param int|NULL $storageUid If not NULL, only the processed files of the given storage are removed
+ * @return int Number of failed deletions
+ */
+ public function removeAll($storageUid = NULL) {
+ $res = $this->databaseConnection->exec_SELECTquery('*', $this->table, 'identifier <> \'\'');
+ $logger = $this->getLogger();
+ $errorCount = 0;
+ while ($row = $this->databaseConnection->sql_fetch_assoc($res)) {
+ if ($storageUid && (int)$storageUid !== (int)$row['storage']) {
+ continue;
+ }
+ try {
+ $file = $this->createDomainObject($row);
+ $file->getStorage()->setEvaluatePermissions(FALSE);
+ $file->delete(TRUE);
+ } catch (\Exception $e) {
+ $logger->error(
+ 'Failed to delete file "' . $row['identifier'] . '" in storage uid ' . $row['storage'] . '.',
+ array(
+ 'exception' => $e
+ )
+ );
+ ++$errorCount;
+ }
+ }
+
+ $this->databaseConnection->exec_TRUNCATEquery($this->table);
+
+ return $errorCount;
+ }
+
/**
* Removes all array keys which cannot be persisted
return array_intersect_key($data, $this->databaseConnection->admin_get_fields($this->table));
}
-}
\ No newline at end of file
+ /**
+ * @return \TYPO3\CMS\Core\Log\Logger
+ */
+ protected function getLogger() {
+ return Utility\GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
+ }
+
+}
* The TYPO3 project - inspiring people to share!
*/
+use TYPO3\CMS\Core\Resource\ProcessedFileRepository;
+use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Install\Controller\Action;
use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Install\Status\ErrorStatus;
+use TYPO3\CMS\Install\Status\InfoStatus;
+use TYPO3\CMS\Install\Status\OkStatus;
/**
* Clean up page
if (isset($this->postValues['set']['resetBackendUserUc'])) {
$this->actionMessages[] = $this->resetBackendUserUc();
}
+ if (isset($this->postValues['set']['clearProcessedFiles'])) {
+ $this->actionMessages[] = $this->clearProcessedFiles();
+ }
$this->view->assign('cleanableTables', $this->getCleanableTableList());
}
}
if (count($clearedTables)) {
- /** @var \TYPO3\CMS\Install\Status\OkStatus $message */
- $message = $this->objectManager->get(\TYPO3\CMS\Install\Status\OkStatus::class);
+ /** @var OkStatus $message */
+ $message = $this->objectManager->get(OkStatus::class);
$message->setTitle('Cleared tables');
$message->setMessage('List of cleared tables: ' . implode(', ', $clearedTables));
} else {
- /** @var \TYPO3\CMS\Install\Status\OkStatus $message */
- $message = $this->objectManager->get(\TYPO3\CMS\Install\Status\InfoStatus::class);
+ /** @var InfoStatus $message */
+ $message = $this->objectManager->get(InfoStatus::class);
$message->setTitle('No tables selected to clear');
}
return $message;
protected function resetBackendUserUc() {
$database = $this->getDatabaseConnection();
$database->exec_UPDATEquery('be_users', '', array('uc' => ''));
- /** @var \TYPO3\CMS\Install\Status\OkStatus $message */
- $message = $this->objectManager->get(\TYPO3\CMS\Install\Status\OkStatus::class);
+ /** @var OkStatus $message */
+ $message = $this->objectManager->get(OkStatus::class);
$message->setTitle('Reset all backend users preferences');
return $message;
}
$ok = FALSE;
$fileCounter++;
if ($condition) {
- if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($condition)) {
+ if (MathUtility::canBeInterpretedAsInteger($condition)) {
if (filesize($absoluteFile) > $condition * 1024) {
$ok = TRUE;
}
$data['numberOfDeletedFiles'] = $deleteCounter;
if ($deleteCounter > 0) {
- $message = $this->objectManager->get(\TYPO3\CMS\Install\Status\OkStatus::class);
+ $message = $this->objectManager->get(OkStatus::class);
$message->setTitle('Deleted ' . $deleteCounter . ' files from typo3temp/' . $subDirectory . '/');
$this->actionMessages[] = $message;
}
return $data;
}
+ /**
+ * Clear processed files
+ *
+ * The sys_file_processedfile table is truncated and the physical files of local storages are deleted.
+ *
+ * @return \TYPO3\CMS\Install\Status\StatusInterface
+ */
+ protected function clearProcessedFiles() {
+ // make the DB available
+ $GLOBALS['TYPO3_DB'] = $this->getDatabaseConnection();
+
+ $repository = GeneralUtility::makeInstance(ProcessedFileRepository::class);
+ $failedDeletions = $repository->removeAll();
+ if ($failedDeletions) {
+ /** @var ErrorStatus $message */
+ $message = $this->objectManager->get(ErrorStatus::class);
+ $message->setTitle('Failed to delete ' . $failedDeletions . ' processed files. See TYPO3 log (by default typo3temp/logs/typo3.log)');
+ } else {
+ /** @var OkStatus $message */
+ $message = $this->objectManager->get(OkStatus::class);
+ $message->setTitle('Cleared processed files');
+ }
+
+ return $message;
+ }
+
}