[BUGFIX] Folder structure honors file and folderCreateMask
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / FolderStructure / DefaultFactory.php
index 7a9375f..590efb8 100644 (file)
@@ -30,103 +30,129 @@ namespace TYPO3\CMS\Install\FolderStructure;
 class DefaultFactory {
 
        /**
-        * @var array Expected folder structure
+        * Get default structure object hierarchy
+        *
+        * @throws Exception
+        * @return RootNode
+        * @TODO: Use objectManager instead of new (will be injected)
         */
-       protected $expectedDefaultStructure = array();
+       public function getStructure() {
+               $rootNode = new RootNode($this->getDefaultStructureDefinition(), NULL);
+               if (!($rootNode instanceof RootNodeInterface)) {
+                       throw new Exception(
+                               'Root node must implement RootNodeInterface',
+                               1366139176
+                       );
+               }
+               $structureFacade = new StructureFacade($rootNode);
+               if (!($structureFacade instanceof StructureFacadeInterface)) {
+                       throw new Exception(
+                               'Structure facade must implement StructureFacadeInterface',
+                               1366535827
+                       );
+               }
+               return $structureFacade;
+       }
 
        /**
-        * Constructor
+        * Default definition of folder and file structure with dynamic
+        * permission settings
+        *
+        * @return array
         */
-       public function __construct() {
-               $this->expectedDefaultStructure = array(
+       protected function getDefaultStructureDefinition() {
+               $filePermission = $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'];
+               $directoryPermission = $GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'];
+
+               return array(
                        // Cut off trailing forward / from PATH_site, so root node has no trailing slash like all others
                        'name' => substr(PATH_site, 0, -1),
-                       'targetPermission' => '2770',
+                       'targetPermission' => $directoryPermission,
                        'children' => array(
                                array(
                                        'name' => 'typo3temp',
                                        'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
-                                       'targetPermission' => '2770',
+                                       'targetPermission' => $directoryPermission,
                                        'children' => array(
                                                array(
                                                        'name' => 'index.html',
                                                        'type' => 'TYPO3\\CMS\\install\\FolderStructure\\FileNode',
-                                                       'targetPermission' => '0660',
+                                                       'targetPermission' => $filePermission,
                                                        'targetContent' => '',
                                                ),
                                                array(
                                                        'name' => 'compressor',
                                                        'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
-                                                       'targetPermission' => '2770',
+                                                       'targetPermission' => $directoryPermission,
                                                ),
                                                array(
                                                        'name' => 'cs',
                                                        'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
-                                                       'targetPermission' => '2770',
+                                                       'targetPermission' => $directoryPermission,
                                                ),
                                                array(
                                                        'name' => 'Cache',
                                                        'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
-                                                       'targetPermission' => '2770',
+                                                       'targetPermission' => $directoryPermission,
                                                ),
                                                array(
                                                        'name' => 'GB',
                                                        'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
-                                                       'targetPermission' => '2770',
+                                                       'targetPermission' => $directoryPermission,
                                                ),
                                                array(
                                                        'name' => 'llxml',
                                                        'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
-                                                       'targetPermission' => '2770',
+                                                       'targetPermission' => $directoryPermission,
                                                ),
                                                array(
                                                        'name' => 'locks',
                                                        'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
-                                                       'targetPermission' => '2770',
+                                                       'targetPermission' => $directoryPermission,
                                                ),
                                                array(
                                                        'name' => 'pics',
                                                        'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
-                                                       'targetPermission' => '2770',
+                                                       'targetPermission' => $directoryPermission,
                                                ),
                                                array(
                                                        'name' => 'sprites',
                                                        'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
-                                                       'targetPermission' => '2770',
+                                                       'targetPermission' => $directoryPermission,
                                                ),
                                                array(
                                                        'name' => 'temp',
                                                        'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
-                                                       'targetPermission' => '2770',
+                                                       'targetPermission' => $directoryPermission,
                                                ),
                                        ),
                                ),
                                array(
                                        'name' => 'typo3conf',
                                        'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
-                                       'targetPermission' => '2770',
+                                       'targetPermission' => $directoryPermission,
                                        'children' => array(
                                                array(
                                                        'name' => 'ext',
                                                        'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
-                                                       'targetPermission' => '2770',
+                                                       'targetPermission' => $directoryPermission,
                                                ),
                                                array(
                                                        'name' => 'l10n',
                                                        'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
-                                                       'targetPermission' => '2770',
+                                                       'targetPermission' => $directoryPermission,
                                                ),
                                        ),
                                ),
                                array(
                                        'name' => 'uploads',
                                        'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
-                                       'targetPermission' => '2770',
+                                       'targetPermission' => $directoryPermission,
                                        'children' => array(
                                                array(
                                                        'name' => 'index.html',
                                                        'type' => 'TYPO3\\CMS\\install\\FolderStructure\\FileNode',
-                                                       'targetPermission' => '0660',
+                                                       'targetPermission' => $filePermission,
                                                        'targetContent' =>
                                                                '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">' . LF .
                                                                '<HTML>' . LF .
@@ -139,12 +165,12 @@ class DefaultFactory {
                                                array(
                                                        'name' => 'media',
                                                        'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
-                                                       'targetPermission' => '2770',
+                                                       'targetPermission' => $directoryPermission,
                                                        'children' => array(
                                                                array(
                                                                        'name' => 'index.html',
                                                                        'type' => 'TYPO3\\CMS\\install\\FolderStructure\\FileNode',
-                                                                       'targetPermission' => '0660',
+                                                                       'targetPermission' => $filePermission,
                                                                        'targetContent' => '',
                                                                ),
                                                        ),
@@ -152,12 +178,12 @@ class DefaultFactory {
                                                array(
                                                        'name' => 'pics',
                                                        'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
-                                                       'targetPermission' => '2770',
+                                                       'targetPermission' => $directoryPermission,
                                                        'children' => array(
                                                                array(
                                                                        'name' => 'index.html',
                                                                        'type' => 'TYPO3\\CMS\\install\\FolderStructure\\FileNode',
-                                                                       'targetPermission' => '0660',
+                                                                       'targetPermission' => $filePermission,
                                                                        'targetContent' => '',
                                                                ),
                                                        ),
@@ -165,12 +191,12 @@ class DefaultFactory {
                                                array(
                                                        'name' => 'tf',
                                                        'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
-                                                       'targetPermission' => '2770',
+                                                       'targetPermission' => $directoryPermission,
                                                        'children' => array(
                                                                array(
                                                                        'name' => 'index.html',
                                                                        'type' => 'TYPO3\\CMS\\install\\FolderStructure\\FileNode',
-                                                                       'targetPermission' => '0660',
+                                                                       'targetPermission' => $filePermission,
                                                                        'targetContent' => '',
                                                                ),
                                                        ),
@@ -180,17 +206,17 @@ class DefaultFactory {
                                array(
                                        'name' => 'fileadmin',
                                        'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
-                                       'targetPermission' => '2770',
+                                       'targetPermission' => $directoryPermission,
                                        'children' => array(
                                                array(
                                                        'name' => '_temp_',
                                                        'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
-                                                       'targetPermission' => '2770',
+                                                       'targetPermission' => $directoryPermission,
                                                        'children' => array(
                                                                array(
                                                                        'name' => '.htaccess',
                                                                        'type' => 'TYPO3\\CMS\\install\\FolderStructure\\FileNode',
-                                                                       'targetPermission' => '0660',
+                                                                       'targetPermission' => $filePermission,
                                                                        'targetContent' =>
                                                                                '# This file restricts access to the fileadmin/_temp_ directory. It is' . LF .
                                                                                '# meant to protect temporary files which could contain sensible' . LF .
@@ -202,7 +228,7 @@ class DefaultFactory {
                                                                array(
                                                                        'name' => 'index.html',
                                                                        'type' => 'TYPO3\\CMS\\install\\FolderStructure\\FileNode',
-                                                                       'targetPermission' => '0660',
+                                                                       'targetPermission' => $filePermission,
                                                                        'targetContent' =>
                                                                                '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">' . LF .
                                                                                '<HTML>' . LF .
@@ -217,17 +243,17 @@ class DefaultFactory {
                                                array(
                                                        'name' => 'user_upload',
                                                        'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
-                                                       'targetPermission' => '2770',
+                                                       'targetPermission' => $directoryPermission,
                                                        'children' => array(
                                                                array(
                                                                        'name' => '_temp_',
                                                                        'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
-                                                                       'targetPermission' => '2770',
+                                                                       'targetPermission' => $directoryPermission,
                                                                        'children' => array(
                                                                                array(
                                                                                        'name' => 'index.html',
                                                                                        'type' => 'TYPO3\\CMS\\install\\FolderStructure\\FileNode',
-                                                                                       'targetPermission' => '0660',
+                                                                                       'targetPermission' => $filePermission,
                                                                                        'targetContent' => '',
                                                                                ),
                                                                        ),
@@ -235,7 +261,7 @@ class DefaultFactory {
                                                                array(
                                                                        'name' => 'index.html',
                                                                        'type' => 'TYPO3\\CMS\\install\\FolderStructure\\FileNode',
-                                                                       'targetPermission' => '0660',
+                                                                       'targetPermission' => $filePermission,
                                                                        'targetContent' => '',
                                                                ),
                                                        ),
@@ -246,30 +272,5 @@ class DefaultFactory {
                );
        }
 
-       /**
-        * Get default structure object hierarchy
-        *
-        * @throws Exception
-        * @return RootNode
-        * @TODO: Use objectManager instead of new (will be injected)
-        * @TODO: Handle targetPermission for files / directory if set in TYPO3_CONF_VARS
-        */
-       public function getStructure() {
-               $rootNode = new RootNode($this->expectedDefaultStructure, NULL);
-               if (!($rootNode instanceof RootNodeInterface)) {
-                       throw new Exception(
-                               'Root node must implement RootNodeInterface',
-                               1366139176
-                       );
-               }
-               $structureFacade = new StructureFacade($rootNode);
-               if (!($structureFacade instanceof StructureFacadeInterface)) {
-                       throw new Exception(
-                               'Structure facade must implement StructureFacadeInterface',
-                               1366535827
-                       );
-               }
-               return $structureFacade;
-       }
 }
 ?>
\ No newline at end of file