TYPO3 CMS  TYPO3_7-6
FileDeletionAspect.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 
32 {
38  protected function getFileIndexRepository()
39  {
40  return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\Index\FileIndexRepository::class);
41  }
42 
48  protected function getMetaDataRepository()
49  {
50  return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\Index\MetaDataRepository::class);
51  }
52 
58  protected function getProcessedFileRepository()
59  {
60  return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\ProcessedFileRepository::class);
61  }
62 
68  protected function getDatabaseConnection()
69  {
70  return $GLOBALS['TYPO3_DB'];
71  }
72 
79  public function removeFromRepository(FileInterface $fileObject)
80  {
81  // remove file from repository
82  if ($fileObject instanceof File) {
83  $this->cleanupProcessedFiles($fileObject);
84  $this->cleanupCategoryReferences($fileObject);
85  $this->getFileIndexRepository()->remove($fileObject->getUid());
86  $this->getMetaDataRepository()->removeByFileUid($fileObject->getUid());
87 
88  // remove all references
89  $this->getDatabaseConnection()->exec_DELETEquery(
90  'sys_file_reference',
91  'uid_local=' . (int)$fileObject->getUid() . ' AND table_local = \'sys_file\''
92  );
93  } elseif ($fileObject instanceof ProcessedFile) {
94  $this->getDatabaseConnection()->exec_DELETEquery('sys_file_processedfile', 'uid=' . (int)$fileObject->getUid());
95  }
96  }
97 
104  public function cleanupProcessedFilesPostFileAdd(FileInterface $file, $targetFolder)
105  {
106  $this->cleanupProcessedFiles($file);
107  }
108 
115  public function cleanupProcessedFilesPostFileReplace(FileInterface $file, $localFilePath)
116  {
117  $this->cleanupProcessedFiles($file);
118  }
119 
126  protected function cleanupCategoryReferences(File $fileObject)
127  {
128 
129  // Retrieve the file metadata uid which is different from the file uid.
130  $metadataProperties = $fileObject->_getMetaData();
131 
132  $metaDataUid = isset($metadataProperties['_ORIG_uid']) ? $metadataProperties['_ORIG_uid'] : $metadataProperties['uid'];
133  $this->getDatabaseConnection()->exec_DELETEquery(
134  'sys_category_record_mm',
135  'uid_foreign=' . (int)$metaDataUid . ' AND tablenames = \'sys_file_metadata\''
136  );
137  }
138 
145  protected function cleanupProcessedFiles(FileInterface $fileObject)
146  {
147 
148  // only delete processed files of File objects
149  if (!$fileObject instanceof File) {
150  return;
151  }
152 
154  foreach ($this->getProcessedFileRepository()->findAllByOriginalFile($fileObject) as $processedFile) {
155  if ($processedFile->exists()) {
156  $processedFile->delete(true);
157  }
158  $this->removeFromRepository($processedFile);
159  }
160  }
161 }
cleanupProcessedFilesPostFileReplace(FileInterface $file, $localFilePath)
cleanupProcessedFilesPostFileAdd(FileInterface $file, $targetFolder)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']