Commit b1e8b011 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Bug 5004 FormElement with state 'ReadOnly' will be saved with empty value -...

Bug 5004 FormElement with state 'ReadOnly' will be saved with empty value - existing values will be overwritten.
parent 61a9cf35
...@@ -49,6 +49,7 @@ const RETURN_URL = 'return_url'; ...@@ -49,6 +49,7 @@ const RETURN_URL = 'return_url';
const RETURN_SIP = 'return_sip'; const RETURN_SIP = 'return_sip';
const RETURN_ARRAY = 'return_array'; const RETURN_ARRAY = 'return_array';
const SQL_FORM_ELEMENT_RAW = "SELECT * FROM FormElement AS fe WHERE fe.formId = ? AND fe.deleted = 'no' AND fe.enabled='yes' ORDER BY fe.ord, fe.id";
const SQL_FORM_ELEMENT_SPECIFIC_CONTAINER = "SELECT *, ? AS 'nestedInFieldSet' FROM FormElement AS fe WHERE fe.formId = ? AND fe.deleted = 'no' AND FIND_IN_SET(fe.class, ? ) AND fe.feIdContainer = ? AND fe.enabled='yes' ORDER BY fe.ord, fe.id"; const SQL_FORM_ELEMENT_SPECIFIC_CONTAINER = "SELECT *, ? AS 'nestedInFieldSet' FROM FormElement AS fe WHERE fe.formId = ? AND fe.deleted = 'no' AND FIND_IN_SET(fe.class, ? ) AND fe.feIdContainer = ? AND fe.enabled='yes' ORDER BY fe.ord, fe.id";
const SQL_FORM_ELEMENT_ALL_CONTAINER = "SELECT *, ? AS 'nestedInFieldSet' FROM FormElement AS fe WHERE fe.formId = ? AND fe.deleted = 'no' AND FIND_IN_SET(fe.class, ? ) AND fe.enabled='yes' ORDER BY fe.ord, fe.id"; const SQL_FORM_ELEMENT_ALL_CONTAINER = "SELECT *, ? AS 'nestedInFieldSet' FROM FormElement AS fe WHERE fe.formId = ? AND fe.deleted = 'no' AND FIND_IN_SET(fe.class, ? ) AND fe.enabled='yes' ORDER BY fe.ord, fe.id";
const SQL_FORM_ELEMENT_SIMPLE_ALL_CONTAINER = "SELECT fe.id, fe.feIdContainer, fe.name, fe.label, fe.type, fe.encode, fe.checkType, fe.checkPattern, fe.mode, fe.modeSql, fe.parameter, fe.dynamicUpdate FROM FormElement AS fe, Form AS f WHERE f.name = ? AND f.id = fe.formId AND fe.deleted = 'no' AND fe.class = 'native' AND fe.enabled='yes' ORDER BY fe.ord, fe.id"; const SQL_FORM_ELEMENT_SIMPLE_ALL_CONTAINER = "SELECT fe.id, fe.feIdContainer, fe.name, fe.label, fe.type, fe.encode, fe.checkType, fe.checkPattern, fe.mode, fe.modeSql, fe.parameter, fe.dynamicUpdate FROM FormElement AS fe, Form AS f WHERE f.name = ? AND f.id = fe.formId AND fe.deleted = 'no' AND fe.class = 'native' AND fe.enabled='yes' ORDER BY fe.ord, fe.id";
...@@ -109,7 +110,7 @@ const ERROR_SIP_INVALID = 1006; ...@@ -109,7 +110,7 @@ const ERROR_SIP_INVALID = 1006;
const ERROR_MISSING_RECORD_ID = 1007; const ERROR_MISSING_RECORD_ID = 1007;
const ERROR_IN_SQL_STATEMENT = 1008; const ERROR_IN_SQL_STATEMENT = 1008;
const ERROR_MISSING_REQUIRED_PARAMETER = 1009; const ERROR_MISSING_REQUIRED_PARAMETER = 1009;
const ERROR_FE_NESTED_TOO_MUCH = 1010;
const ERROR_BROKEN_PARAMETER = 1011; const ERROR_BROKEN_PARAMETER = 1011;
const ERROR_FE_USER_UID_CHANGED = 1012; const ERROR_FE_USER_UID_CHANGED = 1012;
const ERROR_SIP_NOT_FOUND = 1013; const ERROR_SIP_NOT_FOUND = 1013;
......
...@@ -80,6 +80,7 @@ class QuickFormQuery { ...@@ -80,6 +80,7 @@ class QuickFormQuery {
protected $formSpec = array(); protected $formSpec = array();
protected $feSpecAction = array(); // Form Definition: copy of the loaded form protected $feSpecAction = array(); // Form Definition: copy of the loaded form
protected $feSpecNative = array(); // FormEelement Definition: all formElement.class='action' of the loaded form protected $feSpecNative = array(); // FormEelement Definition: all formElement.class='action' of the loaded form
protected $feSpecNativeRaw = array(); // FormEelement Definition: all formElement.class='action' of the loaded form
/** /**
* @var array * @var array
...@@ -383,7 +384,7 @@ class QuickFormQuery { ...@@ -383,7 +384,7 @@ class QuickFormQuery {
$this->fillStoreWithRecord($this->formSpec[F_TABLE_NAME], $recordId, STORE_RECORD); $this->fillStoreWithRecord($this->formSpec[F_TABLE_NAME], $recordId, STORE_RECORD);
// SAVE // SAVE
$save = new Save($this->formSpec, $this->feSpecAction, $this->feSpecNative); $save = new Save($this->formSpec, $this->feSpecAction, $this->feSpecNative, $this->feSpecNativeRaw);
$rc = $save->process(); $rc = $save->process();
// Reload fresh saved record and fill STORE_RECORD with it. // Reload fresh saved record and fill STORE_RECORD with it.
...@@ -692,6 +693,9 @@ class QuickFormQuery { ...@@ -692,6 +693,9 @@ class QuickFormQuery {
// Clear // Clear
$this->store->setVar(SYSTEM_FORM_ELEMENT, '', STORE_SYSTEM); $this->store->setVar(SYSTEM_FORM_ELEMENT, '', STORE_SYSTEM);
// Read all 'active' FE
$this->feSpecNativeRaw = $this->dbArray[$this->dbIndexQfq]->sql(SQL_FORM_ELEMENT_RAW, ROW_REGULAR, [$this->formSpec["id"]]);
// FE: Action // FE: Action
$this->feSpecAction = $this->dbArray[$this->dbIndexQfq]->sql(SQL_FORM_ELEMENT_ALL_CONTAINER, ROW_REGULAR, ['no', $this->formSpec["id"], 'action']); $this->feSpecAction = $this->dbArray[$this->dbIndexQfq]->sql(SQL_FORM_ELEMENT_ALL_CONTAINER, ROW_REGULAR, ['no', $this->formSpec["id"], 'action']);
HelperFormElement::explodeParameterInArrayElements($this->feSpecAction, FE_PARAMETER); HelperFormElement::explodeParameterInArrayElements($this->feSpecAction, FE_PARAMETER);
......
...@@ -23,6 +23,7 @@ class Save { ...@@ -23,6 +23,7 @@ class Save {
private $formSpec = array(); // copy of the loaded form private $formSpec = array(); // copy of the loaded form
private $feSpecAction = array(); // copy of all formElement.class='action' of the loaded form private $feSpecAction = array(); // copy of all formElement.class='action' of the loaded form
private $feSpecNative = array(); // copy of all formElement.class='native' of the loaded form private $feSpecNative = array(); // copy of all formElement.class='native' of the loaded form
private $feSpecNativeRaw = array(); // copy of all formElement.class='native' of the loaded form
/** /**
* @var null|Store * @var null|Store
*/ */
...@@ -35,11 +36,13 @@ class Save { ...@@ -35,11 +36,13 @@ class Save {
* @param array $formSpec * @param array $formSpec
* @param array $feSpecAction * @param array $feSpecAction
* @param array $feSpecNative * @param array $feSpecNative
* @param array $feSpecNativeRaw
*/ */
public function __construct(array $formSpec, array $feSpecAction, array $feSpecNative) { public function __construct(array $formSpec, array $feSpecAction, array $feSpecNative, array $feSpecNativeRaw) {
$this->formSpec = $formSpec; $this->formSpec = $formSpec;
$this->feSpecAction = $feSpecAction; $this->feSpecAction = $feSpecAction;
$this->feSpecNative = $feSpecNative; $this->feSpecNative = $feSpecNative;
$this->feSpecNativeRaw = $feSpecNativeRaw;
$this->store = Store::getInstance(); $this->store = Store::getInstance();
$this->db = new Database(); $this->db = new Database();
$this->evaluate = new Evaluate($this->store, $this->db); $this->evaluate = new Evaluate($this->store, $this->db);
...@@ -91,8 +94,7 @@ class Save { ...@@ -91,8 +94,7 @@ class Save {
break; break;
} }
$feName = $formElement[FE_NAME]; $feName = $formElement[FE_NAME];
if (!isset($formValues[$feName])) { if (!isset($formValues[$feName]) && $this->isMemberOfTemplateGroup($formElement)) {
$formValues[$feName] = $formElement[FE_VALUE]; $formValues[$feName] = $formElement[FE_VALUE];
} }
} }
...@@ -101,6 +103,39 @@ class Save { ...@@ -101,6 +103,39 @@ class Save {
} }
/** /**
* Check if the current $formElement is member of a templateGroup.
*
* @param array $formElement
* @param int $depth
* @return bool
* @throws UserFormException
*/
private function isMemberOfTemplateGroup(array $formElement, $depth = 0) {
$depth++;
if ($depth > 15) {
throw new UserFormException('FormElement nested too much (in each other - endless?): stop recursion', ERROR_FE_NESTED_TOO_MUCH);
}
if ($formElement[FE_TYPE] == FE_TYPE_TEMPLATE_GROUP) {
return true;
}
if ($formElement[FE_ID_CONTAINER] == 0) {
return false;
}
// Get the parent element
$formElementArr = OnArray::filter($this->feSpecNativeRaw, FE_ID, $formElement[FE_ID_CONTAINER]);
if (isset($formElementArr[0])) {
return $this->isMemberOfTemplateGroup($formElementArr[0], $depth);
}
return false; // This should not be reached,
}
/**
*
* @param $feName * @param $feName
* *
* @return bool * @return bool
...@@ -502,21 +537,4 @@ class Save { ...@@ -502,21 +537,4 @@ class Save {
return $slaveId; return $slaveId;
} }
/**
* Get the complete FormElement for $name
*
* @param $name
*
* @return bool|array if found the FormElement, else false.
*/
private function getFormElementByName($name) {
foreach ($this->feSpecNative as $formElement) {
if ($formElement['name'] === $name)
return $formElement;
}
return false;
}
} }
\ No newline at end of file
...@@ -19,7 +19,7 @@ class SaveTest extends AbstractDatabaseTest { ...@@ -19,7 +19,7 @@ class SaveTest extends AbstractDatabaseTest {
public function testUpdateRecord() { public function testUpdateRecord() {
$save = new qfq\Save(array(), array(), array()); $save = new qfq\Save(array(), array(), array(), array());
// $db = new qfq\Database(); // $db = new qfq\Database();
$values = ['name' => 'Doe', 'firstName' => 'John']; $values = ['name' => 'Doe', 'firstName' => 'John'];
...@@ -31,13 +31,13 @@ class SaveTest extends AbstractDatabaseTest { ...@@ -31,13 +31,13 @@ class SaveTest extends AbstractDatabaseTest {
$sql = "SELECT name, firstName FROM Person WHERE id = ? "; $sql = "SELECT name, firstName FROM Person WHERE id = ? ";
$result = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql($sql, ROW_REGULAR, [$id]); $result = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql($sql, ROW_REGULAR, [$id]);
$this->assertEquals($values, $result[0]); $this->assertEquals($values, $result[0], array());
} }
public function testInsertRecord() { public function testInsertRecord() {
$save = new qfq\Save(array(), array(), array()); $save = new qfq\Save(array(), array(), array(), array());
// $db = new qfq\Database(); // $db = new qfq\Database();
$values = ['name' => 'Doe', 'firstName' => 'John']; $values = ['name' => 'Doe', 'firstName' => 'John'];
......
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