Commit 9d966f75 authored by Marc Egger's avatar Marc Egger
Browse files

Refs #10120 allow form name change

parent c2b35d31
Pipeline #3612 failed with stages
in 55 seconds
......@@ -41,6 +41,24 @@ use IMATHUZH\Qfq\Core\Helper\SqlQuery;
// 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: TESTING
// new form => form file created
// form field change => changed in form file
// form name change => old form file deleted, new form file created
// form delete => form file deleted
// form file not writeable => all the above abort before changes to DB are made
// form element create => added to form file
// form element changed => changed in form file
// form element deleted => removed from form file
// form file name changed => old form invalid, new form works
// form file parameter changed => changed in form editor
// 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
///////////////// JUST A TEST, DELETE ME! //////////////
// FormAsFile::exportForm($formName, $this->dbArray[$this->dbIndexQfq]);
// FormAsFile::importForm($formName, $this->dbArray[$this->dbIndexQfq]);
......
......@@ -424,20 +424,25 @@ class QuickFormQuery {
// Make sure form file is writable (before DB changes are made)
// Note: This can't be done earlier because $formModeNew might be changed in the lines above.
$recordFormName = FormAsFile::formNameFromFormRelatedRecord($recordId, $this->formSpec[F_TABLE_NAME], $this->dbArray[$this->dbIndexQfq]);
if (FORM_SAVE === $formModeNew && intval($recordId) === 0) {
$formFileNameDB = FormAsFile::formNameFromFormRelatedRecord($recordId, $this->formSpec[F_TABLE_NAME], $this->dbArray[$this->dbIndexQfq]);
switch ($this->formSpec[F_TABLE_NAME]) {
case TABLE_NAME_FORM: // New Form is being created
$recordFormName = $this->store->getVar(F_NAME, STORE_FORM);
case TABLE_NAME_FORM: // cases covered: new form, existing form, existing form but form name changed
$formFileName = $this->store->getVar(F_NAME, STORE_FORM, SANITIZE_ALLOW_ALNUMX);
$formFileName = $formFileName === false ? $formFileNameDB : $formFileName;
if ($formFileNameDB !== null && $formFileName !== $formFileNameDB && $formModeNew === FORM_SAVE) {
$formFileNameDelete = $formFileNameDB;
FormAsFile::enforceFormFileWritable($formFileNameDelete); // file will be deleted after DB changes
}
break;
case TABLE_NAME_FORM_ELEMENT: // New FormElement is being created
case TABLE_NAME_FORM_ELEMENT: // cases covered: new formElement, existing formElement
$formId = $this->store->getVar(FE_FORM_ID, STORE_FORM);
$recordFormName = FormAsFile::formNameFromFormRelatedRecord($formId, TABLE_NAME_FORM, $this->dbArray[$this->dbIndexQfq]);
$formFileName = $formId !== false ? FormAsFile::formNameFromFormRelatedRecord($formId, TABLE_NAME_FORM, $this->dbArray[$this->dbIndexQfq]) : $formFileNameDB;
break;
default:
$formFileName = $formFileNameDB;
}
}
if ($recordFormName !== null && in_array($formModeNew, [FORM_SAVE, FORM_DRAG_AND_DROP, FORM_DELETE])) {
FormAsFile::enforceFormFileWritable($recordFormName);
if ($formFileName !== null && in_array($formModeNew, [FORM_SAVE, FORM_DRAG_AND_DROP, FORM_DELETE])) {
FormAsFile::enforceFormFileWritable($formFileName);
}
// For 'new' record always create a new Browser TAB-uniq (for this current form, nowhere else used) SIP.
......@@ -639,22 +644,27 @@ class QuickFormQuery {
}
// export Form to file, if loaded record is a Form/FormElement
if ($recordFormName !== null) {
if ($formFileName !== null) {
switch ($formModeNew) {
case FORM_SAVE:
case FORM_DRAG_AND_DROP:
FormAsFile::exportForm($recordFormName, $this->dbArray[$this->dbIndexQfq]);
FormAsFile::exportForm($formFileName, $this->dbArray[$this->dbIndexQfq]);
break;
case FORM_DELETE:
if (TABLE_NAME_FORM_ELEMENT === $this->formSpec[F_TABLE_NAME]) {
FormAsFile::exportForm($recordFormName, $this->dbArray[$this->dbIndexQfq]);
FormAsFile::exportForm($formFileName, $this->dbArray[$this->dbIndexQfq]);
} else {
FormAsFile::deleteFormFile($recordFormName);
FormAsFile::deleteFormFile($formFileName);
}
break;
}
}
// delete old form file if form name was changed
if (isset($formFileNameDelete)) {
FormAsFile::deleteFormFile($formFileNameDelete);
}
return $data;
}
......
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