Commit a2800b04 authored by Marc Egger's avatar Marc Egger
Browse files

Path: set log path absolute instead of realtive to CWD

parent c049da9e
Pipeline #4068 passed with stages
in 3 minutes and 54 seconds
......@@ -16,7 +16,8 @@ namespace IMATHUZH\Qfq\Core\Helper;
* 3) if a path has to be variable, create a setter and getter. E.g. self::setCwdToApp(), self::cwdToApp(), private static $cwdToApp.
* 4) a path getter appends the given arguments to the requested path using self::join(..., func_get_args()). E.g. see cwdToApp().
* 5) additional path getters may be defined which combine other getters. E.g. see cwdToApi().
* 6) avoid defining redundant paths in constants. E.g. create cwdToApi() by combining cwdToExt() and extToApi() instead of defining CWD_TO_API.
* 6) avoid manually defining new paths relative to cwd. Define path relative to App then combine it with cwdToApp()
* 7) avoid defining redundant paths in constants. E.g. create cwdToApi() by combining cwdToExt() and extToApi() instead of defining CWD_TO_API.
*/
use IMATHUZH\Qfq\Core\Exception\Thrower;
......@@ -44,7 +45,7 @@ class Path
const EXT_TO_PATH_ICONS = 'Resources/Public/icons';
// Annotate
const EXT_TO_HIGHLIGHT_JSON_DIR = 'Resources/Public/Json'; // TODO: refactor: remove DIR at the end
const EXT_TO_HIGHLIGHT_JSON_DIR = 'Resources/Public/Json'; // TODO: refactor: remove DIR at the end of the constant name
// Twig
const EXT_TO_TWIG_TEMPLATES = 'Resources/Public/twig_templates';
......@@ -63,7 +64,7 @@ class Path
const APP_TO_TYPO3_CONF = 'typo3conf';
// Log files
private static $cwdToLog = null;
private static $absoluteLog = null;
private static $overloadAbsoluteQfqLogFile = null;
private static $overloadAbsoluteMailLogFile = null;
private static $overloadAbsoluteSqlLogFile = null;
......@@ -71,7 +72,7 @@ class Path
private const LOG_TO_MAIL_LOG_FILE_DEFAULT = 'mail.log';
private const LOG_TO_SQL_LOG_FILE_DEFAULT = 'sql.log';
private const PROJECT_TO_LOG_DEFAULT = 'log';
private const APP_TO_LOG_DEPRECATED = 'fileadmin/protected/log';
private const APP_TO_LOG_IN_PROTECTED = 'fileadmin/protected/log';
// Thumbnail
const APP_TO_SYSTEM_THUMBNAIL_DIR_SECURE_DEFAULT = 'fileadmin/protected/qfqThumbnail';
......@@ -93,8 +94,8 @@ class Path
public static function setMainPaths(string $cwdToApp)
{
self::setCwdToApp($cwdToApp);
self::findAndSetProjectPath();
self::findAndSetLogPath();
self::findAppToProject();
self::findAbsoluteLog();
}
/**
......@@ -124,7 +125,8 @@ class Path
*/
public static function absoluteLog(...$pathPartsToAppend): string
{
return self::realpath(self::cwdToLog(), $pathPartsToAppend);
self::enforcePathIsSet(self::$absoluteLog);
return self::join(self::$absoluteLog, $pathPartsToAppend);
}
/**
......@@ -163,17 +165,6 @@ class Path
return self::$overloadAbsoluteMailLogFile;
}
/**
* @param array $pathPartsToAppend
* @return string
* @throws \UserFormException
*/
public static function cwdToLog(...$pathPartsToAppend): string
{
self::enforcePathIsSet(self::$cwdToLog);
return self::join(self::$cwdToLog, $pathPartsToAppend);
}
/**
* @param array $pathPartsToAppend
* @return string
......@@ -385,9 +376,9 @@ class Path
* @param string $newPath
* @return string
*/
private static function setCwdToLog(string $newPath)
private static function setAbsoluteLog(string $newPath)
{
self::$cwdToLog = $newPath;
self::$absoluteLog = $newPath;
}
/**
......@@ -398,21 +389,21 @@ class Path
*
* @throws \UserFormException
*/
private static function findAndSetLogPath()
private static function findAbsoluteLog()
{
// search log dir qfqProject/log
$cwdToLog = self::cwdToProject(self::PROJECT_TO_LOG_DEFAULT);
if (file_exists($cwdToLog)) {
self::setCwdToLog($cwdToLog);
$absoluteLog = self::absoluteApp(self::appToProject(self::PROJECT_TO_LOG_DEFAULT));
if (file_exists($absoluteLog)) {
self::setAbsoluteLog($absoluteLog);
// search log dir fileadmin/protected/log
} elseif (file_exists(self::cwdToApp(self::APP_TO_LOG_DEPRECATED))) {
self::setCwdToLog(self::cwdToApp(self::APP_TO_LOG_DEPRECATED));
} elseif (file_exists(self::absoluteApp(self::APP_TO_LOG_IN_PROTECTED))) {
self::setAbsoluteLog(self::absoluteApp(self::APP_TO_LOG_IN_PROTECTED));
// create default log dir qfqProject/log
} else {
HelperFile::createPathRecursive($cwdToLog);
self::setCwdToLog($cwdToLog);
HelperFile::createPathRecursive($absoluteLog);
self::setAbsoluteLog($absoluteLog);
}
}
......@@ -422,7 +413,7 @@ class Path
* @throws \CodeException
* @throws \UserFormException
*/
private static function findAndSetProjectPath()
private static function findAppToProject()
{
// does qfq.project.path.php exist? => read path
$cwdToProjectPathFile = self::cwdToApp(PROJECT_PATH_PHP_FILE);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment