[!!!][TASK] Cleanup and remove old filefunc logic
[Packages/TYPO3.CMS.git] / typo3 / sysext / impexp / Classes / ImportExport.php
index bcfa8f2..b6d3861 100644 (file)
@@ -16,9 +16,10 @@ namespace TYPO3\CMS\Impexp;
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
-use TYPO3\CMS\Core\Database\DatabaseConnection;
 use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Imaging\IconFactory;
+use TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException;
+use TYPO3\CMS\Core\Resource\ResourceFactory;
 use TYPO3\CMS\Core\Utility\DebugUtility;
 use TYPO3\CMS\Core\Utility\DiffUtility;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
@@ -940,26 +941,22 @@ abstract class ImportExport
      */
     public function verifyFolderAccess($dirPrefix, $noAlternative = false)
     {
-        $fileProcObj = $this->getFileProcObj();
-        // Check, if dirPrefix is inside a valid Filemount for user:
-        $result = $fileProcObj->checkPathAgainstMounts(PATH_site . $dirPrefix);
-        // If not, try to find another relative filemount and use that instead:
-        if (!$result) {
-            if ($noAlternative) {
-                return false;
-            }
-            // Find first web folder:
-            $result = $fileProcObj->findFirstWebFolder();
-            // If that succeeded, return the path to it:
-            if ($result) {
-                // Remove the "fileadmin/" prefix of input path - and append the rest to the return value:
-                if (GeneralUtility::isFirstPartOfStr($dirPrefix, $this->fileadminFolderName . '/')) {
-                    $dirPrefix = substr($dirPrefix, strlen($this->fileadminFolderName . '/'));
+        // Check the absolute path for PATH_site, if the user has access - no problem
+        try {
+            ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($dirPrefix);
+            return $dirPrefix;
+        } catch (InsufficientFolderAccessPermissionsException $e) {
+            // Check all storages available for the user as alternative
+            if (!$noAlternative) {
+                $fileStorages = $this->getBackendUser()->getFileStorages();
+                foreach ($fileStorages as $fileStorage) {
+                    try {
+                        $folder = $fileStorage->getFolder(rtrim($dirPrefix, '/'));
+                        return $folder->getPublicUrl();
+                    } catch (InsufficientFolderAccessPermissionsException $e) {
+                    }
                 }
-                return PathUtility::stripPathSitePrefix($fileProcObj->mounts[$result]['path'] . $dirPrefix);
             }
-        } else {
-            return $dirPrefix;
         }
         return false;
     }
@@ -1217,7 +1214,6 @@ abstract class ImportExport
     {
         if ($this->fileProcObj === null) {
             $this->fileProcObj = GeneralUtility::makeInstance(ExtendedFileUtility::class);
-            $this->fileProcObj->init(array(), $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
             $this->fileProcObj->setActionPermissions();
         }
         return $this->fileProcObj;
@@ -1286,14 +1282,6 @@ abstract class ImportExport
     }
 
     /**
-     * @return DatabaseConnection
-     */
-    protected function getDatabaseConnection()
-    {
-        return $GLOBALS['TYPO3_DB'];
-    }
-
-    /**
      * @return LanguageService
      */
     protected function getLanguageService()