Commit cf68a1ea authored by Marc Egger's avatar Marc Egger

Refs #10120 add form path to the QFQ extension settings and move constants to constants.php

parent e6a7f746
Pipeline #3647 failed with stages
in 7 minutes and 41 seconds
......@@ -657,6 +657,9 @@ const SYSTEM_THUMBNAIL_DIR_SECURE_DEFAULT = 'fileadmin/protected/qfqThumbnail';
const SYSTEM_THUMBNAIL_DIR_PUBLIC = 'thumbnailDirPublic';
const SYSTEM_THUMBNAIL_DIR_PUBLIC_DEFAULT = 'typo3temp/qfqThumbnail';
// Form/Report as file
const SYSTEM_QFQ_PROJECT_DIR_SECURE = 'qfqProjectDir'; // where form and report files are saved
const SYSTEM_DOCUMENTATION_QFQ = 'documentation';
const SYSTEM_DOCUMENTATION_QFQ_URL = 'https://docs.qfq.io';
......@@ -1074,6 +1077,9 @@ const F_REST_TOKEN = 'restToken';
const CLIENT_REST_ID = '_id';
const CLIENT_REST_FORM = '_form';
// Form Columns: Only in form file
const F_FILE_FORM_ELEMENT = 'FormElement_ff'; // Key for FormElements array saved in Form File
// FORM_ELEMENT_STATI
const FE_MODE_SHOW = 'show';
const FE_MODE_READONLY = 'readonly';
......@@ -1150,6 +1156,9 @@ const FE_TRIM_NONE = 'none';
const FE_FILE_TRASH = 'fileTrash';
const FE_FILE_TRASH_TEXT = 'fileTrashText';
// FormElement Columns: Only in form file
const FE_FILE_CONTAINER_NAME = 'containerName_ff'; // key for referencing container FormElements by name in form file
// Excel Import
const FE_IMPORT_TO_TABLE = 'importToTable';
const FE_IMPORT_TO_COLUMNS = 'importToColumns';
......
......@@ -7,6 +7,7 @@ use IMATHUZH\Qfq\Core\Database\Database;
use IMATHUZH\Qfq\Core\Helper\HelperFile;
use IMATHUZH\Qfq\Core\Helper\OnString;
use IMATHUZH\Qfq\Core\Helper\SqlQuery;
use IMATHUZH\Qfq\Core\Store\Store;
// TODO: Fix all broken tests... one easy solution?
// TODO: Carsten Fragen: Habe keine Unittests zu QuickFormQuery->doForm gefunden. Wird nicht getestet. FormAsFile nicht testen oder vielleicht nur mit selenium?
......@@ -19,15 +20,11 @@ use IMATHUZH\Qfq\Core\Helper\SqlQuery;
// TODO: Carsten Fragen: Kann es sein, dass records in Dirty tabelle nicht mehr richtig abegraeumt werden, weil forms die ID wechseln?
// TODO: Carsten Fragen: Exceptions werden teilweise ohne Developer message angezeigt (API). Deshalb habe ich die Message teilweise in User message getan.
// TODO: Carsten Fragen: PHP version von gitlab runner hochstellen, damit ?string und void type syntax fuer funktionen erlaubt ist? verhindert einige fehler
// TODO: Carsten Fragen: Regex fuer erlaubte file names und form names im editor (+ erlauben?): ^([-\.\w]+)$ VS [a-zA-Z0-9._+-]+
// TODO: Carsten Fragen: Muss die neue Column fileStats von Form tabelle in DatabaseUpdateData.php? Form Editor wird ja sowieso neu eingespielt bei einem update.
// TODO: Carsten Fragen: QFQ as file
// TODO: BEFOORE PRUDUCTION
// TODO: add Exception hint as hint instead of in main message?
// TODO: move formFile code in QuickFormQuery.php into methods in this file as much as possible?
// TODO: remove DEBUG blocks
// TODO: Form-Editor form name einschraenken auf eindeutige und valide file names
// TODO: Form-Editor anpassen: container name muessen eindeutig sein.
// TODO: add fileStats column to Form schema and to DatabaseUpdateData.php. Actually formEditor.sql is run in DatabaseUpdate.php after the DatabaseUpdateData.php changes are executed. So is this neccessary? (ASK Carsten)
// TODO: move Constants to Constants.php if this file is actually used
// TODO: extract all sql queries and make them reusable
// TODO: write tests (file test https://medium.com/weebly-engineering/phpunit-mocking-the-file-system-using-vfsstream-5d7d79b1eb2a)
// TODO: maybe: update button in form list which removes forms from DB if their file was deleted
......@@ -50,7 +47,6 @@ use IMATHUZH\Qfq\Core\Helper\SqlQuery;
// form file form element added => added in form editor
// form file form element changed => changed in form editor
// form file form element removed => removed in form editor
// form file changed => request for dirty lock throws exception
// form folder does not exist but formEditor is opened => form folder is created, all forms exported
......@@ -93,10 +89,6 @@ use IMATHUZH\Qfq\Core\Helper\SqlQuery;
// ]));
///////////////////////
const SYSTEM_FORM_FILE_PATH = 'fileadmin/protected/qfq/form'; // where form specification files are saved and loaded
const FORM_FILE_FORM_ELEMENT = 'FormElement_ff'; // Key for FormElements array saved in Form File
const FORM_FILE_CONTAINER_NAME = 'containerName_ff'; // key for referencing container FormElements by name in form file
class FormAsFile
{
/**
......@@ -171,7 +163,7 @@ class FormAsFile
// Insert FormElements to DB and collect container ids
$containerIds = []; // array(container_name => id)
foreach ($formFromFile[FORM_FILE_FORM_ELEMENT] as &$formElementFromFile) {
foreach ($formFromFile[F_FILE_FORM_ELEMENT] as &$formElementFromFile) {
$feId = self::insertFormElement($formElementFromFile, $formId, $database);
$formElementFromFile[FE_ID] = $feId;
if ($formElementFromFile[FE_CLASS] === FE_CLASS_CONTAINER) {
......@@ -180,9 +172,9 @@ class FormAsFile
}
// Update container IDs for each form element which has a container name
foreach ($formFromFile[FORM_FILE_FORM_ELEMENT] as &$formElementFromFile) {
if (array_key_exists(FORM_FILE_CONTAINER_NAME, $formElementFromFile)) {
$containerName = $formElementFromFile[FORM_FILE_CONTAINER_NAME];
foreach ($formFromFile[F_FILE_FORM_ELEMENT] as &$formElementFromFile) {
if (array_key_exists(FE_FILE_CONTAINER_NAME, $formElementFromFile)) {
$containerName = $formElementFromFile[FE_FILE_CONTAINER_NAME];
$containerId = $containerIds[$containerName];
$feId = $formElementFromFile[FE_ID];
list($sql, $parameterArray) = SqlQuery::updateRecord(TABLE_NAME_FORM_ELEMENT, [FE_ID_CONTAINER => $containerId], $feId);
......@@ -252,7 +244,7 @@ class FormAsFile
$formElements = array_map(function ($formElement) use ($containerNames) {
$containerId = $formElement[FE_ID_CONTAINER];
if ($containerId !== 0) {
$formElement[FORM_FILE_CONTAINER_NAME] = $containerNames[$containerId];
$formElement[FE_FILE_CONTAINER_NAME] = $containerNames[$containerId];
}
unset($formElement[FE_ID_CONTAINER]);
unset($formElement[FE_ID]);
......@@ -261,7 +253,7 @@ class FormAsFile
}, $formElements);
// write form as JSON to file
$form[FORM_FILE_FORM_ELEMENT] = $formElements;
$form[F_FILE_FORM_ELEMENT] = $formElements;
$formJson = json_encode($form, JSON_PRETTY_PRINT);
$pathFileName = self::formPathFileName($formName, $database);
$success = file_put_contents($pathFileName, $formJson);
......@@ -632,10 +624,12 @@ class FormAsFile
* @throws \CodeException
* @throws \DbException
* @throws \UserFormException
* @throws \UserReportException
*/
private static function formPath(Database $database): string
{
$formPath = HelperFile::correctRelativePathFileName(SYSTEM_FORM_FILE_PATH);
$systemQfqProjectDir = Store::getInstance()->getVar(SYSTEM_QFQ_PROJECT_DIR_SECURE, STORE_SYSTEM);
$formPath = HelperFile::correctRelativePathFileName(HelperFile::joinPathFilename($systemQfqProjectDir, 'form'));
if (!is_dir($formPath)) {
// create path
......
......@@ -422,7 +422,7 @@ class QuickFormQuery {
}
}
// Make sure form file is writable (before DB changes are made)
// FormAsFile: Get the new and the old form file name and make sure both files are writable (before DB changes are made)
// Note: This can't be done earlier because $formModeNew might be changed in the lines above.
$formNameDB = FormAsFile::formNameFromFormRelatedRecord($recordId, $this->formSpec[F_TABLE_NAME], $this->dbArray[$this->dbIndexQfq]);
switch ($this->formSpec[F_TABLE_NAME]) {
......
......@@ -13,6 +13,9 @@ baseUrl =
# cat=config/date; type=string; label=Date format:Default is 'dd.mm.yyyy'. Possible options: 'yyyy-mm-dd', 'dd.mm.yyyy'
dateFormat = dd.mm.yyyy
# cat=config/config; type=string; label=QFQ project directory:Default is 'fileadmin/protected/qfqProject'. Important: secure the directory (recursive) against direct access. Forms and reports are saved in this directory.
qfqProjectDir = fileadmin/protected/qfqProject
# cat=config/config; type=string; label=Thumbnail directory 'secure':Default is 'fileadmin/protected/qfqThumbnail'. Important: secure the directory (recursive) against direct access. Will be used by a special columnname '_thumbnail'.
thumbnailDirSecure = fileadmin/protected/qfqThumbnail
......
Markdown is supported
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