// 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
// 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: Make unittest for isFormQuery(). Example string:
//$sql = <<<END
//SELECT CONCAT('p:{{pageId:T}}&form=form&r=', f.id) as _pagee, f.id, f.name, f.title, f.tableName, CONCAT('form=form&r=', f.id) as _Paged FROM where
//FormFormElement,Form AS f ORDER BY f.name
//
//SELECT CONCAT('p:{{pageId:T}}&form=form&r=', f.id) as _pagee, f.id, f.name, f.title, f.tableName, CONCAT('form=form&r=', f.id) as _Paged From Order by Form AS f ORDER BY f.name
//
//SELECT CONCAT('p:{{pageId:T}}&form=form&r=', f.id) as _pagee, f.id, f.name, f.title, f.tableName, CONCAT('form=form&r=', f.id) as _Paged FRom having Form AS f ORDER BY f.name
//
//SELECT CONCAT('p:{{pageId:T}}&form=form&r=', f.id) as _pagee, f.id, f.name, f.title, f.tableName, CONCAT('form=form&r=', f.id) as _Paged from Form AS f ORDER BY f.name
//END;
// 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
// 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! //////////////
$F_ID=F_ID;// can't use constants in strings directly
...
...
@@ -124,7 +134,7 @@ class FormAsFile
// Read form file
$fileContents=file_get_contents($pathFileName);
if($fileContents===false){
self::deleteForm($formName,$database);
self::deleteFormDB($formName,$database);
throw$fileReadException;
}
$formFromFile=json_decode($fileContents,true);
...
...
@@ -132,7 +142,7 @@ class FormAsFile
// Delete old form from DB if it exists
if(array_key_exists(F_ID,$formFromDb)){
$formId=$formFromDb[$F_ID];
self::deleteFormWithId($formId,$database);
self::deleteFormDBWithId($formId,$database);
}
// Insert new Form to DB (after filtering allowed columns and adding columns 'name' and 'fileStats')
...
...
@@ -356,18 +366,6 @@ class FormAsFile
*/
publicstaticfunctionisFormQuery(string$sql):bool
{
// $sql = <<<END
// SELECT CONCAT('p:{{pageId:T}}&form=form&r=', f.id) as _pagee, f.id, f.name, f.title, f.tableName, CONCAT('form=form&r=', f.id) as _Paged FROM where
// FormFormElement,Form AS f ORDER BY f.name
//
// SELECT CONCAT('p:{{pageId:T}}&form=form&r=', f.id) as _pagee, f.id, f.name, f.title, f.tableName, CONCAT('form=form&r=', f.id) as _Paged From Order by Form AS f ORDER BY f.name
//
// SELECT CONCAT('p:{{pageId:T}}&form=form&r=', f.id) as _pagee, f.id, f.name, f.title, f.tableName, CONCAT('form=form&r=', f.id) as _Paged FRom having Form AS f ORDER BY f.name
//
// SELECT CONCAT('p:{{pageId:T}}&form=form&r=', f.id) as _pagee, f.id, f.name, f.title, f.tableName, CONCAT('form=form&r=', f.id) as _Paged from Form AS f ORDER BY f.name
//END;
// find substrings whihch start with FROM and are followed by Form or FormElement
$F_ID=F_ID;// can't use constants in strings directly
$TABLE_NAME_FORM=TABLE_NAME_FORM;// can't use constants in strings directly
...
...
@@ -513,32 +517,32 @@ class FormAsFile
// validate form name
if(!HelperFile::isValidFileName($formName)){
thrownew\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_MESSAGE_TO_USER=>'Reading/Writing Form file failed.',
ERROR_MESSAGE_TO_DEVELOPER=>"Form name '$formName' not valid. Name may only consist of alphanumeric characters and _ . -"]),
ERROR_FORM_INVALID_NAME);
}
// create form folder path
if(!is_dir(self::formPath())){
$success=mkdir(self::formPath(),0777,true);
if($success===false){
thrownew\UserFormException(json_encode([
ERROR_MESSAGE_TO_USER=>"Can't create form file path.",