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

move config into 'conf' dir and improve error message

parent 75a9cff8
Pipeline #4854 failed with stages
in 3 minutes and 41 seconds
......@@ -64,7 +64,7 @@ selenium:
- cd docker; ./remove-containers.sh <<< "y"
- cd ..
- umask 002
- mkdir "$SELENIUM_LOGS_PATH/$CI_COMMIT_SHORT_SHA"
- mkdir -p "$SELENIUM_LOGS_PATH/$CI_COMMIT_SHORT_SHA"
- cp extension/Tests/selenium/selenium_logs/* "$SELENIUM_LOGS_PATH/$CI_COMMIT_SHORT_SHA/"
- echo "Selenium Logs copied to $SELENIUM_LOGS_PATH/$CI_COMMIT_SHORT_SHA/"
- echo "Or download result (log/screenshot) in gitlab under CI/CD > Pipelines <job> > right side 'Artifacts'"
......
......@@ -25,13 +25,13 @@ Quick Form Query Extension
2017-2020
:Authors:
Carsten Rose, Benjamin Baer, Marc Egger
Carsten Rose, Benjamin Baer
:Further Contributors:
Rafael Ostertag, Elias Villiger, Nicola Chiapolini
:Email:
carsten.rose@math.uzh.ch, benjamin.baer@math.uzh.ch, marc.egger@uzh.ch
carsten.rose@math.uzh.ch, benjamin.baer@math.uzh.ch
:License:
This document is published under the Open Publication License
......
......@@ -56,8 +56,9 @@ class Path
private const APP_TO_FILEADMIN = 'fileadmin';
private const APP_TO_PROJECT_IN_PROTECTED = 'fileadmin/protected/qfqProject';
const PROJECT_TO_FORM = 'form';
const PROJECT_TO_CONF = 'conf';
const FORM_TO_FORM_BACKUP = '_backup';
const PROJECT_DIR_TO_REPORT = 'report';
const PROJECT_DIR_TO_REPORT = 'report'; // TODO: refactor: remove DIR from constant name
const REPORT_FILE_TO_BACKUP = '_backup'; // The path from a directory containing a report file to the directory containing backups of that report file
// Config
......@@ -202,6 +203,16 @@ class Path
return self::cwdToApp(self::appToProject($pathPartsToAppend));
}
/**
* @param array $pathPartsToAppend
* @return string
* @throws \UserFormException
*/
public static function cwdToConf(...$pathPartsToAppend): string
{
return self::cwdToProject(self::PROJECT_TO_CONF, $pathPartsToAppend);
}
/**
* @param array $pathPartsToAppend
* @return string
......
......@@ -78,10 +78,11 @@ class Config {
}
// read and parse config. Throw exception if not exists.
$cwdToConfigFile = $PhpUnitOverloadCwdToConfigFile === '' ? Path::cwdToProject(CONFIG_QFQ_JSON) : $PhpUnitOverloadCwdToConfigFile;
$cwdToConfigFile = $PhpUnitOverloadCwdToConfigFile === '' ? Path::cwdToConf(CONFIG_QFQ_JSON) : $PhpUnitOverloadCwdToConfigFile;
if (!file_exists($cwdToConfigFile)) {
HelperFile::file_put_contents(Path::cwdToProject(CONFIG_QFQ_JSON_EXAMPLE), json_encode(self::CONFIG_REQUIRED_TEMPLATE, JSON_PRETTY_PRINT));
Thrower::userFormException("Please create qfq config file '" . CONFIG_QFQ_JSON . "' in project directory. Example config file '" . CONFIG_QFQ_JSON_EXAMPLE . "' was created in project directory.", "Project directory: " . realpath(Path::cwdToProject()));
HelperFile::createPathRecursive(Path::cwdToConf());
HelperFile::file_put_contents(Path::cwdToConf(CONFIG_QFQ_JSON_EXAMPLE), json_encode(self::CONFIG_REQUIRED_TEMPLATE, JSON_PRETTY_PRINT));
Thrower::userFormException("Please create qfq config file '" . CONFIG_QFQ_JSON . "' in the conf directory which is inside the project directory. Example config file '" . CONFIG_QFQ_JSON_EXAMPLE . "' was created in conf directory.", "Project directory: " . realpath(Path::cwdToProject()));
}
$config = HelperFile::json_decode(HelperFile::file_get_contents($cwdToConfigFile));
......@@ -156,9 +157,9 @@ class Config {
*/
private static function writeConfig(array $config)
{
$cwdToProject = Path::cwdToProject();
HelperFile::createPathRecursive($cwdToProject);
HelperFile::file_put_contents(Path::join($cwdToProject, CONFIG_QFQ_JSON), json_encode($config, JSON_PRETTY_PRINT));
$cwdToConf = Path::cwdToConf();
HelperFile::createPathRecursive($cwdToConf);
HelperFile::file_put_contents(Path::join($cwdToConf, CONFIG_QFQ_JSON), json_encode($config, JSON_PRETTY_PRINT));
}
/**
......@@ -171,7 +172,11 @@ class Config {
{
// read old config.qfq.php
$cwdToOldConfigFile = Path::cwdToApp(Path::APP_TO_TYPO3_CONF, CONFIG_QFQ_PHP);
HelperFile::enforce_writable($cwdToOldConfigFile); // so we can delete it.
if (!is_writeable($cwdToOldConfigFile)) {
throw new \UserFormException(json_encode([
ERROR_MESSAGE_TO_USER => "Can't migrate to new config: Legacy config file `config.qfq.php` not writable.",
ERROR_MESSAGE_TO_DEVELOPER => "Can't write to file/directory '$cwdToOldConfigFile'"]));
}
$config = include($cwdToOldConfigFile);
// In case the database credentials are given in the old style: rename the keys
......
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