[TASK] Use resource API to deleted files from uploads in DataHandler 01/31001/6
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:34:03 +0000 (11:34 +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/31001
Reviewed-by: Michael Oehlhof <typo3@oehlhof.de>
Reviewed-by: Philipp Gampe <philipp.gampe@typo3.org>
Reviewed-by: Frans Saris <franssaris@gmail.com>
Tested-by: Frans Saris <franssaris@gmail.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Classes/DataHandling/DataHandler.php

index 86c7ece..aa0c373 100644 (file)
@@ -4415,7 +4415,8 @@ class DataHandler {
                if (is_array($files) && $dsArr['TCEforms']['config']['internal_type'] === 'file') {
                        foreach ($files as $dat) {
                                if (@is_file($dat['ID_absFile'])) {
                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');
                                }
                                } 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');
                                }
@@ -6562,7 +6563,10 @@ class DataHandler {
         */
        public function removeRegisteredFiles() {
                foreach ($this->removeFilesStore as $file) {
         */
        public function removeRegisteredFiles() {
                foreach ($this->removeFilesStore as $file) {
-                       unlink($file);
+                       if (@is_file($file)) {
+                               $file = $this->getResourceFactory()->retrieveFileOrFolderObject($file);
+                               $file->delete();
+                       }
                }
        }
 
                }
        }
 
@@ -6811,8 +6815,10 @@ class DataHandler {
                                if ($theFile) {
                                        switch ($func) {
                                                case 'deleteAll':
                                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');
                                                        }
                                                        } 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');
                                                        }
@@ -7474,4 +7480,11 @@ class DataHandler {
                return GeneralUtility::makeInstance(CacheManager::class);
        }
 
                return GeneralUtility::makeInstance(CacheManager::class);
        }
 
+       /**
+        * Gets the resourceFactory
+        * @return ResourceFactory
+        */
+       protected function getResourceFactory() {
+               return \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance();
+       }
 }
 }