[BUGFIX] Fix of .zip exports of extension 44/18344/2
authorJost Baron <jost.baron@gmx.de>
Sat, 16 Feb 2013 13:43:22 +0000 (14:43 +0100)
committerJigal van Hemert <jigal@xs4all.nl>
Sun, 17 Feb 2013 15:53:54 +0000 (16:53 +0100)
Before this, all files of an extension where included into its
.zip export. Now $TYPO3_CONF_VARS['EXT']['excludeForPackaging']
is respected.

Also the function responsible for the export is cleaned up and uses
more core API than before.

Change-Id: I1c06084e4da3ee18014563572fd270ea1e4d3ec5
Fixes: #45404
Releases: 6.0, 6.1
Reviewed-on: https://review.typo3.org/18344
Reviewed-by: Jigal van Hemert
Tested-by: Jigal van Hemert
typo3/sysext/extensionmanager/Classes/Utility/FileHandlingUtility.php

index ed5e768..9293bce 100644 (file)
@@ -337,23 +337,47 @@ class FileHandlingUtility implements \TYPO3\CMS\Core\SingletonInterface {
         * Create a zip file from an extension
         *
         * @param array $extension
-        * @return string
+        * @return string Name and path of create zip file
         */
        public function createZipFileFromExtension($extension) {
+
                $extensionPath = $this->getAbsoluteExtensionPath($extension);
+
+               // Add trailing slash to the extension path, getAllFilesAndFoldersInPath explicitly requires that.
+               $extensionPath = \TYPO3\CMS\Core\Utility\PathUtility::sanitizeTrailingSeparator($extensionPath);
+
                $version = $this->getExtensionVersion($extension);
+               if (empty($version)) {
+                       $version =  '0.0.0';
+               }
+
                $fileName = $this->getAbsolutePath('typo3temp/' . $extension . '_' . $version . '.zip');
+
                $zip = new \ZipArchive();
                $zip->open($fileName, \ZipArchive::CREATE);
-               $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($extensionPath));
-               foreach ($iterator as $key => $value) {
-                       $archiveName = str_replace($extensionPath, '', $key);
-                       if (\TYPO3\CMS\Core\Utility\StringUtility::isLastPartOfString($key, '.')) {
-                               continue;
-                       } else {
-                               $zip->addFile($key, $archiveName);
-                       }
+
+               $excludePattern = $GLOBALS['TYPO3_CONF_VARS']['EXT']['excludeForPackaging'];
+
+               // Get all the files of the extension, but exclude the ones specified in the excludePattern
+               $files = \TYPO3\CMS\Core\Utility\GeneralUtility::getAllFilesAndFoldersInPath(
+                       array(),                        // No files pre-added
+                       $extensionPath,         // Start from here
+                       '',                                     // Do not filter files by extension
+                       TRUE,                           // Include subdirectories
+                       PHP_INT_MAX,            // Recursion level
+                       $excludePattern         // Files and directories to exclude.
+               );
+
+               // Make paths relative to extension root directory.
+               $files = \TYPO3\CMS\Core\Utility\GeneralUtility::removePrefixPathFromList($files, $extensionPath);
+
+               // Remove the one empty path that is the extension dir itself.
+               $files = array_filter($files);
+
+               foreach ($files as $file) {
+                       $zip->addFile($extensionPath . $file, $file);
                }
+
                $zip->close();
                return $fileName;
        }