[TASK] Use resource API to deleted files from uploads in DataHandler 88/36488/2
authorMarc Bastian Heinrichs <typo3@mbh-software.de>
Sat, 21 Jun 2014 13:49:34 +0000 (15:49 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sat, 31 Jan 2015 10:51:38 +0000 (11:51 +0100)
The DataHandler deletes files from the uploads folder. Since also a
sys_file record could exist for such file, the resource API should be
used to delete it.

Resolves: #58967
Releases: master, 6.2
Change-Id: I6c0b3683657e1c4da5f9ab0a2016e33b1e472f62
Reviewed-on: http://review.typo3.org/36488
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Classes/DataHandling/DataHandler.php

index a21f352..4637e9e 100644 (file)
@@ -4441,7 +4441,8 @@ class DataHandler {
                if (is_array($files) && $dsArr['TCEforms']['config']['internal_type'] === 'file') {
                        foreach ($files as $dat) {
                                if (@is_file($dat['ID_absFile'])) {
-                                       unlink($dat['ID_absFile']);
+                                       $file = $this->getResourceFactory()->retrieveFileOrFolderObject($dat['ID_absFile']);
+                                       $file->delete();
                                } else {
                                        $this->log('', 0, 3, 0, 100, 'Delete: Referenced file \'' . $dat['ID_absFile'] . '\' that was supposed to be deleted together with its record which didn\'t exist');
                                }
@@ -6636,7 +6637,10 @@ class DataHandler {
         */
        public function removeRegisteredFiles() {
                foreach ($this->removeFilesStore as $file) {
-                       unlink($file);
+                       if (@is_file($file)) {
+                               $file = $this->getResourceFactory()->retrieveFileOrFolderObject($file);
+                               $file->delete();
+                       }
                }
        }
 
@@ -6920,8 +6924,10 @@ class DataHandler {
                                if ($theFile) {
                                        switch ($func) {
                                                case 'deleteAll':
-                                                       if (@is_file(($uploadPath . '/' . $theFile))) {
-                                                               unlink($uploadPath . '/' . $theFile);
+                                                       $theFileFullPath = $uploadPath . '/' . $theFile;
+                                                       if (@is_file($theFileFullPath)) {
+                                                               $file = $this->getResourceFactory()->retrieveFileOrFolderObject($theFileFullPath);
+                                                               $file->delete();
                                                        } else {
                                                                $this->log($table, 0, 3, 0, 100, 'Delete: Referenced file that was supposed to be deleted together with it\'s record didn\'t exist');
                                                        }
@@ -7634,4 +7640,13 @@ class DataHandler {
        protected function getCacheManager() {
                return GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager');
        }
+
+       /**
+        * Gets the resourceFactory
+        * @return ResourceFactory
+        */
+       protected function getResourceFactory() {
+               return \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance();
+       }
+
 }