[TASK] Deprecate GraphicalFunctions->tempPath and createTempSubDir() 12/52212/4
authorBenni Mack <benni@typo3.org>
Tue, 28 Mar 2017 11:02:11 +0000 (13:02 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Tue, 28 Mar 2017 21:18:21 +0000 (23:18 +0200)
The short-hand functionality within GraphicalFunctions to create a
sub directory inside the hard-coded tempPath is a simple wrapper
of GeneralUtility::mkdir_deep().

The according change deprecates both the property $tempPath
and the method createTempSubDir().

Resolves: #80514
Releases: master
Change-Id: Ie0f0ac017e979ab67820182d16d7a4ebbc2fd4e4
Reviewed-on: https://review.typo3.org/52212
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
typo3/sysext/core/Classes/Resource/Processing/LocalCropScaleMaskHelper.php
typo3/sysext/core/Documentation/Changelog/master/Deprecation-80514-GraphicalFunctions-tempPathAndCreateTempSubDir.rst [new file with mode: 0644]
typo3/sysext/frontend/Classes/ContentObject/Menu/GraphicalMenuContentObject.php
typo3/sysext/frontend/Classes/ContentObject/Menu/ImageMenuContentObject.php
typo3/sysext/frontend/Classes/Imaging/GifBuilder.php
typo3/sysext/install/Classes/Controller/Action/Tool/TestSetup.php

index cafb884..e4050ae 100644 (file)
@@ -213,6 +213,7 @@ class GraphicalFunctions
      * The temp-directory where to store the files. Normally relative to PATH_site but is allowed to be the absolute path AS LONG AS it is a subdir to PATH_site.
      *
      * @var string
+     * @deprecated since TYPO3 v8, will be removed in TYPO3 v9
      */
     public $tempPath = 'typo3temp/';
 
@@ -1971,15 +1972,15 @@ class GraphicalFunctions
     }
 
     /**
-     * Returns a random filename prefixed with "temp_" and then 32 char md5 hash (without extension) from $this->tempPath.
+     * Returns a random filename prefixed with "temp_" and then 32 char md5 hash (without extension).
      * Used by functions in this class to create truly temporary files for the on-the-fly processing. These files will most likely be deleted right away.
      *
      * @return string
      */
     public function randomName()
     {
-        $this->createTempSubDir('var/transient/');
-        return $this->tempPath . 'var/transient/' . md5(uniqid('', true));
+        GeneralUtility::mkdir_deep(PATH_site . 'typo3temp/var/transient/');
+        return 'typo3temp/var/transient/' . md5(uniqid('', true));
     }
 
     /**
@@ -2192,8 +2193,8 @@ class GraphicalFunctions
             $this->imageMagickConvert_forceFileNameBody = '';
         }
         // Making the temporary filename:
-        $this->createTempSubDir('assets/images/');
-        $output = $this->absPrefix . $this->tempPath . 'assets/images/' . $this->filenamePrefix . $theOutputName . '.' . $newExt;
+        GeneralUtility::mkdir_deep(PATH_site . 'typo3temp/assets/images/');
+        $output = $this->absPrefix . 'typo3temp/assets/images/' . $this->filenamePrefix . $theOutputName . '.' . $newExt;
         if ($this->dontCheckForExistingTempFile || !file_exists($output)) {
             $this->imageMagickExec($imagefile, $output, $command, $frame);
         }
@@ -2655,9 +2656,11 @@ class GraphicalFunctions
      *
      * @param string $dirName Name of sub directory
      * @return bool Result of \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir(), TRUE if it went well.
+     * @deprecated since TYPO3 v8, will be removed in TYPO3 v9, use GeneralUtility::mkdir_deep() directly.
      */
     public function createTempSubDir($dirName)
     {
+        GeneralUtility::logDeprecatedFunction();
         // Checking if the this->tempPath is already prefixed with PATH_site and if not, prefix it with that constant.
         if (GeneralUtility::isFirstPartOfStr($this->tempPath, PATH_site)) {
             $tmpPath = $this->tempPath;
index a26cd0f..f765722 100644 (file)
@@ -137,7 +137,7 @@ class LocalCropScaleMaskHelper
             }
         } else {
             $targetFileName = $this->getFilenameForImageCropScaleMask($task);
-            $temporaryFileName = $gifBuilder->tempPath . $targetFileName;
+            $temporaryFileName = PATH_site . 'typo3temp/' . $targetFileName;
             $maskImage = $configuration['maskImages']['maskImage'];
             $maskBackgroundImage = $configuration['maskImages']['backgroundImage'];
             if ($maskImage instanceof Resource\FileInterface && $maskBackgroundImage instanceof Resource\FileInterface) {
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-80514-GraphicalFunctions-tempPathAndCreateTempSubDir.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-80514-GraphicalFunctions-tempPathAndCreateTempSubDir.rst
new file mode 100644 (file)
index 0000000..64c9dcf
--- /dev/null
@@ -0,0 +1,34 @@
+.. include:: ../../Includes.txt
+
+=========================================================================
+Deprecation: #80514 - GraphicalFunctions->tempPath and createTempSubDir()
+=========================================================================
+
+See :issue:`80514`
+
+Description
+===========
+
+The method php:`GraphicalFunctions->createTempSubDir()` and the property
+php:`GraphicalFunctions->tempPath` have been marked as deprecated.
+
+
+Impact
+======
+
+Calling the method above will trigger a deprecation log entry.
+
+
+Affected Installations
+======================
+
+Any instance with custom extensions extending the PHP class GraphicalFunctions.
+
+
+Migration
+=========
+
+Use `GeneralUtility::mkdir_deep()` with the full path (including the PHP constant `PATH_site`)
+directly.
+
+.. index:: PHP-API
\ No newline at end of file
index 5048d67..75cb0d2 100644 (file)
@@ -234,8 +234,8 @@ class GraphicalMenuContentObject extends AbstractMenuContentObject
             }
             // If an alternative name was NOT given, find the GIFBUILDER name.
             if (!$gifFileName && $isGD) {
-                $gifCreator->createTempSubDir('menu/');
-                $gifFileName = $gifCreator->fileName('menu/');
+                GeneralUtility::mkdir_deep(PATH_site . 'typo3temp/assets/menu/');
+                $gifFileName = $gifCreator->fileName('assets/menu/');
             }
             $this->result[$resKey][$key] = $conf[$key];
             // Generation of image file:
index 396a94b..a58fe95 100644 (file)
@@ -191,8 +191,8 @@ class ImageMenuContentObject extends AbstractMenuContentObject
                     echo '<h3>Renumbered GIFBUILDER object:</h3>';
                     debug($gifCreator->setup);
                 }
-                $gifCreator->createTempSubDir('menu/');
-                $gifFileName = $gifCreator->fileName('menu/');
+                GeneralUtility::mkdir_deep(PATH_site . 'typo3temp/assets/menu/');
+                $gifFileName = $gifCreator->fileName('assets/menu/');
                 // Gets the ImageMap from the cache...
                 $cache = $this->getCache();
                 $imgHash = md5($gifFileName);
index 77b1ca1..1fc8670 100644 (file)
@@ -343,11 +343,11 @@ class GifBuilder extends GraphicalFunctions
     {
         if ($this->setup) {
             // Relative to PATH_site
-            $gifFileName = $this->fileName('images/');
+            $gifFileName = $this->fileName('assets/images/');
             // File exists
             if (!file_exists($gifFileName)) {
                 // Create temporary directory if not done:
-                $this->createTempSubDir('images/');
+                GeneralUtility::mkdir_deep(PATH_site . 'typo3temp/assets/images/');
                 // Create file:
                 $this->make();
                 $this->output($gifFileName);
@@ -705,7 +705,7 @@ class GifBuilder extends GraphicalFunctions
         // shorten prefix to avoid overly long file names
         $filePrefix = substr($filePrefix, 0, 100);
 
-        return $this->tempPath . $pre . $filePrefix . '_' . GeneralUtility::shortMD5(serialize($this->setup)) . '.' . $this->extension();
+        return 'typo3temp/' . $pre . $filePrefix . '_' . GeneralUtility::shortMD5(serialize($this->setup)) . '.' . $this->extension();
     }
 
     /**
index 1582db4..da31ef2 100644 (file)
@@ -656,7 +656,7 @@ class TestSetup extends Action\AbstractAction
         /** @var GraphicalFunctions $imageProcessor */
         $imageProcessor = GeneralUtility::makeInstance(GraphicalFunctions::class);
         $imageProcessor->init();
-        $imageProcessor->tempPath = PATH_site . 'typo3temp/';
+        $imageProcessor->absPrefix = PATH_site;
         $imageProcessor->dontCheckForExistingTempFile = 1;
         $imageProcessor->filenamePrefix = 'installTool-';
         $imageProcessor->dontCompress = 1;