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

Refs #10120 all basic functionality implemented. Needs testing.

parent 6674f4ae
Pipeline #3601 failed with stages
in 1 minute and 24 seconds
...@@ -6,30 +6,19 @@ use IMATHUZH\Qfq\Core\Database\Database; ...@@ -6,30 +6,19 @@ use IMATHUZH\Qfq\Core\Database\Database;
use IMATHUZH\Qfq\Core\Helper\HelperFile; use IMATHUZH\Qfq\Core\Helper\HelperFile;
use IMATHUZH\Qfq\Core\Helper\SqlQuery; use IMATHUZH\Qfq\Core\Helper\SqlQuery;
// TODO: test saving of FormElement <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // TODO: test deleteing of Form and FormElement <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// TODO: implement FORM_DELETE in QuickFormQuery.php // TODO: ensure that form file is imported if Form is loaded via Rest API
// TODO: Form speichern. siehe zettlr note.
// FORM_DELETE: export Form/FormElement
// FORM_REST:
// FORM_LOAD:
// FORM_SAVE: export Form/FormElement
// FORM_UPDATE: (export Form/FormElement) NO, ask carsten
// FORM_DRAG_AND_DROP: export Form/FormElement
// TODO: gibt es UPDATE/INSERT/DELETE statements die an Form/FormElement arbeiten koennen, die nicht nur durch doForm aufgerufen werden? // TODO: gibt es UPDATE/INSERT/DELETE statements die an Form/FormElement arbeiten koennen, die nicht nur durch doForm aufgerufen werden?
// TODO: Dies sollte schon erfuellt sein, testen: bevor ein form/formelement im form editor gespeichert wird, soll es vom file geladen werden (Save.php). Falls das file importiert wurde, gibt es eine fehlermeldung. // TODO: Testen: Dies sollte schon erfuellt sein, testen: bevor ein form/formelement im form editor gespeichert wird, soll es vom file geladen werden (Save.php). Falls das file importiert wurde, gibt es eine fehlermeldung.
// TODO: anfrage nach dirty, form file ueberpruefen (importieren) // TODO: Testen: anfrage nach dirty, form file ueberpruefen (importieren)
// TODO: Testen: Dirty tabelle ist aussergewoehnlich voll. werden die records nicht abgeraeumt wegen formAsFile? // TODO: Testen: Dirty tabelle ist aussergewoehnlich voll. werden die records nicht abgeraeumt wegen formAsFile?
// TODO: ausporbieren was passiert wenn ich in Form-Editor auf speicher druecke nachdem ich in einem anderen tab das geanderte form file in die DB lade. // TODO: Testen: ausporbieren was passiert wenn ich in Form-Editor auf speicher druecke nachdem ich in einem anderen tab das geanderte form file in die DB lade.
// TODO: form list Report: when form list report is loaded, load new form files into DB and delete removed forms from DB // TODO: form list Report: when form list report is loaded, load new form files into DB and delete removed forms from DB
// TODO: Carsten Fragen: Form backups erstellen vor dem delete? // TODO: Carsten Fragen: Form backups erstellen vor deleteFormFile und exportForm?
// TODO: Maybe: solve reference by ID after file change Problem (might not be a big deal since it only happens on git pull) // TODO: Carsten Fragen: "git rm" anstatt "rm" benutzen falls ordner ein git repo? Einziger unterschied: macht "git add"
// Problem: FormEditor and form list might reference a form by an old id. In that case everything has to be reloaded. That's annoying.
// Variant 1: reference form by name in edit and delete button, not by id (only solver part of the problem)
// Variant 2: track old form ids and relay to new form automatically. Track old form ids in new Form column "oldIds"
// TODO: DONT DO: add column import-modification-date to Form and FormElement and set them to the same as modification date in both exportForm and importForm. compare the two modification dates in the beginning. If the actual modification is after importModification and fileStats are the same in file and in form, then exportForm.
// TODO: DONT DO: what to do if importModificationDate and fileStats have changed? > 1) export Form to new form file named <formName>mergeConflict_timestamp 2) importForm form file, overwrite DB
// TODO: BEFOORE PRUDUCTION // 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: move formFile code in QuickFormQuery.php into methods in this file as much as possible?
// TODO: remove DEBUG blocks // TODO: remove DEBUG blocks
// TODO: Form-Editor form name einschraenken auf eindeutige und valide file names // TODO: Form-Editor form name einschraenken auf eindeutige und valide file names
...@@ -41,6 +30,16 @@ use IMATHUZH\Qfq\Core\Helper\SqlQuery; ...@@ -41,6 +30,16 @@ use IMATHUZH\Qfq\Core\Helper\SqlQuery;
// TODO: maybe: update button in form list which removes forms from DB if their file was deleted // TODO: maybe: update button in form list which removes forms from DB if their file was deleted
// TODO: Carsten Fragen: add log messages somewhare? // TODO: Carsten Fragen: add log messages somewhare?
// TODO: MAYBE
// TODO: Maybe: solve reference by ID after file change Problem (might not be a big deal since it only happens on git pull)
// Problem: FormEditor and form list might reference a form by an old id. In that case everything has to be reloaded. That's annoying.
// Variant 1: reference form by name in edit and delete button, not by id (only solver part of the problem)
// Variant 2: track old form ids and relay to new form automatically. Track old form ids in new Form column "oldIds"
// TODO: DON'T DO
// TODO: DONT DO: add column import-modification-date to Form and FormElement and set them to the same as modification date in both exportForm and importForm. compare the two modification dates in the beginning. If the actual modification is after importModification and fileStats are the same in file and in form, then exportForm.
// TODO: DONT DO: what to do if importModificationDate and fileStats have changed? > 1) export Form to new form file named <formName>mergeConflict_timestamp 2) importForm form file, overwrite DB
///////////////// JUST A TEST, DELETE ME! ////////////// ///////////////// JUST A TEST, DELETE ME! //////////////
// FormAsFile::exportForm($formName, $this->dbArray[$this->dbIndexQfq]); // FormAsFile::exportForm($formName, $this->dbArray[$this->dbIndexQfq]);
// FormAsFile::importForm($formName, $this->dbArray[$this->dbIndexQfq]); // FormAsFile::importForm($formName, $this->dbArray[$this->dbIndexQfq]);
...@@ -59,64 +58,6 @@ const FORM_FILE_CONTAINER_NAME = 'containerName_ff'; // key for referencing cont ...@@ -59,64 +58,6 @@ const FORM_FILE_CONTAINER_NAME = 'containerName_ff'; // key for referencing cont
class FormAsFile class FormAsFile
{ {
/**
* Multiple errors might occur after a form file import. This hint can be added to such exceptions to help users.
* Only returns non-empty string if the table is either Form of FormElement.
*
* @param string $tableName
* @return string
*/
public static function errorHintFormImport (string $tableName = 'Form'): string
{
$message = '';
if (in_array($tableName, [TABLE_NAME_FORM, TABLE_NAME_FORM_ELEMENT])) {
$message .= "Hint: Form definition file might have changed. Please reopen the form list and Form-Editor from scratch.";
}
return $message;
}
/**
* Wrapper to call self::importForm(...) with an ID instead of a form name.
*
* @param int $formId
* @param Database $database
* @return bool True if form has been updated.
* @throws \CodeException
* @throws \DbException
* @throws \UserFormException
*/
public static function importFormWithId(int $formId, Database $database): bool
{
if ($formId === 0) {
return false;
}
$formName = self::queryFormNameWithId($formId, $database);
return self::importForm($formName, $database);
}
/**
* Wrapper to call self::importForm(...) with a formElement ID instead of a form name.
*
* @param int $formElementId
* @param Database $database
* @return bool True if form has been updated.
* @throws \CodeException
* @throws \DbException
* @throws \UserFormException
*/
public static function importFormElementWithId(int $formElementId, Database $database): bool
{
if ($formElementId === 0) {
return false;
}
// get form name
$formName = self::queryFormNameWithFormElementId($formElementId, $database);
// import form
return self::importForm($formName, $database);
}
/** /**
* Remove the form from the DB and insert it using the form file. (only if the form file was changed) * Remove the form from the DB and insert it using the form file. (only if the form file was changed)
* If the form file can't be read, then the form is deleted from the DB and an exception is thrown. * If the form file can't be read, then the form is deleted from the DB and an exception is thrown.
...@@ -136,10 +77,9 @@ class FormAsFile ...@@ -136,10 +77,9 @@ class FormAsFile
public static function importForm(string $formName, Database $database): bool public static function importForm(string $formName, Database $database): bool
{ {
// Get file stats both from file system and DB and exit if they are equal // Get file stats both from file system and DB and exit if they are equal
self::enforceFormNameValid($formName);
$pathFileName = self::formPathFileName($formName); $pathFileName = self::formPathFileName($formName);
$fileReadException = new \UserFormException(json_encode([ $fileReadException = new \UserFormException(json_encode([
ERROR_MESSAGE_TO_USER => "Form file not found or missing permission: {$formName}.json", ERROR_MESSAGE_TO_USER => "Form file not found or missing permission: " . baseName($pathFileName),
ERROR_MESSAGE_TO_DEVELOPER => "Form definition file not found or no permission to read file: '$pathFileName'"]), ERROR_MESSAGE_TO_DEVELOPER => "Form definition file not found or no permission to read file: '$pathFileName'"]),
ERROR_FORM_NOT_FOUND); ERROR_FORM_NOT_FOUND);
if(!file_exists($pathFileName)) { if(!file_exists($pathFileName)) {
...@@ -209,45 +149,10 @@ class FormAsFile ...@@ -209,45 +149,10 @@ class FormAsFile
return true; return true;
} }
/**
* Wrapper to call self::exportForm(...) with an ID instead of a form name.
*
* @param int $formId
* @param Database $database
* @throws \CodeException
* @throws \DbException
* @throws \UserFormException
*/
public static function exportFormWithId(int $formId, Database $database): void
{
if ($formId === 0) {
return;
}
$formName = self::queryFormNameWithId($formId, $database);
self::exportForm($formName, $database);
}
/**
* Wrapper to call self::exportForm(...) with a formElement ID instead of a form name.
*
* @param int $formElementId
* @param Database $database
* @throws \CodeException
* @throws \DbException
* @throws \UserFormException
*/
public static function exportFormElementWithId(int $formElementId, Database $database): void
{
if ($formElementId === 0) {
return;
}
$formName = self::queryFormNameWithFormElementId($formElementId, $database);
self::exportForm($formName, $database);
}
/** /**
* Reads the form from the DB and saves it in the form folder as a form file. * Reads the form from the DB and saves it in the form folder as a form file.
* If the form file path does not exist, it is created. * If the form file path does not exist, it is created.
* Updates column fileStats with new stats from new file.
* *
* Container FormElements: The form file uses names instead if ids to reference containers. These references are translated before saving the file. * Container FormElements: The form file uses names instead if ids to reference containers. These references are translated before saving the file.
* Ignored columns: The columns 'id', 'name' (only Form table), 'fileStats', 'formId', 'feIdContainer' are not saved in the file. * Ignored columns: The columns 'id', 'name' (only Form table), 'fileStats', 'formId', 'feIdContainer' are not saved in the file.
...@@ -261,8 +166,6 @@ class FormAsFile ...@@ -261,8 +166,6 @@ class FormAsFile
*/ */
public static function exportForm(string $formName, Database $database): void public static function exportForm(string $formName, Database $database): void
{ {
self::enforceFormNameValid($formName);
// Get form from DB // Get form from DB
$FORM = TABLE_NAME_FORM; // can't use constants in strings directly $FORM = TABLE_NAME_FORM; // can't use constants in strings directly
$NAME = F_NAME; // can't use constants in strings directly $NAME = F_NAME; // can't use constants in strings directly
...@@ -315,7 +218,7 @@ class FormAsFile ...@@ -315,7 +218,7 @@ class FormAsFile
$success = file_put_contents($pathFileName, $formJson); $success = file_put_contents($pathFileName, $formJson);
if ($success === false) { if ($success === false) {
throw new \UserFormException(json_encode([ throw new \UserFormException(json_encode([
ERROR_MESSAGE_TO_USER => "writing form file '{$formName}.json' failed", ERROR_MESSAGE_TO_USER => "Writing form file failed: " . baseName($pathFileName),
ERROR_MESSAGE_TO_DEVELOPER => "Can't write to file '$pathFileName'"]), ERROR_MESSAGE_TO_DEVELOPER => "Can't write to file '$pathFileName'"]),
ERROR_IO_WRITE_FILE); ERROR_IO_WRITE_FILE);
} }
...@@ -327,40 +230,101 @@ class FormAsFile ...@@ -327,40 +230,101 @@ class FormAsFile
} }
/** /**
* Throw exception if Form file is not writeable. * Deletes the form file for the given form.
* *
* @param int $formId * @param $formName
* @param Database $database
* @return void
* @throws \CodeException
* @throws \DbException
* @throws \UserFormException * @throws \UserFormException
*/ */
public static function enforceFormFileWritable(int $formId, Database $database): void public static function deleteFormFile($formName): void
{ {
$formName = self::queryFormNameWithId($formId, $database); self::enforceFormFileWritable($formName);
$pathFileName = self::formPathFileName($formName); $pathFileName = self::formPathFileName($formName);
if (!is_writable($pathFileName)) { if(file_exists($pathFileName)) {
throw new \UserFormException(json_encode([ unlink($pathFileName);
ERROR_MESSAGE_TO_USER => "Can't write to form file '{$formName}.json'. Check permissions.",
ERROR_MESSAGE_TO_DEVELOPER => "Can't write to file '$pathFileName'."]),
ERROR_IO_WRITE_FILE);
} }
} }
/** /**
* Throws an exception if form name is not a valid file name. * Multiple errors might occur after a form file import. This hint can be added to such exceptions to help users.
* Only returns non-empty string if the table is either Form of FormElement.
*
* @param string $tableName
* @return string
*/
public static function errorHintFormImport (string $tableName = 'Form'): string
{
$message = '';
if (in_array($tableName, [TABLE_NAME_FORM, TABLE_NAME_FORM_ELEMENT])) {
$message .= "Hint: Form definition file might have changed. Please reopen the form list and Form-Editor from scratch.";
}
return $message;
}
/**
* Throw exception if form file or form directory is not writeable.
* *
* @param string $formName * @param string $formName
* @return void
* @throws \UserFormException * @throws \UserFormException
*/ */
private static function enforceFormNameValid(string $formName): void public static function enforceFormFileWritable(string $formName): void
{ {
if (!HelperFile::isValidFileName($formName)) { $pathFileName = self::formPathFileName($formName);
throw new \UserFormException(json_encode([ if (file_exists($pathFileName)) {
ERROR_MESSAGE_TO_USER => 'Invalid form name.', if (!is_writable($pathFileName)) {
ERROR_MESSAGE_TO_DEVELOPER => "Form name not valid '$formName': Name may only consist of alphanumeric characters and _ . -"]), throw new \UserFormException(json_encode([
ERROR_FORM_INVALID_NAME); ERROR_MESSAGE_TO_USER => "Can't write to file: " . baseName($pathFileName),
ERROR_MESSAGE_TO_DEVELOPER => "Can't write to file '$pathFileName'. Check permissions."]),
ERROR_IO_WRITE_FILE);
}
} else {
if (!is_writable(dirname($pathFileName))) {
throw new \UserFormException(json_encode([
ERROR_MESSAGE_TO_USER => "Can't write to form directory. Check permissions.",
ERROR_MESSAGE_TO_DEVELOPER => "Can't write to directory: " . dirname($pathFileName)]),
ERROR_IO_WRITE_FILE);
}
}
}
/**
* Return form name if given record is an existing Form or FormElement.
* Return false otherwise.
*
* @param int $recordId
* @param string $recordTable
* @param Database $database
* @return string formName|false
* @throws \CodeException
* @throws \DbException
* @throws \UserFormException
*/
public static function isFormOrFormElement(int $recordId, string $recordTable, Database $database): string
{
if ($recordId === 0) {
return false;
}
switch ($recordTable) {
case TABLE_NAME_FORM:
$F_NAME = F_NAME;
$TABLE_NAME_FORM = TABLE_NAME_FORM;
$F_ID = F_ID;
$formFromDb = $database->sql("SELECT `$F_NAME` FROM `$TABLE_NAME_FORM` AS f WHERE `f`.`$F_ID`=? AND `f`.`deleted`='no'", ROW_EXPECT_1,
[$recordId], "Form with id '$recordId' not found. " . self::errorHintFormImport());
return $formFromDb[F_NAME];
case TABLE_NAME_FORM_ELEMENT:
$F_NAME = F_NAME;
$TABLE_NAME_FORM_ELEMENT = TABLE_NAME_FORM_ELEMENT;
$TABLE_NAME_FORM = TABLE_NAME_FORM;
$F_ID = F_ID;
$FE_FORM_ID = FE_FORM_ID;
$FE_ID = FE_ID;
$formFromDb = $database->sql("SELECT `f`.`$F_NAME` FROM `$TABLE_NAME_FORM` AS f INNER JOIN `$TABLE_NAME_FORM_ELEMENT` AS fe ON f.`$F_ID`=fe.`$FE_FORM_ID` WHERE `fe`.`$FE_ID`=?", ROW_EXPECT_1,
[$recordId], "Form element with id '$recordId' not found. " . self::errorHintFormImport());
return $formFromDb[F_NAME];
default:
return false;
} }
} }
...@@ -434,45 +398,6 @@ class FormAsFile ...@@ -434,45 +398,6 @@ class FormAsFile
$database->sql("DELETE FROM `$TABLE_NAME_FORM_ELEMENT` WHERE `$FE_FORM_ID`=?", ROW_REGULAR, [$formId]); $database->sql("DELETE FROM `$TABLE_NAME_FORM_ELEMENT` WHERE `$FE_FORM_ID`=?", ROW_REGULAR, [$formId]);
} }
/**
* @param int $formId
* @param Database $database
* @return string
* @throws \CodeException
* @throws \DbException
* @throws \UserFormException
*/
private static function queryFormNameWithId(int $formId, Database $database): string
{
$F_NAME = F_NAME;
$TABLE_NAME_FORM = TABLE_NAME_FORM;
$F_ID = F_ID;
$formFromDb = $database->sql("SELECT `$F_NAME` FROM `$TABLE_NAME_FORM` AS f WHERE `f`.`$F_ID`=? AND `f`.`deleted`='no'", ROW_EXPECT_1,
[$formId], "Form with id '$formId' not found. " . self::errorHintFormImport());
return $formFromDb[F_NAME];
}
/**
* @param int $formElementId
* @param Database $database
* @return string
* @throws \CodeException
* @throws \DbException
* @throws \UserFormException
*/
private static function queryFormNameWithFormElementId(int $formElementId, Database $database): string
{
$F_NAME = F_NAME;
$TABLE_NAME_FORM_ELEMENT = TABLE_NAME_FORM_ELEMENT;
$TABLE_NAME_FORM = TABLE_NAME_FORM;
$F_ID = F_ID;
$FE_FORM_ID = FE_FORM_ID;
$FE_ID = FE_ID;
$formFromDb = $database->sql("SELECT `f`.`$F_NAME` FROM `$TABLE_NAME_FORM` AS f INNER JOIN `$TABLE_NAME_FORM_ELEMENT` AS fe ON f.`$F_ID`=fe.`$FE_FORM_ID` WHERE `fe`.`$FE_ID`=?", ROW_EXPECT_1,
[$formElementId], "Form element with id '$formElementId' not found. " . self::errorHintFormImport());
return $formFromDb[F_NAME];
}
/** /**
* @param string $pathFileName * @param string $pathFileName
* @return false|string * @return false|string
...@@ -500,6 +425,15 @@ class FormAsFile ...@@ -500,6 +425,15 @@ class FormAsFile
*/ */
private static function formPathFileName(string $formName): string private static function formPathFileName(string $formName): string
{ {
// validate form name
if (!HelperFile::isValidFileName($formName)) {
throw new \UserFormException(json_encode([
ERROR_MESSAGE_TO_USER => 'Invalid form name.',
ERROR_MESSAGE_TO_DEVELOPER => "Reading/Writing Form file failed: Form name '$formName' not valid. Name may only consist of alphanumeric characters and _ . -"]),
ERROR_FORM_INVALID_NAME);
}
// create form folder path
if (!is_dir(SYSTEM_FORM_FILE_PATH)) { if (!is_dir(SYSTEM_FORM_FILE_PATH)) {
$success = mkdir(SYSTEM_FORM_FILE_PATH, 0777, true); $success = mkdir(SYSTEM_FORM_FILE_PATH, 0777, true);
if ($success === false) { if ($success === false) {
...@@ -509,6 +443,7 @@ class FormAsFile ...@@ -509,6 +443,7 @@ class FormAsFile
ERROR_IO_WRITE_FILE); ERROR_IO_WRITE_FILE);
} }
} }
return HelperFile::correctRelativePathFileName(SYSTEM_FORM_FILE_PATH . '/' . $formName . ".json"); return HelperFile::correctRelativePathFileName(SYSTEM_FORM_FILE_PATH . '/' . $formName . ".json");
} }
} }
\ No newline at end of file
...@@ -423,9 +423,10 @@ class QuickFormQuery { ...@@ -423,9 +423,10 @@ class QuickFormQuery {
} }
// Make sure form file is writable (before DB changes are made) // Make sure form file is writable (before DB changes are made)
if (in_array($this->formSpec[F_TABLE_NAME], [TABLE_NAME_FORM, TABLE_NAME_FORM_ELEMENT]) // Note: This can't be done earlier because $formModeNew might be changed in the lines above.
&& in_array($formModeNew, [FORM_SAVE, FORM_DRAG_AND_DROP, FORM_DELETE])) { $recordFormName = FormAsFile::isFormOrFormElement($recordId, $this->formSpec[F_TABLE_NAME], $this->dbArray[$this->dbIndexQfq]);
FormAsFile::enforceFormFileWritable($recordId, $this->dbArray[$this->dbIndexQfq]); if ($recordFormName !== false && in_array($formModeNew, [FORM_SAVE, FORM_DRAG_AND_DROP, FORM_DELETE])) {
FormAsFile::enforceFormFileWritable($recordFormName);
} }
// For 'new' record always create a new Browser TAB-uniq (for this current form, nowhere else used) SIP. // For 'new' record always create a new Browser TAB-uniq (for this current form, nowhere else used) SIP.
...@@ -627,23 +628,19 @@ class QuickFormQuery { ...@@ -627,23 +628,19 @@ class QuickFormQuery {
} }
// export Form to file, if loaded record is a Form/FormElement // export Form to file, if loaded record is a Form/FormElement
switch ($formModeNew) { if ($recordFormName !== false) {
case FORM_SAVE: switch ($formModeNew) {
case FORM_DRAG_AND_DROP: case FORM_SAVE:
if (TABLE_NAME_FORM === $this->formSpec[F_TABLE_NAME]) { case FORM_DRAG_AND_DROP:
FormAsFile::exportFormWithId($recordId, $this->dbArray[$this->dbIndexQfq]); FormAsFile::exportForm($recordFormName, $this->dbArray[$this->dbIndexQfq]);
} elseif (TABLE_NAME_FORM_ELEMENT === $this->formSpec[F_TABLE_NAME]) { break;
FormAsFile::exportFormElementWithId($recordId, $this->dbArray[$this->dbIndexQfq]); case FORM_DELETE:
} if (TABLE_NAME_FORM_ELEMENT === $this->formSpec[F_TABLE_NAME]) {
break; FormAsFile::exportForm($recordFormName, $this->dbArray[$this->dbIndexQfq]);
case FORM_DELETE: } else {
if (TABLE_NAME_FORM === $this->formSpec[F_TABLE_NAME]) { FormAsFile::deleteFormFile($recordFormName);
// TODO: delete form file }
} elseif (TABLE_NAME_FORM_ELEMENT === $this->formSpec[F_TABLE_NAME]) { }
// TODO: find out the formId of the FormElement. should be in store. Or save it in a variable earlier.
// TODO: export Form
}
} }
return $data; return $data;
...@@ -1033,17 +1030,14 @@ class QuickFormQuery { ...@@ -1033,17 +1030,14 @@ class QuickFormQuery {
[$formName], 'Form "' . $formName . '" not found or multiple forms with the same name.'); [$formName], 'Form "' . $formName . '" not found or multiple forms with the same name.');
// Import Form from file if loaded record is Form/FormElement (If form file was changed, throw exception) // Import Form from file if loaded record is Form/FormElement (If form file was changed, throw exception)
$throwException = false; $recordFormName = FormAsFile::isFormOrFormElement($recordId, $form[F_TABLE_NAME], $this->dbArray[$this->dbIndexQfq]);
if ($form[F_TABLE_NAME] === TABLE_NAME_FORM) { if ($recordFormName !== false) {
$throwException = FormAsFile::importFormWithId($recordId, $this->dbArray[$this->dbIndexQfq]); if(FormAsFile::importForm($recordFormName, $this->dbArray[$this->dbIndexQfq])) {
} elseif ($form[F_TABLE_NAME] === TABLE_NAME_FORM_ELEMENT) { throw new \UserFormException(json_encode([
$throwException = FormAsFile::importFormElementWithId($recordId, $this->dbArray[$this->dbIndexQfq]); ERROR_MESSAGE_TO_USER => 'Form file was changed.',
} ERROR_MESSAGE_TO_DEVELOPER => "Form definition file has been changed. Please close tab and reload the form list and Form-Editor from scratch."]),
if($throwException) { ERROR_FORM_NOT_FOUND);
throw new \UserFormException(json_encode([ }
ERROR_MESSAGE_TO_USER => 'Form file was changed.',
ERROR_MESSAGE_TO_DEVELOPER => "Form definition file has been changed. Please close tab and reload the form list and Form-Editor from scratch."]),
ERROR_FORM_NOT_FOUND);
} }
$form = $this->checkFormLogMode($form); $form = $this->checkFormLogMode($form);
......
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