Skip to content

Commit

Permalink
[TASK] Replace last occurrences of PATH_site with Environment API
Browse files Browse the repository at this point in the history
Resolves: #85285
Releases: master
Change-Id: I4d12f7add6f536b3a412e554c8a6c4d64fd677e4
Reviewed-on: https://review.typo3.org/57241
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
  • Loading branch information
bmack authored and lolli42 committed Jun 15, 2018
1 parent 311cfe2 commit 2dd2e0e
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 53 deletions.
25 changes: 13 additions & 12 deletions typo3/sysext/core/Classes/Configuration/ConfigurationManager.php
Expand Up @@ -14,6 +14,7 @@
* The TYPO3 project - inspiring people to share!
*/

use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Crypto\Random;
use TYPO3\CMS\Core\Service\OpcodeCacheService;
use TYPO3\CMS\Core\Utility\ArrayUtility;
Expand All @@ -37,22 +38,22 @@
class ConfigurationManager
{
/**
* @var string Path to default TYPO3_CONF_VARS file, relative to PATH_site
* @var string Path to default TYPO3_CONF_VARS file, relative to the public web folder
*/
protected $defaultConfigurationFile = 'typo3/sysext/core/Configuration/DefaultConfiguration.php';

/**
* @var string Path to description file for TYPO3_CONF_VARS, relative to PATH_site
* @var string Path to description file for TYPO3_CONF_VARS, relative to the public web folder
*/
protected $defaultConfigurationDescriptionFile = 'typo3/sysext/core/Configuration/DefaultConfigurationDescription.yaml';

/**
* @var string Path to local overload TYPO3_CONF_VARS file, relative to PATH_site
* @var string Path to local overload TYPO3_CONF_VARS file, relative to the public web folder
*/
protected $localConfigurationFile = 'typo3conf/LocalConfiguration.php';

/**
* @var string Path to additional local file, relative to PATH_site
* @var string Path to additional local file, relative to the public web folder
*/
protected $additionalConfigurationFile = 'typo3conf/AdditionalConfiguration.php';

Expand Down Expand Up @@ -100,7 +101,7 @@ public function getDefaultConfiguration()
*/
public function getDefaultConfigurationFileLocation()
{
return PATH_site . $this->defaultConfigurationFile;
return Environment::getPublicPath() . '/' . $this->defaultConfigurationFile;
}

/**
Expand All @@ -112,7 +113,7 @@ public function getDefaultConfigurationFileLocation()
*/
public function getDefaultConfigurationDescriptionFileLocation()
{
return PATH_site . $this->defaultConfigurationDescriptionFile;
return Environment::getPublicPath() . '/' . $this->defaultConfigurationDescriptionFile;
}

/**
Expand All @@ -134,7 +135,7 @@ public function getLocalConfiguration()
*/
public function getLocalConfigurationFileLocation()
{
return PATH_site . $this->localConfigurationFile;
return Environment::getPublicPath() . '/' . $this->localConfigurationFile;
}

/**
Expand All @@ -158,7 +159,7 @@ public function getMergedLocalConfiguration(): array
*/
public function getAdditionalConfigurationFileLocation()
{
return PATH_site . $this->additionalConfigurationFile;
return Environment::getPublicPath() . '/' . $this->additionalConfigurationFile;
}

/**
Expand All @@ -168,7 +169,7 @@ public function getAdditionalConfigurationFileLocation()
*/
protected function getFactoryConfigurationFileLocation()
{
return PATH_site . $this->factoryConfigurationFile;
return Environment::getPublicPath() . '/' . $this->factoryConfigurationFile;
}

/**
Expand All @@ -178,7 +179,7 @@ protected function getFactoryConfigurationFileLocation()
*/
protected function getAdditionalFactoryConfigurationFileLocation()
{
return PATH_site . $this->additionalFactoryConfigurationFile;
return Environment::getPublicPath() . '/' . $this->additionalFactoryConfigurationFile;
}

/**
Expand Down Expand Up @@ -320,7 +321,7 @@ public function disableFeature(string $featureName): bool
public function canWriteConfiguration()
{
$fileLocation = $this->getLocalConfigurationFileLocation();
return @is_writable(file_exists($fileLocation) ? $fileLocation : PATH_site . 'typo3conf/');
return @is_writable(file_exists($fileLocation) ? $fileLocation : Environment::getPublicPath() . '/typo3conf/');
}

/**
Expand Down Expand Up @@ -392,7 +393,7 @@ public function writeLocalConfiguration(array $configuration)
public function writeAdditionalConfiguration(array $additionalConfigurationLines)
{
return GeneralUtility::writeFile(
PATH_site . $this->additionalConfigurationFile,
Environment::getPublicPath() . '/' . $this->additionalConfigurationFile,
'<?php' . LF .
implode(LF, $additionalConfigurationLines) . LF
);
Expand Down
8 changes: 4 additions & 4 deletions typo3/sysext/core/Classes/Core/ClassLoadingInformation.php
Expand Up @@ -92,7 +92,7 @@ public static function dumpClassLoadingInformation()
$activeExtensionPackages = static::getActiveExtensionPackages();

/** @var ClassLoadingInformationGenerator $generator */
$generator = GeneralUtility::makeInstance(ClassLoadingInformationGenerator::class, $composerClassLoader, $activeExtensionPackages, PATH_site, self::isTestingContext());
$generator = GeneralUtility::makeInstance(ClassLoadingInformationGenerator::class, $composerClassLoader, $activeExtensionPackages, Environment::getPublicPath() . '/', self::isTestingContext());
$classInfoFiles = $generator->buildAutoloadInformationFiles();
GeneralUtility::writeFile(self::getClassLoadingInformationDirectory() . self::AUTOLOAD_CLASSMAP_FILENAME, $classInfoFiles['classMapFile']);
GeneralUtility::writeFile(self::getClassLoadingInformationDirectory() . self::AUTOLOAD_PSR4_FILENAME, $classInfoFiles['psr-4File']);
Expand Down Expand Up @@ -148,7 +148,7 @@ public static function registerTransientClassLoadingInformationForPackage(Packag
$activeExtensionPackages = static::getActiveExtensionPackages();

/** @var ClassLoadingInformationGenerator $generator */
$generator = GeneralUtility::makeInstance(ClassLoadingInformationGenerator::class, $composerClassLoader, $activeExtensionPackages, PATH_site, self::isTestingContext());
$generator = GeneralUtility::makeInstance(ClassLoadingInformationGenerator::class, $composerClassLoader, $activeExtensionPackages, Environment::getPublicPath() . '/', self::isTestingContext());

$classInformation = $generator->buildClassLoadingInformationForPackage($package);
$composerClassLoader->addClassMap($classInformation['classMap']);
Expand All @@ -167,9 +167,9 @@ public static function registerTransientClassLoadingInformationForPackage(Packag
protected static function getClassLoadingInformationDirectory()
{
if (self::isTestingContext()) {
return PATH_site . self::AUTOLOAD_INFO_DIR_TESTS;
return Environment::getPublicPath() . '/' . self::AUTOLOAD_INFO_DIR_TESTS;
}
return PATH_site . self::AUTOLOAD_INFO_DIR;
return Environment::getPublicPath() . '/' . self::AUTOLOAD_INFO_DIR;
}

/**
Expand Down
Expand Up @@ -214,7 +214,7 @@ public function buildAutoloadInformationFiles()
// autoload_classmap.php @generated by TYPO3
\$typo3InstallDir = PATH_site;
\$typo3InstallDir = \TYPO3\CMS\Core\Core\Environment::getPublicPath() . '/';
return array(
Expand Down
2 changes: 2 additions & 0 deletions typo3/sysext/core/Classes/Core/SystemEnvironmentBuilder.php
Expand Up @@ -188,10 +188,12 @@ protected static function definePaths($entryPointLevel = 0)
}

if (!defined('PATH_thisScript')) {
// @deprecated since v9, will be removed in v10
define('PATH_thisScript', $scriptPath);
}
// Absolute path of the document root of the instance with trailing slash
if (!defined('PATH_site')) {
// @deprecated since v9, will be removed in v10
define('PATH_site', $rootPath . '/');
}
// Relative path from document root to typo3/ directory
Expand Down
40 changes: 20 additions & 20 deletions typo3/sysext/core/Classes/Utility/GeneralUtility.php
Expand Up @@ -2003,7 +2003,7 @@ public static function fixPermissions($path, $recursive = false)
* Writes $content to a filename in the typo3temp/ folder (and possibly one or two subfolders...)
* Accepts an additional subdirectory in the file path!
*
* @param string $filepath Absolute file path to write to inside "typo3temp/". First part of this string must match PATH_site."typo3temp/"
* @param string $filepath Absolute file path to write within the typo3temp/ or Environment::getVarPath() folder - the file path must be prefixed with this path
* @param string $content Content string to write
* @return string Returns NULL on success, otherwise an error string telling about the problem.
*/
Expand All @@ -2022,7 +2022,7 @@ public static function writeFileToTypo3tempDir($filepath, $content)
Environment::getPublicPath() . '/typo3temp' => 'Environment::getPublicPath() + "/typo3temp/"'
];
// Also allow project-path + /var/
if (Environment::getVarPath() !== PATH_site . 'typo3temp/var') {
if (Environment::getVarPath() !== Environment::getPublicPath() . '/typo3temp/var') {
$relPath = substr(Environment::getVarPath(), strlen(Environment::getProjectPath()) + 1);
$allowedPathPrefixes[Environment::getVarPath()] = 'ProjectPath + ' . $relPath;
}
Expand Down Expand Up @@ -2820,7 +2820,7 @@ public static function getIndpEnv($getEnvName)
// This can only be set by external entry scripts
if (defined('TYPO3_PATH_WEB')) {
$retVal = $url;
} elseif (Environment::getCurrentScript() && defined('PATH_site')) {
} elseif (Environment::getCurrentScript()) {
$lPath = PathUtility::stripPathSitePrefix(PathUtility::dirnameDuringBootstrap(Environment::getCurrentScript())) . '/';
$siteUrl = substr($url, 0, -strlen($lPath));
if (substr($siteUrl, -1) !== '/') {
Expand Down Expand Up @@ -3083,7 +3083,7 @@ public static function getHostname($requestHost = true)
/**
* Returns the absolute filename of a relative reference, resolves the "EXT:" prefix
* (way of referring to files inside extensions) and checks that the file is inside
* the PATH_site of the TYPO3 installation and implies a check with
* the TYPO3's base folder and implies a check with
* \TYPO3\CMS\Core\Utility\GeneralUtility::validPathStr().
*
* @param string $filename The input filename/filepath to evaluate
Expand All @@ -3102,8 +3102,8 @@ public static function getFileAbsFileName($filename)
$filename = ExtensionManagementUtility::extPath($extKey) . $local;
}
} elseif (!static::isAbsPath($filename)) {
// is relative. Prepended with PATH_site
$filename = PATH_site . $filename;
// is relative. Prepended with the public web folder
$filename = Environment::getPublicPath() . '/' . $filename;
} elseif (!(
static::isFirstPartOfStr($filename, Environment::getProjectPath())
|| static::isFirstPartOfStr($filename, Environment::getPublicPath())
Expand Down Expand Up @@ -3147,7 +3147,7 @@ public static function isAbsPath($path)
}

/**
* Returns TRUE if the path is absolute, without backpath '..' and within the PATH_site OR within the lockRootPath
* Returns TRUE if the path is absolute, without backpath '..' and within TYPO3s project or public folder OR within the lockRootPath
*
* @param string $path File path to evaluate
* @return bool
Expand Down Expand Up @@ -3189,11 +3189,11 @@ public static function verifyFilenameAgainstDenyPattern($filename)
*/
public static function copyDirectory($source, $destination)
{
if (strpos($source, PATH_site) === false) {
$source = PATH_site . $source;
if (strpos($source, Environment::getPublicPath() . '/') === false) {
$source = Environment::getPublicPath() . '/' . $source;
}
if (strpos($destination, PATH_site) === false) {
$destination = PATH_site . $destination;
if (strpos($destination, Environment::getPublicPath() . '/') === false) {
$destination = Environment::getPublicPath() . '/' . $destination;
}
if (static::isAllowedAbsPath($source) && static::isAllowedAbsPath($destination)) {
static::mkdir_deep($destination);
Expand Down Expand Up @@ -3287,7 +3287,7 @@ public static function upload_copy_move($source, $destination)
/**
* Will move an uploaded file (normally in "/tmp/xxxxx") to a temporary filename in Environment::getProjectPath() . "var/" from where TYPO3 can use it.
* Use this function to move uploaded files to where you can work on them.
* REMEMBER to use \TYPO3\CMS\Core\Utility\GeneralUtility::unlink_tempfile() afterwards - otherwise temp-files will build up! They are NOT automatically deleted in PATH_site."typo3temp/"!
* REMEMBER to use \TYPO3\CMS\Core\Utility\GeneralUtility::unlink_tempfile() afterwards - otherwise temp-files will build up! They are NOT automatically deleted in the temporary folder!
*
* @param string $uploadedFileName The temporary uploaded filename, eg. $_FILES['[upload field name here]']['tmp_name']
* @return string If a new file was successfully created, return its filename, otherwise blank string.
Expand All @@ -3311,11 +3311,11 @@ public static function upload_to_tempfile($uploadedFileName)
}

/**
* Deletes (unlink) a temporary filename in 'PATH_site."typo3temp/"' given as input.
* The function will check that the file exists, is in PATH_site."typo3temp/" and does not contain back-spaces ("../") so it should be pretty safe.
* Deletes (unlink) a temporary filename in the var/ or typo3temp folder given as input.
* The function will check that the file exists, is within TYPO3's var/ or typo3temp/ folder and does not contain back-spaces ("../") so it should be pretty safe.
* Use this after upload_to_tempfile() or tempnam() from this class!
*
* @param string $uploadedTempFileName Filepath for a file in PATH_site."typo3temp/". Must be absolute.
* @param string $uploadedTempFileName absolute file path - must reside within var/ or typo3temp/ folder.
* @return bool Returns TRUE if the file was unlink()'ed
* @see upload_to_tempfile(), tempnam()
*/
Expand All @@ -3326,7 +3326,7 @@ public static function unlink_tempfile($uploadedTempFileName)
if (
self::validPathStr($uploadedTempFileName)
&& (
self::isFirstPartOfStr($uploadedTempFileName, PATH_site . 'typo3temp/')
self::isFirstPartOfStr($uploadedTempFileName, Environment::getPublicPath() . '/typo3temp/')
|| self::isFirstPartOfStr($uploadedTempFileName, Environment::getVarPath() . '/')
)
&& @is_file($uploadedTempFileName)
Expand All @@ -3345,7 +3345,7 @@ public static function unlink_tempfile($uploadedTempFileName)
*
* @param string $filePrefix Prefix for temporary file
* @param string $fileSuffix Suffix for temporary file, for example a special file extension
* @return string result from PHP function tempnam() with PATH_site . 'typo3temp/' set for temp path.
* @return string result from PHP function tempnam() with the temp/var folder prefixed.
* @see unlink_tempfile(), upload_to_tempfile()
*/
public static function tempnam($filePrefix, $fileSuffix = '')
Expand Down Expand Up @@ -3995,7 +3995,7 @@ public static function logDeprecatedViewHelperAttribute(string $property, Render
$renderingContext->getControllerName(),
$renderingContext->getControllerAction()
);
$template = str_replace(PATH_site, '', $template);
$template = str_replace(Environment::getPublicPath() . '/', '', $template);
$message = [];
$message[] = '[' . $template . ']';
$message[] = 'The property "' . $property . '" has been marked as deprecated.';
Expand All @@ -4013,7 +4013,7 @@ public static function logDeprecatedViewHelperAttribute(string $property, Render
public static function getDeprecationLogFileName()
{
static::writeDeprecationLogFileEntry(__METHOD__ . ' is deprecated since TYPO3 v9.0, will be removed in TYPO3 v10.0');
return Environment::getVarPath() . '/log/deprecation_' . self::shortMD5(PATH_site . $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']) . '.log';
return Environment::getVarPath() . '/log/deprecation_' . self::shortMD5(Environment::getProjectPath() . $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']) . '.log';
}

/**
Expand Down Expand Up @@ -4180,7 +4180,7 @@ private static function writeDeprecationLogFileEntry($msg)
{
$date = date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] . ' ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'] . ': ');
// Write a longer message to the deprecation log
$destination = Environment::getVarPath() . '/log/deprecation_' . self::shortMD5(PATH_site . $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']) . '.log';
$destination = Environment::getVarPath() . '/log/deprecation_' . self::shortMD5(Environment::getProjectPath() . $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']) . '.log';
$file = @fopen($destination, 'a');
if ($file) {
@fwrite($file, $date . $msg . LF);
Expand Down
@@ -0,0 +1,45 @@
.. include:: ../../Includes.txt

=======================================================
Deprecation: #85285 - Deprecated path related constants
=======================================================

See :issue:`85285`

Description
===========

The following constants have been deprecated and should not be used any longer:

* :php:`PATH_thisScript`
Use :php:`Environment::getCurrentScript()` instead

* :php:`PATH_site`
Use :php:`Environment::getPublicPath() . '/'` instead


Impact
======

The above constants are still defined in TYPO3 v9, but their definition will be
dropped in v10.


Affected Installations
======================

Constants can not be deprecated as such and using them does not log a deprecation message.
Extensions in v9 should not use them any longer but switch to the alternatives already.

The extension scanner will find usages of the above constants and marks them as strong
matches.



Migration
=========

Usages of the above constants should be switched to the Environment class methods instead.


.. index:: PHP-API, FullyScanned
Expand Up @@ -21,8 +21,6 @@
*/
class GeneralUtilityFixture extends GeneralUtility
{
const DEPRECATION_LOG_PATH = 'typo3temp/var/test_deprecation/test.log';

/**
* @var int
*/
Expand Down Expand Up @@ -58,16 +56,6 @@ protected static function isInternalRequestType()
return false;
}

/**
* Gets the absolute path to the deprecation log file.
*
* @return string Absolute path to the deprecation log file
*/
public static function getDeprecationLogFileName()
{
return PATH_site . static::DEPRECATION_LOG_PATH;
}

/**
* Resets the internal computed class name cache.
*/
Expand Down
Expand Up @@ -4122,10 +4122,10 @@ public function set_no_cache($reason = '', $internal = false)
} else {
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
// This is a hack to work around ___FILE___ resolving symbolic links
$PATH_site_real = PathUtility::dirname(realpath(Environment::getPublicPath() . '/typo3')) . '/';
$realWebPath = PathUtility::dirname(realpath(Environment::getPublicPath() . '/typo3')) . '/';
$file = $trace[0]['file'];
if (strpos($file, $PATH_site_real) === 0) {
$file = str_replace($PATH_site_real, '', $file);
if (strpos($file, $realWebPath) === 0) {
$file = str_replace($realWebPath, '', $file);
} else {
$file = str_replace(Environment::getPublicPath() . '/', '', $file);
}
Expand Down
Expand Up @@ -65,4 +65,10 @@
'Deprecation-85123-ConstantsRelatedToServices.rst',
],
],
'PATH_thisScript' => [
'restFiles' => [
'Feature-84153-IntroduceAGenericEnvironmentClass.rst',
'Deprecation-85285-DeprecatedSystemConstants.rst',
],
],
];

0 comments on commit 2dd2e0e

Please sign in to comment.