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 {
$record = array();
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])) {
......
......@@ -8,6 +8,9 @@
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 CONFIG_QFQ_PHP = "config.qfq.php"; // QFQ configuration file: db access - deprecated
......
......@@ -158,20 +158,24 @@ class DatabaseUpdate {
$this->dbUpdateStatements($old, $new);
if ($this->db->existTable('Form')) {
// 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');
FormAsFIle::exportAllForms($this->db);
if (FEATURE_FORM_SYNC) {
if ($this->db->existTable('Form')) {
// 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');
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 {
// 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);
}
Logger::logMessage(date('Y.m.d H:i:s ') . ": Updated from QFQ version '$old' to '$new'", Path::absoluteQfqLogFile());
......@@ -188,7 +192,9 @@ class DatabaseUpdate {
if (version_compare($old, '19.9.0') === -1) {
$this->updateSpecialColumns();
FormAsFIle::exportAllForms($this->db);
if (FEATURE_FORM_SYNC) {
FormAsFIle::exportAllForms($this->db);
}
}
}
......
......@@ -286,7 +286,8 @@ class Dirty {
$primaryKey = $tableVars[F_PRIMARY_KEY];
$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.
$expire = date('Y-m-d H:i:s', strtotime("+" . $tableVars[F_RECORD_LOCK_TIMEOUT_SECONDS] - 1 . " seconds"));
......@@ -320,7 +321,8 @@ class Dirty {
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])) {
// 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 {
$nameId = false;
$nameOrd = false;
// Import Form from file if loaded record is Form/FormElement (If form file was changed, throw exception)
// Note: This is here since this code is called outside QuickFormQuery->doForm
$formFileName = FormAsFile::importFormRecordId($dragId, $tableName, $this->db);
if (FEATURE_FORM_SYNC) {
// Import Form from file if loaded record is Form/FormElement (If form file was changed, throw exception)
// 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'
foreach ($rows as $key => $row) {
......@@ -168,9 +170,11 @@ class DragAndDrop {
$ord += $orderInterval;
}
// Export Form file
if ($formFileName !== null) {
FormAsFile::exportForm($formFileName, $this->db);
if (FEATURE_FORM_SYNC) {
// Export Form file
if ($formFileName !== null) {
FormAsFile::exportForm($formFileName, $this->db);
}
}
return $data;
......
......@@ -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)
// 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] ?? '') {
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 ? $formNameDB : $formFileName;
if ($formNameDB !== null && $formFileName !== $formNameDB && $formModeNew === FORM_SAVE) {
$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
$formId = $this->store->getVar(FE_FORM_ID, STORE_FORM);
$formFileName = $formId !== false ? FormAsFile::formNameFromFormRelatedRecord($formId, TABLE_NAME_FORM, $this->dbArray[$this->dbIndexQfq]) : $formNameDB;
break;
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 (FEATURE_FORM_SYNC) {
// 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] ?? '') {
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 ? $formNameDB : $formFileName;
if ($formNameDB !== null && $formFileName !== $formNameDB && $formModeNew === FORM_SAVE) {
$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
$formId = $this->store->getVar(FE_FORM_ID, STORE_FORM);
$formFileName = $formId !== false ? FormAsFile::formNameFromFormRelatedRecord($formId, TABLE_NAME_FORM, $this->dbArray[$this->dbIndexQfq]) : $formNameDB;
break;
default:
$formFileName = $formNameDB;
}
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.
......@@ -677,26 +679,27 @@ class QuickFormQuery {
$data = $this->groupElementUpdateEntries($data);
}
// export Form to file, if loaded record is a Form/FormElement
if ($formFileName !== null) {
switch ($formModeNew) {
case FORM_SAVE:
case FORM_DRAG_AND_DROP:
FormAsFile::exportForm($formFileName, $this->dbArray[$this->dbIndexQfq]);
break;
case FORM_DELETE:
if (TABLE_NAME_FORM_ELEMENT === ($this->formSpec[F_TABLE_NAME] ?? '')) {
if (FEATURE_FORM_SYNC) {
// export Form to file, if loaded record is a Form/FormElement
if ($formFileName !== null) {
switch ($formModeNew) {
case FORM_SAVE:
case FORM_DRAG_AND_DROP:
FormAsFile::exportForm($formFileName, $this->dbArray[$this->dbIndexQfq]);
} else {
FormAsFile::deleteFormFile($formFileName, $this->dbArray[$this->dbIndexQfq], 'Form was deleted using form-editor.');
}
break;
break;
case FORM_DELETE:
if (TABLE_NAME_FORM_ELEMENT === ($this->formSpec[F_TABLE_NAME] ?? '')) {
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;
......@@ -1087,16 +1090,20 @@ class QuickFormQuery {
// Preparation for Log, Debug
$this->store->setVar(SYSTEM_FORM, $formName, STORE_SYSTEM);
// Check for form file changes
FormAsFile::importForm($formName, $this->dbArray[$this->dbIndexQfq]);
if (FEATURE_FORM_SYNC) {
// Check for form file changes
FormAsFile::importForm($formName, $this->dbArray[$this->dbIndexQfq]);
}
// Load form
$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,
[$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)
FormAsFile::importFormRecordId($recordId, $form[F_TABLE_NAME], $this->dbArray[$this->dbIndexQfq]);
if (FEATURE_FORM_SYNC) {
// 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->modeCleanFormConfig($mode, $form);
......
......@@ -588,9 +588,11 @@ class Report {
$this->store->setVar(SYSTEM_SQL_FINAL, $sql, STORE_SYSTEM);
// import form files if changed + delete Forms without form file
if (FormAsFile::isFormQuery($sql)) {
FormAsFile::importAllForms($this->db, false, true);
if (FEATURE_FORM_SYNC) {
// import form files if changed + delete Forms without form file
if (FormAsFile::isFormQuery($sql)) {
FormAsFile::importAllForms($this->db, false, true);
}
}
$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