[FEATURE] ext:install Implement template files in FolderStructure 22/24122/5
authorChristian Kuhn <lolli@schwarzbu.ch>
Sat, 28 Sep 2013 10:57:22 +0000 (12:57 +0200)
committerSusanne Moog <typo3@susannemoog.de>
Sat, 28 Sep 2013 13:39:39 +0000 (15:39 +0200)
The folder structure definition can be simplified a bit if target
content of files is not stored in the structure definition array
but moved to template files. This also enables handling of binary
files.
The patch implements an option 'targetContentFile' to FileNode and
adapts the current FolderStructure definition to use it.

Change-Id: I097e87a1f7a16e325b398468286fe661abec3553
Resolves: #52351
Releases: 6.2
Reviewed-on: https://review.typo3.org/24122
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Susanne Moog
Tested-by: Susanne Moog
typo3/sysext/install/Classes/FolderStructure/DefaultFactory.php
typo3/sysext/install/Classes/FolderStructure/FileNode.php
typo3/sysext/install/Resources/Private/.htaccess [new file with mode: 0644]
typo3/sysext/install/Resources/Private/FolderStructureTemplateFiles/fileadmin-temp-htaccess [new file with mode: 0644]
typo3/sysext/install/Resources/Private/FolderStructureTemplateFiles/fileadmin-temp-index.html [new file with mode: 0644]
typo3/sysext/install/Resources/Private/FolderStructureTemplateFiles/uploads-index.html [new file with mode: 0644]
typo3/sysext/install/Tests/Unit/FolderStructure/FileNodeTest.php

index 590efb8..1cbb437 100644 (file)
@@ -153,14 +153,7 @@ class DefaultFactory {
                                                        'name' => 'index.html',
                                                        'type' => 'TYPO3\\CMS\\install\\FolderStructure\\FileNode',
                                                        'targetPermission' => $filePermission,
-                                                       'targetContent' =>
-                                                               '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">' . LF .
-                                                               '<HTML>' . LF .
-                                                               '<HEAD>' . LF .
-                                                               TAB . '<TITLE></TITLE>' . LF .
-                                                               '<META http-equiv=Refresh Content="0; Url=../">' . LF .
-                                                               '</HEAD>' . LF .
-                                                               '</HTML>',
+                                                       'targetContentFile' => PATH_site . 'typo3/sysext/install/Resources/Private/FolderStructureTemplateFiles/uploads-index.html',
                                                ),
                                                array(
                                                        'name' => 'media',
@@ -217,26 +210,13 @@ class DefaultFactory {
                                                                        'name' => '.htaccess',
                                                                        'type' => 'TYPO3\\CMS\\install\\FolderStructure\\FileNode',
                                                                        '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 .
-                                                                               '# information. Please do not touch.' . LF .
-                                                                               LF .
-                                                                               'Order deny,allow' . LF .
-                                                                               'Deny from all' . LF,
+                                                                       'targetContentFile' => PATH_site . 'typo3/sysext/install/Resources/Private/FolderStructureTemplateFiles/fileadmin-temp-htaccess',
                                                                ),
                                                                array(
                                                                        'name' => 'index.html',
                                                                        'type' => 'TYPO3\\CMS\\install\\FolderStructure\\FileNode',
                                                                        'targetPermission' => $filePermission,
-                                                                       'targetContent' =>
-                                                                               '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">' . LF .
-                                                                               '<HTML>' . LF .
-                                                                               '<HEAD>' . LF .
-                                                                               TAB . '<TITLE></TITLE>' . LF .
-                                                                               '<META http-equiv=Refresh Content="0; Url=/">' . LF .
-                                                                               '</HEAD>' . LF .
-                                                                               '</HTML>',
+                                                                       'targetContentFile' => PATH_site . 'typo3/sysext/install/Resources/Private/FolderStructureTemplateFiles/fileadmin-temp-index.html',
                                                                ),
                                                        ),
                                                ),
@@ -271,6 +251,5 @@ class DefaultFactory {
                        ),
                );
        }
-
 }
 ?>
\ No newline at end of file
index 4743330..e633356 100644 (file)
@@ -70,9 +70,25 @@ class FileNode extends AbstractNode implements NodeInterface {
                        $this->targetPermission = $structure['targetPermission'];
                }
 
+               if (isset($structure['targetContent']) && isset($structure['targetContentFile'])) {
+                       throw new \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException(
+                               'Either targetContent or targetContentFile can be set, but not both',
+                               1380364361
+                       );
+               }
+
                if (isset($structure['targetContent'])) {
                        $this->targetContent = $structure['targetContent'];
                }
+               if (isset($structure['targetContentFile'])) {
+                       if (!is_readable($structure['targetContentFile'])) {
+                               throw new \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException(
+                                       'targetContentFile ' . $structure['targetContentFile'] . ' does not exist or is not readable',
+                                       1380364362
+                               );
+                       }
+                       $this->targetContent = file_get_contents($structure['targetContentFile']);
+               }
        }
 
        /**
diff --git a/typo3/sysext/install/Resources/Private/.htaccess b/typo3/sysext/install/Resources/Private/.htaccess
new file mode 100644 (file)
index 0000000..3418e55
--- /dev/null
@@ -0,0 +1 @@
+deny from all
\ No newline at end of file
diff --git a/typo3/sysext/install/Resources/Private/FolderStructureTemplateFiles/fileadmin-temp-htaccess b/typo3/sysext/install/Resources/Private/FolderStructureTemplateFiles/fileadmin-temp-htaccess
new file mode 100644 (file)
index 0000000..b26e123
--- /dev/null
@@ -0,0 +1,6 @@
+# This file restricts access to the fileadmin/_temp_ directory. It is
+# meant to protect temporary files which could contain sensible
+# information. Please do not touch.
+
+Order deny,allow
+Deny from all
diff --git a/typo3/sysext/install/Resources/Private/FolderStructureTemplateFiles/fileadmin-temp-index.html b/typo3/sysext/install/Resources/Private/FolderStructureTemplateFiles/fileadmin-temp-index.html
new file mode 100644 (file)
index 0000000..ee50c6a
--- /dev/null
@@ -0,0 +1,7 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<HTML>
+<HEAD>
+       <TITLE></TITLE>
+<META http-equiv=Refresh Content="0; Url=/">
+</HEAD>
+</HTML>
\ No newline at end of file
diff --git a/typo3/sysext/install/Resources/Private/FolderStructureTemplateFiles/uploads-index.html b/typo3/sysext/install/Resources/Private/FolderStructureTemplateFiles/uploads-index.html
new file mode 100644 (file)
index 0000000..d44be3d
--- /dev/null
@@ -0,0 +1,7 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<HTML>
+<HEAD>
+       <TITLE></TITLE>
+<META http-equiv=Refresh Content="0; Url=../">
+</HEAD>
+</HTML>
\ No newline at end of file
index a254905..703ac35 100644 (file)
@@ -113,6 +113,22 @@ class FileNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 
        /**
         * @test
+        * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
+        */
+       public function constructorThrowsExceptionIfBothTargetContentAndTargetContentFileAreSet() {
+               /** @var $node \TYPO3\CMS\Install\FolderStructure\FileNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
+               $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('dummy'), array(), '', FALSE);
+               $parent = $this->getMock('TYPO3\CMS\Install\FolderStructure\RootNodeInterface', array(), array(), '', FALSE);
+               $structure = array(
+                       'name' => 'foo',
+                       'targetContent' => 'foo',
+                       'targetContentFile' => 'aPath',
+               );
+               $node->__construct($structure, $parent);
+       }
+
+       /**
+        * @test
         */
        public function constructorSetsTargetContent() {
                /** @var $node \TYPO3\CMS\Install\FolderStructure\FileNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
@@ -130,6 +146,41 @@ class FileNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        /**
         * @test
         */
+       public function constructorSetsTargetContentToContentOfTargetContentFile() {
+               /** @var $node \TYPO3\CMS\Install\FolderStructure\FileNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
+               $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('dummy'), array(), '', FALSE);
+               $parent = $this->getMock('TYPO3\CMS\Install\FolderStructure\RootNodeInterface', array(), array(), '', FALSE);
+               $targetFile = PATH_site . 'typo3temp/' . uniqid('test_');
+               $targetContent = uniqid('content_');
+               file_put_contents($targetFile, $targetContent);
+               $this->testNodesToDelete[] = $targetFile;
+               $structure = array(
+                       'name' => 'foo',
+                       'targetContentFile' => $targetFile,
+               );
+               $node->__construct($structure, $parent);
+               $this->assertSame($targetContent, $node->_get('targetContent'));
+       }
+
+       /**
+        * @test
+        * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
+        */
+       public function constructorThrowsExceptionIfTargetContentFileDoesNotExist() {
+               /** @var $node \TYPO3\CMS\Install\FolderStructure\FileNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
+               $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('dummy'), array(), '', FALSE);
+               $parent = $this->getMock('TYPO3\CMS\Install\FolderStructure\RootNodeInterface', array(), array(), '', FALSE);
+               $targetFile = PATH_site . 'typo3temp/' . uniqid('test_');
+               $structure = array(
+                       'name' => 'foo',
+                       'targetContentFile' => $targetFile,
+               );
+               $node->__construct($structure, $parent);
+       }
+
+       /**
+        * @test
+        */
        public function targetContentIsNullIfNotGiven() {
                /** @var $node \TYPO3\CMS\Install\FolderStructure\FileNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
                $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('dummy'), array(), '', FALSE);
@@ -723,3 +774,4 @@ class FileNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $this->assertFalse($node->_call('isFile'));
        }
 }
+?>
\ No newline at end of file