TYPO3 CMS  TYPO3_6-2
FileDeletionAspect.php
Go to the documentation of this file.
1 <?php
3 
21 
32 
38  protected function getFileIndexRepository() {
39  return GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Index\\FileIndexRepository');
40  }
41 
47  protected function getMetaDataRepository() {
48  return GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Index\\MetaDataRepository');
49  }
50 
56  protected function getProcessedFileRepository() {
57  return GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\ProcessedFileRepository');
58  }
59 
65  protected function getDatabaseConnection() {
66  return $GLOBALS['TYPO3_DB'];
67  }
68 
75  public function removeFromRepository(FileInterface $fileObject) {
76  // remove file from repository
77  if ($fileObject instanceof File) {
78  $this->cleanupProcessedFiles($fileObject);
79  $this->cleanupCategoryReferences($fileObject);
80  $this->getFileIndexRepository()->remove($fileObject->getUid());
81  $this->getMetaDataRepository()->removeByFileUid($fileObject->getUid());
82 
83  // remove all references
84  $this->getDatabaseConnection()->exec_DELETEquery(
85  'sys_file_reference',
86  'uid_local=' . (int)$fileObject->getUid() . ' AND table_local = \'sys_file\''
87  );
88 
89  } elseif ($fileObject instanceof ProcessedFile) {
90  $this->getDatabaseConnection()->exec_DELETEquery('sys_file_processedfile', 'uid=' . (int)$fileObject->getUid());
91  }
92  }
93 
100  public function cleanupProcessedFilesPostFileAdd(FileInterface $file, $targetFolder) {
101  $this->cleanupProcessedFiles($file);
102  }
103 
110  public function cleanupProcessedFilesPostFileReplace(FileInterface $file, $localFilePath) {
111  $this->cleanupProcessedFiles($file);
112  }
113 
120  protected function cleanupCategoryReferences(File $fileObject) {
121 
122  // Retrieve the file metadata uid which is different from the file uid.
123  $metadataProperties = $fileObject->_getMetaData();
124 
125  $metaDataUid = isset($metadataProperties['_ORIG_uid']) ? $metadataProperties['_ORIG_uid'] : $metadataProperties['uid'];
126  $this->getDatabaseConnection()->exec_DELETEquery(
127  'sys_category_record_mm',
128  'uid_foreign=' . (int)$metaDataUid . ' AND tablenames = \'sys_file_metadata\''
129  );
130  }
131 
138  protected function cleanupProcessedFiles(FileInterface $fileObject) {
139 
140  // only delete processed files of File objects
141  if (!$fileObject instanceof File) {
142  return;
143  }
144 
146  foreach ($this->getProcessedFileRepository()->findAllByOriginalFile($fileObject) as $processedFile) {
147  if ($processedFile->exists()) {
148  $processedFile->delete(TRUE);
149  }
150  $this->removeFromRepository($processedFile);
151  }
152  }
153 }
cleanupProcessedFilesPostFileReplace(FileInterface $file, $localFilePath)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
cleanupProcessedFilesPostFileAdd(FileInterface $file, $targetFolder)