[TASK] Deprecate second argument of GeneralUtility::mkdir_deep() 23/54323/6
authorBenni Mack <benni@typo3.org>
Sun, 8 Oct 2017 13:16:10 +0000 (15:16 +0200)
committerSusanne Moog <susanne.moog@typo3.org>
Mon, 9 Oct 2017 09:27:40 +0000 (11:27 +0200)
The syntax is very confusing, and the second argument is not necessarily
needed - most of the TYPO3 Core code uses only the first argument.

In order to streamline the API the second method argument is deprecated
but still works as before.

Resolves: #82702
Releases: master
Change-Id: Ib2238ff90edf932f9410cf87c214e23d0a1c4826
Reviewed-on: https://review.typo3.org/54323
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Joerg Boesche <typo3@joergboesche.de>
Tested-by: Joerg Boesche <typo3@joergboesche.de>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
typo3/sysext/core/Classes/DataHandling/DataHandler.php
typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/core/Documentation/Changelog/master/Deprecation-82702-SecondArgumentOfGeneralUtilitymkdir_deep.rst [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/Resource/Driver/LocalDriverTest.php
typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php
typo3/sysext/documentation/Classes/Service/DocumentationService.php
typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodArgumentDroppedMatcher.php
typo3/sysext/lang/Classes/Service/TerService.php

index 46e4634..4513536 100644 (file)
@@ -2315,7 +2315,7 @@ class DataHandler
                             } elseif (@is_file($theFile)) {
                                 $dest = dirname(PATH_site . $this->alternativeFilePath[$theFile]);
                                 if (!@is_dir($dest)) {
-                                    GeneralUtility::mkdir_deep(PATH_site, dirname($this->alternativeFilePath[$theFile]) . '/');
+                                    GeneralUtility::mkdir_deep($dest);
                                 }
                                 // Init:
                                 $maxSize = (int)$tcaFieldConf['max_size'];
index 56b0654..1a8c29d 100644 (file)
@@ -231,7 +231,7 @@ class LocalDriver extends AbstractHierarchicalFilesystemDriver
             $parts = array_map([$this, 'sanitizeFileName'], $parts);
             $newFolderName = implode('/', $parts);
             $newIdentifier = $parentFolderIdentifier . $newFolderName . '/';
-            GeneralUtility::mkdir_deep($this->getAbsolutePath($parentFolderIdentifier) . '/', $newFolderName);
+            GeneralUtility::mkdir_deep($this->getAbsolutePath($parentFolderIdentifier) . '/' . $newFolderName);
         }
         return $newIdentifier;
     }
index 8f4fba0..716710f 100644 (file)
@@ -1996,7 +1996,7 @@ class GeneralUtility
             if (preg_match('#^(?:[[:alnum:]_]+/)+$#', $subdir)) {
                 $dirName .= $subdir;
                 if (!@is_dir($dirName)) {
-                    static::mkdir_deep(PATH_site . 'typo3temp/', $subdir);
+                    static::mkdir_deep(PATH_site . 'typo3temp/' . $subdir);
                 }
             } else {
                 return 'Subdir, "' . $subdir . '", was NOT on the form "[[:alnum:]_]/+"';
@@ -2053,7 +2053,11 @@ class GeneralUtility
             throw new \InvalidArgumentException('The specified directory is of type "' . gettype($deepDirectory) . '" but a string is expected.', 1303662956);
         }
         // Ensure there is only one slash
-        $fullPath = rtrim($directory, '/') . '/' . ltrim($deepDirectory, '/');
+        $fullPath = rtrim($directory, '/') . '/';
+        if ($deepDirectory !== '') {
+            trigger_error('Second argument $deepDirectory of GeneralUtility::mkdir_deep() will be removed in TYPO3 v10.0, use a combined string as first argument instead.', E_USER_DEPRECATED);
+            $fullPath .= ltrim($deepDirectory, '/');
+        }
         if ($fullPath !== '/' && !is_dir($fullPath)) {
             $firstCreatedPath = static::createDirectoryPath($fullPath);
             if ($firstCreatedPath !== '') {
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-82702-SecondArgumentOfGeneralUtilitymkdir_deep.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-82702-SecondArgumentOfGeneralUtilitymkdir_deep.rst
new file mode 100644 (file)
index 0000000..ace3063
--- /dev/null
@@ -0,0 +1,35 @@
+.. include:: ../../Includes.txt
+
+=====================================================================
+Deprecation: #82702 - Second argument of GeneralUtility::mkdir_deep()
+=====================================================================
+
+See :issue:`82702`
+
+Description
+===========
+
+The second option of :php:`TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep()` has been marked
+as deprecated.
+
+
+Impact
+======
+
+Calling this method with a second argument which is not empty, will trigger a deprecation entry.
+
+
+Affected Installations
+======================
+
+Any installation with a third-party extension calling this method with two arguments.
+
+
+Migration
+=========
+
+Instead of calling `GeneralUtility::mkdir_deep(PATH_site . 'typo3temp/', 'myfolder');` the simple
+syntax GeneralUtility::mkdir_deep(PATH_site . 'typo3temp/myfolder'); can be used directly, also
+in TYPO3 v8 and before already.
+
+.. index:: PHP-API, FullyScanned
\ No newline at end of file
index f671d31..57b9f4b 100644 (file)
@@ -1429,8 +1429,8 @@ class LocalDriverTest extends \TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase
     public function copyFolderWithinStorageCopiesSingleSubFolderToNewFolderName()
     {
         list($basePath, $subject) = $this->prepareRealTestEnvironment();
-        GeneralUtility::mkdir_deep($basePath, '/sourceFolder/subFolder');
-        GeneralUtility::mkdir_deep($basePath, '/targetFolder');
+        GeneralUtility::mkdir_deep($basePath . '/sourceFolder/subFolder');
+        GeneralUtility::mkdir_deep($basePath . '/targetFolder');
 
         $subject->copyFolderWithinStorage('/sourceFolder/', '/targetFolder/', 'newFolderName');
         $this->assertTrue(is_dir($basePath . '/targetFolder/newFolderName/subFolder'));
@@ -1442,8 +1442,8 @@ class LocalDriverTest extends \TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase
     public function copyFolderWithinStorageCopiesFileInSingleSubFolderToNewFolderName()
     {
         list($basePath, $subject) = $this->prepareRealTestEnvironment();
-        GeneralUtility::mkdir_deep($basePath, '/sourceFolder/subFolder');
-        GeneralUtility::mkdir_deep($basePath, '/targetFolder');
+        GeneralUtility::mkdir_deep($basePath . '/sourceFolder/subFolder');
+        GeneralUtility::mkdir_deep($basePath . '/targetFolder');
         file_put_contents($basePath . '/sourceFolder/subFolder/file', $this->getUniqueId());
         GeneralUtility::fixPermissions($basePath . '/sourceFolder/subFolder/file');
 
index 9ca32d6..837ce73 100644 (file)
@@ -2907,7 +2907,7 @@ class GeneralUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
         // Load fixture files and folders from disk
         FileStreamWrapper::init(PATH_site);
         FileStreamWrapper::registerOverlayPath('fileadmin', 'vfs://root/fileadmin', true);
-        GeneralUtility::mkdir_deep(PATH_site, $directoryToCreate);
+        GeneralUtility::mkdir_deep(PATH_site . $directoryToCreate);
         $this->assertTrue(is_dir(PATH_site . $directoryToCreate));
         FileStreamWrapper::destroy();
     }
@@ -2923,7 +2923,7 @@ class GeneralUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
         $directory = $this->getUniqueId('mkdirdeeptest_');
         $oldUmask = umask(19);
         $GLOBALS['TYPO3_CONF_VARS']['SYS']['folderCreateMask'] = '0777';
-        GeneralUtility::mkdir_deep(PATH_site . 'typo3temp/var/tests/', $directory);
+        GeneralUtility::mkdir_deep(PATH_site . 'typo3temp/var/tests/' . $directory);
         $this->testFilesToDelete[] = PATH_site . 'typo3temp/var/tests/' . $directory;
         clearstatcache();
         umask($oldUmask);
@@ -2942,7 +2942,7 @@ class GeneralUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
         $subDirectory = $directory . '/bar';
         $GLOBALS['TYPO3_CONF_VARS']['SYS']['folderCreateMask'] = '0777';
         $oldUmask = umask(19);
-        GeneralUtility::mkdir_deep(PATH_site . 'typo3temp/var/tests/', $subDirectory);
+        GeneralUtility::mkdir_deep(PATH_site . 'typo3temp/var/tests/' . $subDirectory);
         $this->testFilesToDelete[] = PATH_site . 'typo3temp/var/tests/' . $directory;
         clearstatcache();
         umask($oldUmask);
@@ -2963,7 +2963,7 @@ class GeneralUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
         @mkdir(($baseDirectory . $existingDirectory));
         $this->testFilesToDelete[] = $baseDirectory . $existingDirectory;
         chmod($baseDirectory . $existingDirectory, 482);
-        GeneralUtility::mkdir_deep($baseDirectory, $existingDirectory . $newSubDirectory);
+        GeneralUtility::mkdir_deep($baseDirectory . $existingDirectory . $newSubDirectory);
         $this->assertEquals('0742', substr(decoct(fileperms($baseDirectory . $existingDirectory)), 2));
     }
 
@@ -2976,7 +2976,7 @@ class GeneralUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
         if ($swapGroup !== false) {
             $GLOBALS['TYPO3_CONF_VARS']['SYS']['createGroup'] = $swapGroup;
             $directory = $this->getUniqueId('mkdirdeeptest_');
-            GeneralUtility::mkdir_deep(PATH_site . 'typo3temp/var/tests/', $directory);
+            GeneralUtility::mkdir_deep(PATH_site . 'typo3temp/var/tests/' . $directory);
             $this->testFilesToDelete[] = PATH_site . 'typo3temp/var/tests/' . $directory;
             clearstatcache();
             $resultDirectoryGroup = filegroup(PATH_site . 'typo3temp/var/tests/' . $directory);
@@ -2994,7 +2994,7 @@ class GeneralUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
             $GLOBALS['TYPO3_CONF_VARS']['SYS']['createGroup'] = $swapGroup;
             $directory = $this->getUniqueId('mkdirdeeptest_');
             $subDirectory = $directory . '/bar';
-            GeneralUtility::mkdir_deep(PATH_site . 'typo3temp/var/tests/', $subDirectory);
+            GeneralUtility::mkdir_deep(PATH_site . 'typo3temp/var/tests/' . $subDirectory);
             $this->testFilesToDelete[] = PATH_site . 'typo3temp/var/tests/' . $directory;
             clearstatcache();
             $resultDirectoryGroup = filegroup(PATH_site . 'typo3temp/var/tests/' . $directory);
@@ -3012,7 +3012,7 @@ class GeneralUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
             $GLOBALS['TYPO3_CONF_VARS']['SYS']['createGroup'] = $swapGroup;
             $directory = $this->getUniqueId('mkdirdeeptest_');
             $subDirectory = $directory . '/bar';
-            GeneralUtility::mkdir_deep(PATH_site . 'typo3temp/var/tests/', $subDirectory);
+            GeneralUtility::mkdir_deep(PATH_site . 'typo3temp/var/tests/' . $subDirectory);
             $this->testFilesToDelete[] = PATH_site . 'typo3temp/var/tests/' . $directory;
             clearstatcache();
             $resultDirectoryGroup = filegroup(PATH_site . 'typo3temp/var/tests/' . $directory);
@@ -3031,7 +3031,7 @@ class GeneralUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
         vfsStreamWrapper::register();
         $baseDirectory = $this->getUniqueId('test_');
         vfsStreamWrapper::setRoot(new vfsStreamDirectory($baseDirectory));
-        GeneralUtility::mkdir_deep('vfs://' . $baseDirectory . '/', 'sub');
+        GeneralUtility::mkdir_deep('vfs://' . $baseDirectory . '/sub');
         $this->assertTrue(is_dir('vfs://' . $baseDirectory . '/sub'));
     }
 
index 30c9db4..0756b9e 100644 (file)
@@ -298,7 +298,7 @@ class DocumentationService
                     $fileName = array_pop($zipEntryPathSegments);
                     // It is a folder, because the last segment is empty, let's create it
                     if (empty($fileName)) {
-                        GeneralUtility::mkdir_deep($path, implode('/', $zipEntryPathSegments));
+                        GeneralUtility::mkdir_deep($path . implode('/', $zipEntryPathSegments));
                     } else {
                         $absoluteTargetPath = GeneralUtility::getFileAbsFileName($path . implode('/', $zipEntryPathSegments) . '/' . $fileName);
                         if (trim($absoluteTargetPath) !== '') {
index 3a713f4..c6b3308 100644 (file)
@@ -123,4 +123,10 @@ return [
             'Breaking-82629-TceDbOptionsPrErrAndUPTRemoved.rst',
         ],
     ],
+    'TYPO3\CMS\Core\Utility\GeneralUtility->mkdir_deep' => [
+        'maximumNumberOfArguments' => 1,
+        'restFiles' => [
+            'Deprecation-82702-SecondArgumentOfGeneralUtilitymkdir_deep.rst',
+        ],
+    ],
 ];
index 2ac9757..c452cfa 100644 (file)
@@ -143,7 +143,7 @@ class TerService extends TerUtility implements SingletonInterface
                     throw new LanguageException('Given path is invalid.', 1352565336);
                 }
                 if (!is_dir($absoluteLanguagePath)) {
-                    GeneralUtility::mkdir_deep(PATH_typo3conf, $relativeLanguagePath);
+                    GeneralUtility::mkdir_deep($absoluteLanguagePath);
                 }
                 GeneralUtility::writeFileToTypo3tempDir($absolutePathToZipFile, $l10n[0]);
                 if (is_dir($absoluteExtensionLanguagePath)) {
@@ -220,7 +220,7 @@ class TerService extends TerUtility implements SingletonInterface
                     $fileName = array_pop($zipEntryPathSegments);
                     // It is a folder, because the last segment is empty, let's create it
                     if (empty($fileName)) {
-                        GeneralUtility::mkdir_deep($path, implode('/', $zipEntryPathSegments));
+                        GeneralUtility::mkdir_deep($path . implode('/', $zipEntryPathSegments));
                     } else {
                         $absoluteTargetPath = GeneralUtility::getFileAbsFileName($path . implode('/', $zipEntryPathSegments) . '/' . $fileName);
                         if (trim($absoluteTargetPath) !== '') {