[TASK] Move publicly accessible files to typo3temp/assets/ 69/45669/8
authorBenni Mack <benni@typo3.org>
Thu, 7 Jan 2016 22:29:23 +0000 (23:29 +0100)
committerMarkus Klein <markus.klein@typo3.org>
Fri, 8 Jan 2016 16:46:50 +0000 (17:46 +0100)
New folder structure is given which contains all files
(images, css, js) which need to be accessible for the
web client.

Also, the folders have been named properly:
- typo3temp/pics/ is now typo3temp/images/
- The typo3temp/temp/ directory which was previously
used for storing temporary images when doing complex
image masking etc. is now named
typo3temp/assets/transient/ which also contains some
volatile files when creating online media records before
FAL processes the file.

Resolves: #72580
Releases: master
Change-Id: I77f49152f09139fc1e42bc1a0ffab101022af43d
Reviewed-on: https://review.typo3.org/45669
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
18 files changed:
typo3/sysext/backend/Classes/Controller/BackendController.php
typo3/sysext/backend/Classes/Controller/EditDocumentController.php
typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
typo3/sysext/core/Classes/Resource/OnlineMedia/Helpers/AbstractOnlineMediaHelper.php
typo3/sysext/core/Classes/Resource/OnlineMedia/Processing/PreviewProcessing.php
typo3/sysext/core/Classes/Resource/ResourceCompressor.php
typo3/sysext/core/Classes/Resource/ResourceFactory.php
typo3/sysext/core/Documentation/Changelog/master/Important-72580-PubliclyAccessibleGeneratedAssetFilesMovedToTypo3tempassets.rst [new file with mode: 0644]
typo3/sysext/fluid/Classes/ViewHelpers/ImageViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Uri/ImageViewHelper.php
typo3/sysext/frontend/Classes/Imaging/GifBuilder.php
typo3/sysext/frontend/Classes/Page/PageGenerator.php
typo3/sysext/install/Classes/Controller/Action/Ajax/ExtensionCompatibilityTester.php
typo3/sysext/install/Classes/FolderStructure/DefaultFactory.php
typo3/sysext/install/Classes/Report/InstallStatusReport.php
typo3/sysext/install/Tests/Unit/Controller/Action/Ajax/ExtensionCompatibilityTesterTest.php
typo3/sysext/rtehtmlarea/Classes/Form/Element/RichTextElement.php
typo3/sysext/rtehtmlarea/Classes/RteHtmlAreaApi.php

index 6c5cb89..9bdb322 100644 (file)
@@ -447,7 +447,7 @@ class BackendController
     protected function getLocalLangFileName()
     {
         $code = $this->generateLocalLang();
-        $filePath = 'typo3temp/Language/Backend-' . sha1($code) . '.js';
+        $filePath = 'typo3temp/assets/js/backend-' . sha1($code) . '.js';
         if (!file_exists(PATH_site . $filePath)) {
             // writeFileToTypo3tempDir() returns NULL on success (please double-read!)
             $error = GeneralUtility::writeFileToTypo3tempDir(PATH_site . $filePath, $code);
index 9276cd2..e810f83 100644 (file)
@@ -738,7 +738,7 @@ class EditDocumentController extends AbstractModule
             $generatedLabels = array();
             $generatedLabels['core'] = $coreLabels;
             $code = 'TYPO3.LLL = ' . json_encode($generatedLabels) . ';';
-            $filePath = 'typo3temp/Language/Backend-' . sha1($code) . '.js';
+            $filePath = 'typo3temp/assets/js/backend-' . sha1($code) . '.js';
             if (!file_exists(PATH_site . $filePath)) {
                 // writeFileToTypo3tempDir() returns NULL on success (please double-read!)
                 $error = GeneralUtility::writeFileToTypo3tempDir(PATH_site . $filePath, $code);
index a2c1023..ca9c2e4 100644 (file)
@@ -215,7 +215,7 @@ class GraphicalFunctions
      *
      * @var string
      */
-    public $tempPath = 'typo3temp/';
+    public $tempPath = 'typo3temp/assets/';
 
     /**
      * Prefix for relative paths. Used in "show_item.php" script. Is prefixed the output file name IN imageMagickConvert()
@@ -2002,8 +2002,8 @@ class GraphicalFunctions
      */
     public function randomName()
     {
-        $this->createTempSubDir('temp/');
-        return $this->tempPath . 'temp/' . md5(uniqid('', true));
+        $this->createTempSubDir('transient/');
+        return $this->tempPath . 'transient/' . md5(uniqid('', true));
     }
 
     /**
@@ -2214,8 +2214,8 @@ class GraphicalFunctions
                     $this->imageMagickConvert_forceFileNameBody = '';
                 }
                 // Making the temporary filename:
-                $this->createTempSubDir('pics/');
-                $output = $this->absPrefix . $this->tempPath . 'pics/' . $this->filenamePrefix . $theOutputName . '.' . $newExt;
+                $this->createTempSubDir('images/');
+                $output = $this->absPrefix . $this->tempPath . 'images/' . $this->filenamePrefix . $theOutputName . '.' . $newExt;
                 if ($this->dontCheckForExistingTempFile || !file_exists($output)) {
                     $this->imageMagickExec($imagefile, $output, $command, $frame);
                 }
@@ -2647,10 +2647,10 @@ class GraphicalFunctions
             return $theFile;
         }
 
-        if (!@is_dir(PATH_site . 'typo3temp/GraphicalResources/')) {
-            GeneralUtility::mkdir(PATH_site . 'typo3temp/GraphicalResources/');
+        if (!@is_dir(PATH_site . 'typo3temp/assets/images/')) {
+            GeneralUtility::mkdir_deep(PATH_site . 'typo3temp/assets/images/');
         }
-        $newFile = PATH_site . 'typo3temp/GraphicalResources/' . md5($theFile . '|' . filemtime($theFile)) . ($output_png ? '.png' : '.gif');
+        $newFile = PATH_site . 'typo3temp/assets/images/' . md5($theFile . '|' . filemtime($theFile)) . ($output_png ? '.png' : '.gif');
         $cmd = GeneralUtility::imageMagickCommand(
             'convert', '"' . $theFile . '" "' . $newFile . '"', $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path']
         );
@@ -2698,7 +2698,8 @@ class GraphicalFunctions
         }
         // Making the temporary filename:
         if (!@is_dir(($tmpPath . $dirName))) {
-            return GeneralUtility::mkdir($tmpPath . $dirName);
+            GeneralUtility::mkdir_deep($tmpPath . $dirName);
+            return @is_dir($tmpPath . $dirName);
         }
     }
 
index 1a71c08..0c80b0c 100644 (file)
@@ -93,7 +93,8 @@ abstract class AbstractOnlineMediaHelper implements OnlineMediaHelperInterface
     }
 
     /**
-     * Create new OnlineMedia item container file
+     * Create new OnlineMedia item container file.
+     * This is created inside typo3temp/ and then moved from FAL to the proper storage.
      *
      * @param Folder $targetFolder
      * @param string $fileName
@@ -102,23 +103,9 @@ abstract class AbstractOnlineMediaHelper implements OnlineMediaHelperInterface
      */
     protected function createNewFile(Folder $targetFolder, $fileName, $onlineMediaId)
     {
-        $tempFilePath = GeneralUtility::tempnam('online_media');
-        file_put_contents($tempFilePath, $onlineMediaId);
-        return $targetFolder->addFile($tempFilePath, $fileName, 'changeName');
-    }
-
-    /**
-     * Get temporary folder path to save preview images
-     *
-     * @return string
-     */
-    protected function getTempFolderPath()
-    {
-        $path = PATH_site . 'typo3temp/online_media/';
-        if (!is_dir($path)) {
-            GeneralUtility::mkdir($path);
-        }
-        return $path;
+        $temporaryFile = PATH_site . 'typo3temp/assets/transient/' . GeneralUtility::tempnam('online_media');
+        GeneralUtility::writeFileToTypo3tempDir($temporaryFile, $onlineMediaId);
+        return $targetFolder->addFile($temporaryFile, $fileName, 'changeName');
     }
 
     /**
index 9e0c7f1..1b72f5a 100644 (file)
@@ -78,7 +78,7 @@ class PreviewProcessing
         if (empty($temporaryFileName) || !file_exists($temporaryFileName)) {
             return;
         }
-        $temporaryFileNameForResizedThumb = uniqid(PATH_site . 'typo3temp/online_media_' . $file->getHashedIdentifier()) . '.jpg';
+        $temporaryFileNameForResizedThumb = uniqid(PATH_site . 'typo3temp/assets/transient/online_media_' . $file->getHashedIdentifier()) . '.jpg';
         switch ($taskType) {
             case 'Image.Preview':
                 // Merge custom configuration with default configuration
index 609ec79..8767e2b 100644 (file)
@@ -27,7 +27,7 @@ class ResourceCompressor
     /**
      * @var string
      */
-    protected $targetDirectory = 'typo3temp/compressor/';
+    protected $targetDirectory = 'typo3temp/assets/compressed/';
 
     /**
      * @var string
@@ -71,7 +71,7 @@ class ResourceCompressor
     {
         // we check for existence of our targetDirectory
         if (!is_dir(PATH_site . $this->targetDirectory)) {
-            GeneralUtility::mkdir(PATH_site . $this->targetDirectory);
+            GeneralUtility::mkdir_deep(PATH_site . $this->targetDirectory);
         }
         // if enabled, we check whether we should auto-create the .htaccess file
         if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['generateApacheHtaccess']) {
@@ -544,7 +544,7 @@ class ResourceCompressor
     protected function cssFixRelativeUrlPaths($contents, $oldDir)
     {
         $mainDir = TYPO3_MODE === 'BE' ? TYPO3_mainDir : '';
-        $newDir = '../../' . $mainDir . $oldDir;
+        $newDir = '../../../' . $mainDir . $oldDir;
         // Replace "url()" paths
         if (stripos($contents, 'url') !== false) {
             $regex = '/url(\\(\\s*["\']?(?!\\/)([^"\']+)["\']?\\s*\\))/iU';
index d8032cc..e08e30b 100644 (file)
@@ -152,7 +152,7 @@ class ResourceFactory implements ResourceFactoryInterface, \TYPO3\CMS\Core\Singl
                     'name' => 'Fallback Storage',
                     'description' => 'Internal storage, mounting the main TYPO3_site directory.',
                     'driver' => 'Local',
-                    'processingfolder' => 'typo3temp/_processed_/',
+                    'processingfolder' => 'typo3temp/assets/_processed_/',
                     // legacy code
                     'configuration' => '',
                     'is_online' => true,
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Important-72580-PubliclyAccessibleGeneratedAssetFilesMovedToTypo3tempassets.rst b/typo3/sysext/core/Documentation/Changelog/master/Important-72580-PubliclyAccessibleGeneratedAssetFilesMovedToTypo3tempassets.rst
new file mode 100644 (file)
index 0000000..9965673
--- /dev/null
@@ -0,0 +1,14 @@
+========================================================================================
+Important: #72580 - Publicly accessible generated asset files moved to typo3temp/assets/
+========================================================================================
+
+Description
+===========
+
+The folder structure within typo3temp/ was changed to separate assets that need to be accessed by
+the client from the files that are temporary created for e.g. caching or locking purposes and only need
+server-side access.
+
+These assets were moved from the folders ``\_processed\_``, ``compressor``, ``GB``, ``temp``, ``Language``,
+``pics`` and organized into ``typo3temp/assets/js/``, ``typo3temp/assets/css/``,
+``typo3temp/assets/compressed/`` and ``typo3temp/assets/images/``.
\ No newline at end of file
index 78a12f4..469d6c9 100644 (file)
@@ -44,7 +44,7 @@ use TYPO3\CMS\Extbase\Domain\Model\AbstractFileFolder;
  * {f:image(src: 'EXT:viewhelpertest/Resources/Public/typo3_logo.png', alt: 'alt text', minWidth: 30, maxWidth: 40)}
  * </code>
  * <output>
- * <img alt="alt text" src="../typo3temp/pics/f13d79a526.png" width="40" height="38" />
+ * <img alt="alt text" src="../typo3temp/assets/images/f13d79a526.png" width="40" height="38" />
  * (depending on your TYPO3s encryption key)
  * </output>
  *
index 6b82b93..8a74d74 100644 (file)
@@ -53,7 +53,7 @@ use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
  * {f:uri.image(src: 'EXT:myext/Resources/Public/typo3_logo.png', minWidth: 30, maxWidth: 40)}
  * </code>
  * <output>
- * typo3temp/pics/[b4c0e7ed5c].png
+ * typo3temp/assets/images/[b4c0e7ed5c].png
  * (depending on your TYPO3s encryption key)
  * </output>
  *
index 8d40967..7e4b74e 100644 (file)
@@ -378,7 +378,7 @@ class GifBuilder extends GraphicalFunctions
 
     /**
      * Initiates the image file generation if ->setup is TRUE and if the file did not exist already.
-     * Gets filename from fileName() and if file exists in typo3temp/ dir it will - of course - not be rendered again.
+     * Gets filename from fileName() and if file exists in typo3temp/assets/images/ dir it will - of course - not be rendered again.
      * Otherwise rendering means calling ->make(), then ->output(), then ->destroy()
      *
      * @return string The filename for the created GIF/PNG file. The filename will be prefixed "GB_
@@ -388,11 +388,11 @@ class GifBuilder extends GraphicalFunctions
     {
         if ($this->setup) {
             // Relative to PATH_site
-            $gifFileName = $this->fileName('GB/');
+            $gifFileName = $this->fileName('images/');
             // File exists
             if (!file_exists($gifFileName)) {
                 // Create temporary directory if not done:
-                $this->createTempSubDir('GB/');
+                $this->createTempSubDir('images/');
                 // Create file:
                 $this->make();
                 $this->output($gifFileName);
index 9052490..cf845bf 100644 (file)
@@ -973,10 +973,10 @@ class PageGenerator
         $script = '';
         switch ($ext) {
             case 'js':
-                $script = 'typo3temp/Assets/' . substr(md5($str), 0, 10) . '.js';
+                $script = 'typo3temp/assets/js/' . GeneralUtility::shortMD5($str) . '.js';
                 break;
             case 'css':
-                $script = 'typo3temp/Assets/' . substr(md5($str), 0, 10) . '.css';
+                $script = 'typo3temp/assets/css/' . GeneralUtility::shortMD5($str) . '.css';
                 break;
         }
         // Write file:
index df1c34c..3dca81f 100644 (file)
@@ -54,8 +54,8 @@ class ExtensionCompatibilityTester extends AbstractAjaxAction
      */
     public function __construct()
     {
-        $this->protocolFile = PATH_site . 'typo3temp/ExtensionCompatibilityTester.txt';
-        $this->errorProtocolFile = PATH_site . 'typo3temp/ExtensionCompatibilityTesterErrors.json';
+        $this->protocolFile = PATH_site . 'typo3temp/assets/ExtensionCompatibilityTester.txt';
+        $this->errorProtocolFile = PATH_site . 'typo3temp/assets/ExtensionCompatibilityTesterErrors.json';
     }
 
     /**
index 74fca20..b0e855b 100644 (file)
@@ -93,9 +93,41 @@ class DefaultFactory
                         'targetContent' => '',
                     ),
                     array(
-                        'name' => 'compressor',
+                        'name' => 'assets',
                         'type' => DirectoryNode::class,
                         'targetPermission' => $directoryPermission,
+                        'children' => array(
+                            array(
+                                'name' => 'compressed',
+                                'type' => DirectoryNode::class,
+                                'targetPermission' => $directoryPermission
+                            ),
+                            array(
+                                'name' => 'css',
+                                'type' => DirectoryNode::class,
+                                'targetPermission' => $directoryPermission
+                            ),
+                            array(
+                                'name' => 'js',
+                                'type' => DirectoryNode::class,
+                                'targetPermission' => $directoryPermission
+                            ),
+                            array(
+                                'name' => 'images',
+                                'type' => DirectoryNode::class,
+                                'targetPermission' => $directoryPermission
+                            ),
+                            array(
+                                'name' => 'transient',
+                                'type' => DirectoryNode::class,
+                                'targetPermission' => $directoryPermission
+                            ),
+                            array(
+                                'name' => '_processed_',
+                                'type' => DirectoryNode::class,
+                                'targetPermission' => $directoryPermission
+                            )
+                        )
                     ),
                     array(
                         'name' => 'cs',
@@ -108,30 +140,10 @@ class DefaultFactory
                         'targetPermission' => $directoryPermission,
                     ),
                     array(
-                        'name' => 'GB',
-                        'type' => DirectoryNode::class,
-                        'targetPermission' => $directoryPermission,
-                    ),
-                    array(
                         'name' => 'locks',
                         'type' => DirectoryNode::class,
                         'targetPermission' => $directoryPermission,
                     ),
-                    array(
-                        'name' => 'pics',
-                        'type' => DirectoryNode::class,
-                        'targetPermission' => $directoryPermission,
-                    ),
-                    array(
-                        'name' => 'temp',
-                        'type' => DirectoryNode::class,
-                        'targetPermission' => $directoryPermission,
-                    ),
-                    array(
-                        'name' => '_processed_',
-                        'type' => DirectoryNode::class,
-                        'targetPermission' => $directoryPermission,
-                    ),
                 ),
             ),
             array(
index cd798fb..c899501 100644 (file)
@@ -63,10 +63,17 @@ class InstallStatusReport implements \TYPO3\CMS\Reports\StatusProviderInterface
         //  2 = required, has to be writable
         $checkWritable = array(
             'typo3temp/' => 2,
-            'typo3temp/pics/' => 2,
-            'typo3temp/temp/' => 2,
+            'typo3temp/assets/' => 2,
+            'typo3temp/assets/transient/' => 2,
+            'typo3temp/assets/compressed/' => 2,
+            // only needed when GraphicalFunctions is used
+            'typo3temp/assets/images/' => 0,
+            // used in PageGenerator (inlineStyle2Temp) and Backend + Language JS files
+            'typo3temp/assets/css/' => 2,
+            'typo3temp/assets/js/' => 2,
+            // fallback storage of FAL
+            'typo3temp/assets/_processed_/' => 0,
             'typo3temp/cs/' => 2,
-            'typo3temp/GB/' => 2,
             'typo3temp/locks/' => 2,
             'typo3conf/' => 2,
             'typo3conf/ext/' => 0,
index 3d4c09d..c3cc1e2 100644 (file)
@@ -121,9 +121,9 @@ class ExtensionCompatibilityTesterTest extends \TYPO3\CMS\Core\Tests\UnitTestCas
     public function deleteProtocolFileDeletesFile()
     {
         $extensionCompatibilityTesterMock = $this->getAccessibleMock(\TYPO3\CMS\Install\Controller\Action\Ajax\ExtensionCompatibilityTester::class, array('dummy'), array());
-        GeneralUtility::writeFile(PATH_site . 'typo3temp/ExtensionCompatibilityTester.txt', 'foobar');
+        GeneralUtility::writeFile(PATH_site . 'typo3temp/assets/ExtensionCompatibilityTester.txt', 'foobar');
         $extensionCompatibilityTesterMock->_call('deleteProtocolFile');
-        $this->assertFalse(file_exists(PATH_site . 'typo3temp/ExtensionCompatibilityTester.txt'));
+        $this->assertFalse(file_exists(PATH_site . 'typo3temp/assets/ExtensionCompatibilityTester.txt'));
     }
 
     /**
index 8d2be70..4f13d8c 100644 (file)
@@ -951,7 +951,7 @@ class RichTextElement extends AbstractFormElement
      */
     protected function writeTemporaryFile($label, $fileExtension = 'js', $contents = '')
     {
-        $relativeFilename = 'typo3temp/RteHtmlArea/' . str_replace('-', '_', $label) . '_' . GeneralUtility::shortMD5($contents, 20) . '.' . $fileExtension;
+        $relativeFilename = 'typo3temp/assets/js/rte_' . str_replace('-', '_', $label) . '_' . GeneralUtility::shortMD5($contents, 20) . '.' . $fileExtension;
         $destination = PATH_site . $relativeFilename;
         if (!file_exists($destination)) {
             $minifiedJavaScript = '';
index 7c9853b..a5db96d 100644 (file)
@@ -308,7 +308,7 @@ abstract class RteHtmlAreaApi
      */
     protected function writeTemporaryFile($label, $fileExtension = 'js', $contents = '')
     {
-        $relativeFilename = 'typo3temp/RteHtmlArea/' . str_replace('-', '_', $label) . '_' . GeneralUtility::shortMD5($contents, 20) . '.' . $fileExtension;
+        $relativeFilename = 'typo3temp/assets/js/rte_' . str_replace('-', '_', $label) . '_' . GeneralUtility::shortMD5($contents, 20) . '.' . $fileExtension;
         $destination = PATH_site . $relativeFilename;
         if (!file_exists($destination)) {
             $minifiedJavaScript = '';