[TASK] Add hook to upload methods in GeneralUtility 91/56591/2
authorFrank Naegler <frank.naegler@typo3.org>
Fri, 6 Apr 2018 15:07:17 +0000 (17:07 +0200)
committerAndreas Fernandez <a.fernandez@scripting-base.de>
Fri, 6 Apr 2018 15:19:02 +0000 (17:19 +0200)
Resolves: #84600
Releases: master, 8.7, 7.6
Change-Id: I3f4698e892c98aadb41d3e6ba4f1e974a2ca479d
Reviewed-on: https://review.typo3.org/56591
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
typo3/sysext/core/Classes/Utility/GeneralUtility.php

index 442addf..126049b 100644 (file)
@@ -4051,6 +4051,16 @@ class GeneralUtility
      */
     public static function upload_copy_move($source, $destination)
     {
+        if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['TYPO3\CMS\Core\Utility\GeneralUtility']['moveUploadedFile'])
+            && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['TYPO3\CMS\Core\Utility\GeneralUtility']['moveUploadedFile'])
+        ) {
+            $params = ['source' => $source, 'destination' => $destination, 'method' => 'upload_copy_move'];
+            foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['TYPO3\CMS\Core\Utility\GeneralUtility']['moveUploadedFile'] as $hookMethod) {
+                $fakeThis = false;
+                self::callUserFunction($hookMethod, $params, $fakeThis);
+            }
+        }
+
         if (is_uploaded_file($source)) {
             $uploaded = true;
             // Return the value of move_uploaded_file, and if FALSE the temporary $source is still around so the user can use unlink to delete it:
@@ -4078,6 +4088,16 @@ class GeneralUtility
     {
         if (is_uploaded_file($uploadedFileName)) {
             $tempFile = self::tempnam('upload_temp_');
+            if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['TYPO3\CMS\Core\Utility\GeneralUtility']['moveUploadedFile'])
+                && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['TYPO3\CMS\Core\Utility\GeneralUtility']['moveUploadedFile'])
+            ) {
+                $params = ['source' => $uploadedFileName, 'destination' => $tempFile, 'method' => 'upload_to_tempfile'];
+                foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['TYPO3\CMS\Core\Utility\GeneralUtility']['moveUploadedFile'] as $hookMethod) {
+                    $fakeThis = false;
+                    self::callUserFunction($hookMethod, $params, $fakeThis);
+                }
+            }
+
             move_uploaded_file($uploadedFileName, $tempFile);
             return @is_file($tempFile) ? $tempFile : '';
         }