Commit cf275dd2 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Merge branch 'develop' into 'master'

Develop

See merge request !349
parents 739a7f7d c2cc7ffe
Pipeline #5246 passed with stages
in 3 minutes and 25 seconds
...@@ -657,14 +657,14 @@ class BuildFormBootstrap extends AbstractBuildForm { ...@@ -657,14 +657,14 @@ class BuildFormBootstrap extends AbstractBuildForm {
$actionUpload = FILE_ACTION . '=' . FILE_ACTION_UPLOAD; $actionUpload = FILE_ACTION . '=' . FILE_ACTION_UPLOAD;
$actionDelete = FILE_ACTION . '=' . FILE_ACTION_DELETE; $actionDelete = FILE_ACTION . '=' . FILE_ACTION_DELETE;
$apiDeletePhp = Path::appToApi(API_DELETE_PHP); $apiDeletePhp = Path::urlApi(API_DELETE_PHP);
$dirtyAction = ($this->formSpec[F_DIRTY_MODE] == DIRTY_MODE_NONE) ? '' : "dirtyUrl: '" . Path::appToApi(API_DIRTY_PHP) . "',"; $dirtyAction = ($this->formSpec[F_DIRTY_MODE] == DIRTY_MODE_NONE) ? '' : "dirtyUrl: '" . Path::urlApi(API_DIRTY_PHP) . "',";
$submitTo = Path::appToApi(API_SAVE_PHP); $submitTo = Path::urlApi(API_SAVE_PHP);
$refreshUrl = Path::appToApi(API_LOAD_PHP); $refreshUrl = Path::urlApi(API_LOAD_PHP);
$fileUploadTo = Path::appToApi(API_FILE_PHP) . '?' . $actionUpload; $fileUploadTo = Path::urlApi(API_FILE_PHP) . '?' . $actionUpload;
$fileDeleteUrl = Path::appToApi(API_FILE_PHP) . '?' . $actionDelete; $fileDeleteUrl = Path::urlApi(API_FILE_PHP) . '?' . $actionDelete;
$html .= '</form>'; // <form class="form-horizontal" ... $html .= '</form>'; // <form class="form-horizontal" ...
$html .= <<<EOF $html .= <<<EOF
......
...@@ -552,6 +552,8 @@ const SYSTEM_FORM_BS_NOTE_COLUMNS = 'formBsNoteColumns'; ...@@ -552,6 +552,8 @@ const SYSTEM_FORM_BS_NOTE_COLUMNS = 'formBsNoteColumns';
const SYSTEM_BASE_URL = 'baseUrl'; const SYSTEM_BASE_URL = 'baseUrl';
const SYSTEM_PASWORD_HASH_TYPE = 'PASSWORD_HASH_TYPE';
const SYSTEM_SEND_E_MAIL_OPTIONS = 'sendEMailOptions'; const SYSTEM_SEND_E_MAIL_OPTIONS = 'sendEMailOptions';
const SYSTEM_EDIT_FORM_PAGE = 'editFormPage'; const SYSTEM_EDIT_FORM_PAGE = 'editFormPage';
...@@ -1119,6 +1121,7 @@ const FE_BS_INPUT_COLUMNS = F_BS_INPUT_COLUMNS; ...@@ -1119,6 +1121,7 @@ const FE_BS_INPUT_COLUMNS = F_BS_INPUT_COLUMNS;
const FE_BS_NOTE_COLUMNS = F_BS_NOTE_COLUMNS; const FE_BS_NOTE_COLUMNS = F_BS_NOTE_COLUMNS;
const FE_WRAP_ROW_LABEL_INPUT_NOTE = 'rowLabelInputNote'; const FE_WRAP_ROW_LABEL_INPUT_NOTE = 'rowLabelInputNote';
const FE_MAX_LENGTH = 'maxLength'; const FE_MAX_LENGTH = 'maxLength';
const FE_MAX_LENGTH_COLUMN = 'maxLengthColumn';
const FE_PARAMETER = 'parameter'; const FE_PARAMETER = 'parameter';
const FE_ENCODE = 'encode'; const FE_ENCODE = 'encode';
const FE_CHECK_TYPE = 'checkType'; const FE_CHECK_TYPE = 'checkType';
...@@ -2060,3 +2063,6 @@ const I_UNCHECKED = 'unchecked'; ...@@ -2060,3 +2063,6 @@ const I_UNCHECKED = 'unchecked';
// Rest Client // Rest Client
const HTTP_STATUS = 'http-status'; const HTTP_STATUS = 'http-status';
const ERROR_MESSAGE = 'error-message'; const ERROR_MESSAGE = 'error-message';
// Misc
const BASE_DIR_FAKE = 'http://xxxxxxxxxxxxxxxxxxxxxxxxxxxx/qfq/';
...@@ -318,7 +318,7 @@ class Evaluate { ...@@ -318,7 +318,7 @@ class Evaluate {
$this->store::setVar(SYSTEM_DRAG_AND_DROP_JS, 'true', STORE_SYSTEM); $this->store::setVar(SYSTEM_DRAG_AND_DROP_JS, 'true', STORE_SYSTEM);
// data-dnd-api="typo3conf/ext/qfq/qfq/Api/dragAndDrop.php?s={{'U:form=<form name>[&paramX=<any value>]|s|r:8' AS _link}}" // data-dnd-api="typo3conf/ext/qfq/qfq/Api/dragAndDrop.php?s={{'U:form=<form name>[&paramX=<any value>]|s|r:8' AS _link}}"
return DND_DATA_DND_API . '="' . Path::appToApi(API_DRAG_AND_DROP_PHP) . '?s=' . $s . '"'; return DND_DATA_DND_API . '="' . Path::urlApi(API_DRAG_AND_DROP_PHP) . '?s=' . $s . '"';
} }
/** /**
......
...@@ -457,7 +457,7 @@ class HelperFile { ...@@ -457,7 +457,7 @@ class HelperFile {
} }
if (isset($extToFileType[$ext])) { if (isset($extToFileType[$ext])) {
return Path::appToExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/' . $extToFileType[$ext]; return Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/' . $extToFileType[$ext];
} }
return ''; return '';
......
...@@ -3,14 +3,17 @@ ...@@ -3,14 +3,17 @@
namespace IMATHUZH\Qfq\Core\Helper; namespace IMATHUZH\Qfq\Core\Helper;
/* /**
* Glossar: * Glossary:
* - App: directory in which the index.php file is located. All urls should be relative to this. * - App: directory in which the index.php file is located. All urls should be relative to this.
* - Ext: directory in which the QFQ extension is loacted. e.g. the folder Classes is in there. * - Ext: directory in which the QFQ extension is located. e.g. the folder Classes is in there.
* - API: api folder of qfq extension * - API: api folder of qfq extension
* *
* Naming convention of path constants/functions/variables: * Conventions of Path class:
* 1) name a path by its origin and its destination separated by 'to'. E.g. APP_TO_SYSTEM_LOG, $appToProject. * 1) naming conventions of of path constants/functions/variables:
* a) name a path by its origin and its destination separated by 'to'. E.g. APP_TO_SYSTEM_LOG, $appToProject.
* b) Or only by its destination and prefix "absolute" if the path is absolute e.g. absoluteApp().
* c) Or by its destination and prefix "url" if the path returns a fully qualified url using the base path e.g. urlExt().
* 2) if the destination is a file, append "File". E.g. APP_TO_SYSTEM_QFQ_LOG_FILE. * 2) if the destination is a file, append "File". E.g. APP_TO_SYSTEM_QFQ_LOG_FILE.
* 3) if a path has to be variable, create a setter and getter. E.g. self::setAbsoluteApp(), self::absoluteApp(), private static $absoluteApp. * 3) if a path has to be variable, create a setter and getter. E.g. self::setAbsoluteApp(), self::absoluteApp(), private static $absoluteApp.
* 4) a path getter appends the given arguments to the requested path using self::join(..., func_get_args()). E.g. see absoluteApp(). * 4) a path getter appends the given arguments to the requested path using self::join(..., func_get_args()). E.g. see absoluteApp().
...@@ -22,11 +25,10 @@ namespace IMATHUZH\Qfq\Core\Helper; ...@@ -22,11 +25,10 @@ namespace IMATHUZH\Qfq\Core\Helper;
use IMATHUZH\Qfq\Core\Exception\Thrower; use IMATHUZH\Qfq\Core\Exception\Thrower;
use IMATHUZH\Qfq\Core\Store\Config; use IMATHUZH\Qfq\Core\Store\Config;
class Path class Path {
{
// App // App
// This is manually set in self::setMainPaths()
private static $absoluteApp = null; private static $absoluteApp = null;
private static $urlApp = null;
// Extension // Extension
const APP_TO_EXT = 'typo3conf/ext/qfq'; const APP_TO_EXT = 'typo3conf/ext/qfq';
...@@ -89,34 +91,18 @@ class Path ...@@ -89,34 +91,18 @@ class Path
// Send Email // Send Email
const EXT_TO_SEND_EMAIL_FILE = 'Classes/External/sendEmail'; const EXT_TO_SEND_EMAIL_FILE = 'Classes/External/sendEmail';
/**
* Manually set the paths which are not constant nor can be inferred by other paths.
* This function must be called at the beginning of every entry point, to tell the Path class, where things are.
*
* @param string|null $absoluteApp
* @throws \CodeException
* @throws \UserFormException
*/
public static function setMainPaths(string $absoluteApp = null)
{
if (is_null($absoluteApp)) {
$absoluteApp = self::findAbsoluteApp();
}
self::setAbsoluteApp($absoluteApp);
// Only executed on first call:
self::findAppToProject();
self::findAbsoluteLog();
}
/** /**
* @param array $pathPartsToAppend * @param array $pathPartsToAppend
* @return string * @return string
* @throws \UserFormException * @throws \UserFormException
*/ */
public static function absoluteApp(...$pathPartsToAppend): string public static function absoluteApp(...$pathPartsToAppend): string {
{ if (is_null(self::$absoluteApp)) {
self::enforcePathIsSet(self::$absoluteApp); self::findAbsoluteApp();
}
if (is_null(self::$absoluteApp)) {
Thrower::userFormException('Path not set.', 'Absolute app path is null. This should not happen at this point.');
}
return self::join(self::$absoluteApp, $pathPartsToAppend); return self::join(self::$absoluteApp, $pathPartsToAppend);
} }
...@@ -125,8 +111,7 @@ class Path ...@@ -125,8 +111,7 @@ class Path
* @return string * @return string
* @throws \UserFormException * @throws \UserFormException
*/ */
public static function absoluteExt(...$pathPartsToAppend): string public static function absoluteExt(...$pathPartsToAppend): string {
{
return self::absoluteApp(self::appToExt(), $pathPartsToAppend); return self::absoluteApp(self::appToExt(), $pathPartsToAppend);
} }
...@@ -135,12 +120,13 @@ class Path ...@@ -135,12 +120,13 @@ class Path
* @return string * @return string
* @throws \UserFormException * @throws \UserFormException
*/ */
public static function absoluteLog(...$pathPartsToAppend): string public static function absoluteLog(...$pathPartsToAppend): string {
{
if (is_null(self::$absoluteLog)) { if (is_null(self::$absoluteLog)) {
self::findAbsoluteLog(); self::findAbsoluteLog();
} }
self::enforcePathIsSet(self::$absoluteLog); if (is_null(self::$absoluteLog)) {
Thrower::userFormException('Path not set.', 'Absolute log path is null. This should not happen at this point.');
}
return self::join(self::$absoluteLog, $pathPartsToAppend); return self::join(self::$absoluteLog, $pathPartsToAppend);
} }
...@@ -148,8 +134,7 @@ class Path ...@@ -148,8 +134,7 @@ class Path
* @return string * @return string
* @throws \UserFormException * @throws \UserFormException
*/ */
public static function absoluteSqlLogFile(): string public static function absoluteSqlLogFile(): string {
{
if (is_null(self::$overloadAbsoluteSqlLogFile)) { if (is_null(self::$overloadAbsoluteSqlLogFile)) {
return self::absoluteLog(self::LOG_TO_SQL_LOG_FILE_DEFAULT); return self::absoluteLog(self::LOG_TO_SQL_LOG_FILE_DEFAULT);
} }
...@@ -160,8 +145,7 @@ class Path ...@@ -160,8 +145,7 @@ class Path
* @return string * @return string
* @throws \UserFormException * @throws \UserFormException
*/ */
public static function absoluteQfqLogFile(): string public static function absoluteQfqLogFile(): string {
{
if (is_null(self::$overloadAbsoluteQfqLogFile)) { if (is_null(self::$overloadAbsoluteQfqLogFile)) {
return self::absoluteLog(self::LOG_TO_QFQ_LOG_FILE_DEFAULT); return self::absoluteLog(self::LOG_TO_QFQ_LOG_FILE_DEFAULT);
} }
...@@ -172,8 +156,7 @@ class Path ...@@ -172,8 +156,7 @@ class Path
* @return string * @return string
* @throws \UserFormException * @throws \UserFormException
*/ */
public static function absoluteMailLogFile(): string public static function absoluteMailLogFile(): string {
{
if (is_null(self::$overloadAbsoluteMailLogFile)) { if (is_null(self::$overloadAbsoluteMailLogFile)) {
return self::absoluteLog(self::LOG_TO_MAIL_LOG_FILE_DEFAULT); return self::absoluteLog(self::LOG_TO_MAIL_LOG_FILE_DEFAULT);
} }
...@@ -183,11 +166,16 @@ class Path ...@@ -183,11 +166,16 @@ class Path
/** /**
* @param array $pathPartsToAppend * @param array $pathPartsToAppend
* @return string * @return string
* @throws \CodeException
* @throws \UserFormException * @throws \UserFormException
*/ */
public static function appToProject(...$pathPartsToAppend): string public static function appToProject(...$pathPartsToAppend): string {
{ if (is_null(self::$appToProject)) {
self::enforcePathIsSet(self::$appToProject); self::findAppToProject();
}
if (is_null(self::$appToProject)) {
Thrower::userFormException('Path not set.', 'Project path is null. This should not happen at this point.');
}
return self::join(self::$appToProject, $pathPartsToAppend); return self::join(self::$appToProject, $pathPartsToAppend);
} }
...@@ -196,8 +184,7 @@ class Path ...@@ -196,8 +184,7 @@ class Path
* @return string * @return string
* @throws \UserFormException * @throws \UserFormException
*/ */
public static function absoluteProject(...$pathPartsToAppend): string public static function absoluteProject(...$pathPartsToAppend): string {
{
return self::absoluteApp(self::appToProject($pathPartsToAppend)); return self::absoluteApp(self::appToProject($pathPartsToAppend));
} }
...@@ -206,8 +193,7 @@ class Path ...@@ -206,8 +193,7 @@ class Path
* @return string * @return string
* @throws \UserFormException * @throws \UserFormException
*/ */
public static function absoluteConf(...$pathPartsToAppend): string public static function absoluteConf(...$pathPartsToAppend): string {
{
return self::absoluteProject(self::PROJECT_TO_CONF, $pathPartsToAppend); return self::absoluteProject(self::PROJECT_TO_CONF, $pathPartsToAppend);
} }
...@@ -216,19 +202,36 @@ class Path ...@@ -216,19 +202,36 @@ class Path
* @return string * @return string
* @throws \UserFormException * @throws \UserFormException
*/ */
public static function appToExt(...$pathPartsToAppend): string public static function appToExt(...$pathPartsToAppend): string {
{
return self::join(self::APP_TO_EXT, $pathPartsToAppend); return self::join(self::APP_TO_EXT, $pathPartsToAppend);
} }
/**
* @param mixed ...$pathPartsToAppend
* @return string
* @throws \CodeException
* @throws \UserFormException
* @throws \UserReportException
*/
public static function urlApp(...$pathPartsToAppend): string {
if (is_null(self::$urlApp)) {
self::setUrlApp(Config::get(SYSTEM_BASE_URL));
}
// ensure base url is configured
if (is_null(self::$urlApp) || self::$urlApp === '') {
Thrower::userFormException('Base url not configured.', 'Go to QFQ extension configuration in the Typo3 backend and fill in a value for config.baseUrl');
}
return self::join(self::$urlApp, $pathPartsToAppend);
}
/** /**
* @param array $pathPartsToAppend * @param array $pathPartsToAppend
* @return string * @return string
* @throws \UserFormException * @throws \UserFormException
*/ */
public static function extToApi(...$pathPartsToAppend): string public static function urlExt(...$pathPartsToAppend): string {
{ return self::urlApp(self::appToExt($pathPartsToAppend));
return self::join(self::EXT_TO_API, $pathPartsToAppend);
} }
/** /**
...@@ -236,17 +239,24 @@ class Path ...@@ -236,17 +239,24 @@ class Path
* @return string * @return string
* @throws \UserFormException * @throws \UserFormException
*/ */
public static function appToApi(...$pathPartsToAppend): string public static function appToApi(...$pathPartsToAppend): string {
{
return self::join(self::APP_TO_EXT, self::EXT_TO_API, $pathPartsToAppend); return self::join(self::APP_TO_EXT, self::EXT_TO_API, $pathPartsToAppend);
} }
/**
* @param array $pathPartsToAppend
* @return string
* @throws \UserFormException
*/
public static function urlApi(...$pathPartsToAppend): string {
return self::urlApp(self::appToApi($pathPartsToAppend));
}
/** /**
* @param mixed ...$pathPartsToAppend * @param mixed ...$pathPartsToAppend
* @return string * @return string
*/ */
public static function projectToForm(...$pathPartsToAppend) : string public static function projectToForm(...$pathPartsToAppend): string {
{
$projectToForm = is_null(self::$projectToForm) ? self::PROJECT_TO_FORM_DEFAULT : self::$projectToForm; $projectToForm = is_null(self::$projectToForm) ? self::PROJECT_TO_FORM_DEFAULT : self::$projectToForm;
return self::join($projectToForm, $pathPartsToAppend); return self::join($projectToForm, $pathPartsToAppend);
} }
...@@ -255,8 +265,7 @@ class Path ...@@ -255,8 +265,7 @@ class Path
* @param mixed ...$pathPartsToAppend * @param mixed ...$pathPartsToAppend
* @return string * @return string
*/ */
public static function projectToReport(...$pathPartsToAppend) : string public static function projectToReport(...$pathPartsToAppend): string {
{
$projectToReport = is_null(self::$projectToReport) ? self::PROJECT_TO_REPORT_DEFAULT : self::$projectToReport; $projectToReport = is_null(self::$projectToReport) ? self::PROJECT_TO_REPORT_DEFAULT : self::$projectToReport;
return self::join($projectToReport, $pathPartsToAppend); return self::join($projectToReport, $pathPartsToAppend);
} }
...@@ -264,16 +273,14 @@ class Path ...@@ -264,16 +273,14 @@ class Path
/** /**
* @param string $newPath * @param string $newPath
*/ */
public static function setProjectToForm(string $newPath) public static function setProjectToForm(string $newPath) {
{
self::$projectToForm = $newPath; self::$projectToForm = $newPath;
} }
/** /**
* @param string $newPath * @param string $newPath
*/ */
public static function setProjectToReport(string $newPath) public static function setProjectToReport(string $newPath) {
{
self::$projectToReport = $newPath; self::$projectToReport = $newPath;
} }
...@@ -281,8 +288,7 @@ class Path ...@@ -281,8 +288,7 @@ class Path
* @param string $newPath * @param string $newPath
* @throws \UserFormException * @throws \UserFormException
*/ */
public static function setAbsoluteSqlLogFile(string $newPath) public static function setAbsoluteSqlLogFile(string $newPath) {
{
self::enforcePathIsAbsolute($newPath); self::enforcePathIsAbsolute($newPath);
self::$overloadAbsoluteSqlLogFile = $newPath; self::$overloadAbsoluteSqlLogFile = $newPath;
} }
...@@ -291,8 +297,7 @@ class Path ...@@ -291,8 +297,7 @@ class Path
* @param string $newPath * @param string $newPath
* @throws \UserFormException * @throws \UserFormException
*/ */
public static function setAbsoluteQfqLogFile(string $newPath) public static function setAbsoluteQfqLogFile(string $newPath) {
{
self::enforcePathIsAbsolute($newPath); self::enforcePathIsAbsolute($newPath);
self::$overloadAbsoluteQfqLogFile = $newPath; self::$overloadAbsoluteQfqLogFile = $newPath;
} }
...@@ -301,12 +306,18 @@ class Path ...@@ -301,12 +306,18 @@ class Path
* @param string $newPath * @param string $newPath
* @throws \UserFormException * @throws \UserFormException
*/ */
public static function setAbsoluteMailLogFile(string $newPath) public static function setAbsoluteMailLogFile(string $newPath) {
{
self::enforcePathIsAbsolute($newPath); self::enforcePathIsAbsolute($newPath);
self::$overloadAbsoluteMailLogFile = $newPath; self::$overloadAbsoluteMailLogFile = $newPath;
} }
/**
* @param $urlApp
*/
public static function setUrlApp($urlApp) {
self::$urlApp = $urlApp;
}
/** /**
* Override the paths of sql.log, qfq.log, mail.log using the values from the config file or Typo3. * Override the paths of sql.log, qfq.log, mail.log using the values from the config file or Typo3.
* *
...@@ -314,8 +325,7 @@ class Path ...@@ -314,8 +325,7 @@ class Path
* @throws \UserFormException * @throws \UserFormException
* @throws \UserReportException * @throws \UserReportException
*/ */
public static function overrideLogPathsFromConfig() public static function overrideLogPathsFromConfig() {
{
// QFQ log // QFQ log
$absoluteQfqLogFile = Config::get(SYSTEM_QFQ_LOG_PATHFILENAME); $absoluteQfqLogFile = Config::get(SYSTEM_QFQ_LOG_PATHFILENAME);
if (!empty($absoluteQfqLogFile)) { if (!empty($absoluteQfqLogFile)) {
...@@ -343,8 +353,7 @@ class Path ...@@ -343,8 +353,7 @@ class Path
* @return string * @return string
* @throws \UserFormException * @throws \UserFormException
*/ */
public static function joinIfNotAbsolute (string $path1, string $path2): string public static function joinIfNotAbsolute(string $path1, string $path2): string {
{
if ($path2 !== '' && $path2[0] === '/') { if ($path2 !== '' && $path2[0] === '/') {
return $path2; return $path2;
} }
...@@ -360,8 +369,7 @@ class Path ...@@ -360,8 +369,7 @@ class Path
* @param array $pathPartsToAppend * @param array $pathPartsToAppend
* @return string * @return string
*/ */
public static function join(...$pathPartsToAppend): string public static function join(...$pathPartsToAppend): string {
{
$parts = $pathPartsToAppend; $parts = $pathPartsToAppend;
// concatenate all parts (arrays are flattened) // concatenate all parts (arrays are flattened)
...@@ -390,34 +398,36 @@ class Path ...@@ -390,34 +398,36 @@ class Path
} }
}); });
// remove multiple occurrences of '/' // remove multiple occurrences of '/' (but keep http://)
return preg_replace('/\/{2,}/','/', $path); if (preg_match('/^\w*:\/\//', $path, $match)) {
} $protocol = $match[0];
$path = substr($path, strlen($protocol));
} else {
$protocol = '';
}
$path = preg_replace('/\/{2,}/', '/', $path);
/////////////////////////////////////////////////// Private ////////////////////////////////////////////////////// return $protocol . $path;
}
/** /**
* @param string $newPath * @param string $newPath
*/ */
private static function setAbsoluteApp(string $newPath) public static function setAbsoluteApp(string $newPath) {
{
self::$absoluteApp = $newPath; self::$absoluteApp = $newPath;
} }
/** /**
* @param string $newPath * @param string $newPath
*/ */
private static function setAppToProject(string $newPath) private static function setAppToProject(string $newPath) {
{
self::$appToProject = $newPath; self::$appToProject = $newPath;
} }
/** /**
* @param string $newPath * @param string $newPath
* @return string
*/ */
private static function setAbsoluteLog(string $newPath)