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

Refs #12145 disable form sync using feature flag

parent 2adaecd2
Pipeline #5068 passed with stages
in 3 minutes and 37 seconds
...@@ -558,7 +558,8 @@ abstract class AbstractBuildForm { ...@@ -558,7 +558,8 @@ abstract class AbstractBuildForm {
$record = array(); $record = array();
if ($recordId != 0) { if ($recordId != 0) {
$record = $this->dbArray[$this->dbIndexData]->sql("SELECT * FROM `$tableName` WHERE `$primaryKey`=?", ROW_EXPECT_1, [$recordId], "Record to load not found. " . FormAsFile::errorHintFormImport($tableName)); $record = $this->dbArray[$this->dbIndexData]->sql("SELECT * FROM `$tableName` WHERE `$primaryKey`=?", ROW_EXPECT_1, [$recordId], "Record to load not found. "
. (FEATURE_FORM_SYNC ? FormAsFile::errorHintFormImport($tableName) : ''));
} }
if (isset($record[F_FILE_STATS])) { if (isset($record[F_FILE_STATS])) {
......
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
const EXT_KEY = 'qfq'; const EXT_KEY = 'qfq';
// Feature Flags
const FEATURE_FORM_SYNC = false; // Enable automatic form sync between database and form files.
const PROJECT_PATH_PHP_FILE = 'qfq.project.path.php'; const PROJECT_PATH_PHP_FILE = 'qfq.project.path.php';
const CONFIG_QFQ_PHP = "config.qfq.php"; // QFQ configuration file: db access - deprecated const CONFIG_QFQ_PHP = "config.qfq.php"; // QFQ configuration file: db access - deprecated
......
...@@ -158,20 +158,24 @@ class DatabaseUpdate { ...@@ -158,20 +158,24 @@ class DatabaseUpdate {
$this->dbUpdateStatements($old, $new); $this->dbUpdateStatements($old, $new);
if ($this->db->existTable('Form')) { if (FEATURE_FORM_SYNC) {
// If Form table exists, import all form files so everything is up to date. if ($this->db->existTable('Form')) {
FormAsFile::importAllForms($this->db, true); // Note: Creates path and exports all forms first if the form directory does not exist. // If Form table exists, import all form files so everything is up to date.
FormAsFile::importAllForms($this->db, true); // Note: Creates path and exports all forms first if the form directory does not exist.
// create Form table and export all system forms
$this->db->playSqlFile(__DIR__ . '/../../Sql/formEditor.sql'); // create Form table and export all system forms
FormAsFIle::exportAllForms($this->db); $this->db->playSqlFile(__DIR__ . '/../../Sql/formEditor.sql');
FormAsFIle::exportAllForms($this->db);
} else {
// If not, then create Form table and export all system forms
$this->db->playSqlFile(__DIR__ . '/../../Sql/formEditor.sql');
FormAsFIle::exportAllForms($this->db);
// import form files which existed before the new installation
FormAsFile::importAllForms($this->db, true);
}
} else { } else {
// If not, then create Form table and export all system forms
$this->db->playSqlFile(__DIR__ . '/../../Sql/formEditor.sql'); $this->db->playSqlFile(__DIR__ . '/../../Sql/formEditor.sql');
FormAsFIle::exportAllForms($this->db);
// import form files which existed before the new installation
FormAsFile::importAllForms($this->db, true);
} }
Logger::logMessage(date('Y.m.d H:i:s ') . ": Updated from QFQ version '$old' to '$new'", Path::absoluteQfqLogFile()); Logger::logMessage(date('Y.m.d H:i:s ') . ": Updated from QFQ version '$old' to '$new'", Path::absoluteQfqLogFile());
...@@ -188,7 +192,9 @@ class DatabaseUpdate { ...@@ -188,7 +192,9 @@ class DatabaseUpdate {
if (version_compare($old, '19.9.0') === -1) { if (version_compare($old, '19.9.0') === -1) {
$this->updateSpecialColumns(); $this->updateSpecialColumns();
FormAsFIle::exportAllForms($this->db); if (FEATURE_FORM_SYNC) {
FormAsFIle::exportAllForms($this->db);
}
} }
} }
......
...@@ -286,7 +286,8 @@ class Dirty { ...@@ -286,7 +286,8 @@ class Dirty {
$primaryKey = $tableVars[F_PRIMARY_KEY]; $primaryKey = $tableVars[F_PRIMARY_KEY];
$formDirtyMode = $tableVars[F_DIRTY_MODE]; $formDirtyMode = $tableVars[F_DIRTY_MODE];
$record = $this->dbArray[$this->dbIndexData]->sql("SELECT * FROM `$tableName` WHERE `$primaryKey`=?", ROW_EXPECT_1, [$recordId], "Record to lock not found. " . FormAsFile::errorHintFormImport($tableName)); $record = $this->dbArray[$this->dbIndexData]->sql("SELECT * FROM `$tableName` WHERE `$primaryKey`=?", ROW_EXPECT_1, [$recordId], "Record to lock not found. "
. (FEATURE_FORM_SYNC ? FormAsFile::errorHintFormImport($tableName) : ''));
# Dirty workaround: setting the 'expired timestamp' minus 1 second guarantees that the client ask for relock always if the timeout is expired. # Dirty workaround: setting the 'expired timestamp' minus 1 second guarantees that the client ask for relock always if the timeout is expired.
$expire = date('Y-m-d H:i:s', strtotime("+" . $tableVars[F_RECORD_LOCK_TIMEOUT_SECONDS] - 1 . " seconds")); $expire = date('Y-m-d H:i:s', strtotime("+" . $tableVars[F_RECORD_LOCK_TIMEOUT_SECONDS] - 1 . " seconds"));
...@@ -320,7 +321,8 @@ class Dirty { ...@@ -320,7 +321,8 @@ class Dirty {
return false; // If there is no recordHashMd5, the check is not possible. Always return 'not modified' (=ok) return false; // If there is no recordHashMd5, the check is not possible. Always return 'not modified' (=ok)
} }
$record = $this->dbArray[$this->dbIndexData]->sql("SELECT * FROM `$tableName` WHERE `$primaryKey`=?", ROW_EXPECT_1, [$recordId], "Record to lock not found. " . FormAsFile::errorHintFormImport($tableName)); $record = $this->dbArray[$this->dbIndexData]->sql("SELECT * FROM `$tableName` WHERE `$primaryKey`=?", ROW_EXPECT_1, [$recordId], "Record to lock not found. "
. (FEATURE_FORM_SYNC ? FormAsFile::errorHintFormImport($tableName) : ''));
if (isset($record[F_FILE_STATS])) { if (isset($record[F_FILE_STATS])) {
// why: The column "fileStats" in the Form table is modified when a form is exported to a file but nothing else changes. // why: The column "fileStats" in the Form table is modified when a form is exported to a file but nothing else changes.
......
...@@ -125,9 +125,11 @@ class DragAndDrop { ...@@ -125,9 +125,11 @@ class DragAndDrop {
$nameId = false; $nameId = false;
$nameOrd = false; $nameOrd = false;
// Import Form from file if loaded record is Form/FormElement (If form file was changed, throw exception) if (FEATURE_FORM_SYNC) {
// Note: This is here since this code is called outside QuickFormQuery->doForm // Import Form from file if loaded record is Form/FormElement (If form file was changed, throw exception)
$formFileName = FormAsFile::importFormRecordId($dragId, $tableName, $this->db); // Note: This is here since this code is called outside QuickFormQuery->doForm
$formFileName = FormAsFile::importFormRecordId($dragId, $tableName, $this->db);
}
// Reorder. Get index for 'drag' and 'hover' // Reorder. Get index for 'drag' and 'hover'
foreach ($rows as $key => $row) { foreach ($rows as $key => $row) {
...@@ -168,9 +170,11 @@ class DragAndDrop { ...@@ -168,9 +170,11 @@ class DragAndDrop {
$ord += $orderInterval; $ord += $orderInterval;
} }
// Export Form file if (FEATURE_FORM_SYNC) {
if ($formFileName !== null) { // Export Form file
FormAsFile::exportForm($formFileName, $this->db); if ($formFileName !== null) {
FormAsFile::exportForm($formFileName, $this->db);
}
} }
return $data; return $data;
......
...@@ -456,27 +456,29 @@ class QuickFormQuery { ...@@ -456,27 +456,29 @@ class QuickFormQuery {
} }
} }
// FormAsFile: Get the new and the old form file name and make sure both files are writable (before DB changes are made) if (FEATURE_FORM_SYNC) {
// Note: This can't be done earlier because $formModeNew might be changed in the lines above. // FormAsFile: Get the new and the old form file name and make sure both files are writable (before DB changes are made)
$formNameDB = FormAsFile::formNameFromFormRelatedRecord($recordId, $this->formSpec[F_TABLE_NAME] ?? '', $this->dbArray[$this->dbIndexQfq]); // Note: This can't be done earlier because $formModeNew might be changed in the lines above.
switch ($this->formSpec[F_TABLE_NAME] ?? '') { $formNameDB = FormAsFile::formNameFromFormRelatedRecord($recordId, $this->formSpec[F_TABLE_NAME] ?? '', $this->dbArray[$this->dbIndexQfq]);
case TABLE_NAME_FORM: // cases covered: new form, existing form, existing form but form name changed switch ($this->formSpec[F_TABLE_NAME] ?? '') {
$formFileName = $this->store->getVar(F_NAME, STORE_FORM, SANITIZE_ALLOW_ALNUMX); case TABLE_NAME_FORM: // cases covered: new form, existing form, existing form but form name changed
$formFileName = $formFileName === false ? $formNameDB : $formFileName; $formFileName = $this->store->getVar(F_NAME, STORE_FORM, SANITIZE_ALLOW_ALNUMX);
if ($formNameDB !== null && $formFileName !== $formNameDB && $formModeNew === FORM_SAVE) { $formFileName = $formFileName === false ? $formNameDB : $formFileName;
$formFileNameDelete = $formNameDB; if ($formNameDB !== null && $formFileName !== $formNameDB && $formModeNew === FORM_SAVE) {
FormAsFile::enforceFormFileWritable($formFileNameDelete, $this->dbArray[$this->dbIndexQfq]); // file will be deleted after DB changes $formFileNameDelete = $formNameDB;
} FormAsFile::enforceFormFileWritable($formFileNameDelete, $this->dbArray[$this->dbIndexQfq]); // file will be deleted after DB changes
break; }
case TABLE_NAME_FORM_ELEMENT: // cases covered: new formElement, existing formElement break;
$formId = $this->store->getVar(FE_FORM_ID, STORE_FORM); case TABLE_NAME_FORM_ELEMENT: // cases covered: new formElement, existing formElement
$formFileName = $formId !== false ? FormAsFile::formNameFromFormRelatedRecord($formId, TABLE_NAME_FORM, $this->dbArray[$this->dbIndexQfq]) : $formNameDB; $formId = $this->store->getVar(FE_FORM_ID, STORE_FORM);
break; $formFileName = $formId !== false ? FormAsFile::formNameFromFormRelatedRecord($formId, TABLE_NAME_FORM, $this->dbArray[$this->dbIndexQfq]) : $formNameDB;
default: break;
$formFileName = $formNameDB; default:
} $formFileName = $formNameDB;
if ($formFileName !== null && in_array($formModeNew, [FORM_SAVE, FORM_DRAG_AND_DROP, FORM_DELETE])) { }
FormAsFile::enforceFormFileWritable($formFileName, $this->dbArray[$this->dbIndexQfq]); if ($formFileName !== null && in_array($formModeNew, [FORM_SAVE, FORM_DRAG_AND_DROP, FORM_DELETE])) {
FormAsFile::enforceFormFileWritable($formFileName, $this->dbArray[$this->dbIndexQfq]);
}
} }
// 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.
...@@ -677,26 +679,27 @@ class QuickFormQuery { ...@@ -677,26 +679,27 @@ class QuickFormQuery {
$data = $this->groupElementUpdateEntries($data); $data = $this->groupElementUpdateEntries($data);
} }
// export Form to file, if loaded record is a Form/FormElement if (FEATURE_FORM_SYNC) {
if ($formFileName !== null) { // export Form to file, if loaded record is a Form/FormElement
switch ($formModeNew) { if ($formFileName !== null) {
case FORM_SAVE: switch ($formModeNew) {
case FORM_DRAG_AND_DROP: case FORM_SAVE:
FormAsFile::exportForm($formFileName, $this->dbArray[$this->dbIndexQfq]); case FORM_DRAG_AND_DROP:
break;
case FORM_DELETE:
if (TABLE_NAME_FORM_ELEMENT === ($this->formSpec[F_TABLE_NAME] ?? '')) {
FormAsFile::exportForm($formFileName, $this->dbArray[$this->dbIndexQfq]); FormAsFile::exportForm($formFileName, $this->dbArray[$this->dbIndexQfq]);
} else { break;
FormAsFile::deleteFormFile($formFileName, $this->dbArray[$this->dbIndexQfq], 'Form was deleted using form-editor.'); case FORM_DELETE:
} if (TABLE_NAME_FORM_ELEMENT === ($this->formSpec[F_TABLE_NAME] ?? '')) {
break; FormAsFile::exportForm($formFileName, $this->dbArray[$this->dbIndexQfq]);
} else {
FormAsFile::deleteFormFile($formFileName, $this->dbArray[$this->dbIndexQfq], 'Form was deleted using form-editor.');
}
break;
}
}
// delete old form file if form name was changed
if (isset($formFileNameDelete)) {
FormAsFile::deleteFormFile($formFileNameDelete, $this->dbArray[$this->dbIndexQfq], "Form was renamed to: '$formFileName'.");
} }
}
// delete old form file if form name was changed
if (isset($formFileNameDelete)) {
FormAsFile::deleteFormFile($formFileNameDelete, $this->dbArray[$this->dbIndexQfq], "Form was renamed to: '$formFileName'.");
} }
return $data; return $data;
...@@ -1087,16 +1090,20 @@ class QuickFormQuery { ...@@ -1087,16 +1090,20 @@ class QuickFormQuery {
// Preparation for Log, Debug // Preparation for Log, Debug
$this->store->setVar(SYSTEM_FORM, $formName, STORE_SYSTEM); $this->store->setVar(SYSTEM_FORM, $formName, STORE_SYSTEM);
// Check for form file changes if (FEATURE_FORM_SYNC) {
FormAsFile::importForm($formName, $this->dbArray[$this->dbIndexQfq]); // Check for form file changes
FormAsFile::importForm($formName, $this->dbArray[$this->dbIndexQfq]);
}
// Load form // Load form
$constant = F_NAME; // PhpStorm complains if the constant is directly defined in the string below $constant = F_NAME; // PhpStorm complains if the constant is directly defined in the string below
$form = $this->dbArray[$this->dbIndexQfq]->sql("SELECT * FROM `Form` AS f WHERE `f`.`$constant` LIKE ? AND `f`.`deleted`='no'", ROW_EXPECT_1, $form = $this->dbArray[$this->dbIndexQfq]->sql("SELECT * FROM `Form` AS f WHERE `f`.`$constant` LIKE ? AND `f`.`deleted`='no'", ROW_EXPECT_1,
[$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) if (FEATURE_FORM_SYNC) {
FormAsFile::importFormRecordId($recordId, $form[F_TABLE_NAME], $this->dbArray[$this->dbIndexQfq]); // Import Form from file if loaded record is Form/FormElement (If form file was changed, throw exception)
FormAsFile::importFormRecordId($recordId, $form[F_TABLE_NAME], $this->dbArray[$this->dbIndexQfq]);
}
$form = $this->checkFormLogMode($form); $form = $this->checkFormLogMode($form);
$form = $this->modeCleanFormConfig($mode, $form); $form = $this->modeCleanFormConfig($mode, $form);
......
...@@ -588,9 +588,11 @@ class Report { ...@@ -588,9 +588,11 @@ class Report {
$this->store->setVar(SYSTEM_SQL_FINAL, $sql, STORE_SYSTEM); $this->store->setVar(SYSTEM_SQL_FINAL, $sql, STORE_SYSTEM);
// import form files if changed + delete Forms without form file if (FEATURE_FORM_SYNC) {
if (FormAsFile::isFormQuery($sql)) { // import form files if changed + delete Forms without form file
FormAsFile::importAllForms($this->db, false, true); if (FormAsFile::isFormQuery($sql)) {
FormAsFile::importAllForms($this->db, false, true);
}
} }
$stat = array(); $stat = array();
......
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