Commit 9ee1995b authored by Elias Villiger's avatar Elias Villiger
Browse files

Merge branch 'B5467-min-max-parameters' into 'master'

B5467 min max parameters

See merge request !84
parents a18c5cb5 9ca14668
Pipeline #872 passed with stage
in 1 minute and 40 seconds
...@@ -389,7 +389,8 @@ class QuickFormQuery { ...@@ -389,7 +389,8 @@ class QuickFormQuery {
} }
if ($this->store->getVar('id', STORE_BEFORE) === false) { if ($this->store->getVar('id', STORE_BEFORE) === false) {
$this->fillStoreWithRecord($this->formSpec[F_TABLE_NAME], $recordId, STORE_BEFORE); $this->store->fillStoreWithRecord($this->formSpec[F_TABLE_NAME], $recordId,
$this->dbArray[$this->dbIndexData], STORE_BEFORE);
} }
// Check (and release) dirtyRecord. // Check (and release) dirtyRecord.
...@@ -474,7 +475,8 @@ class QuickFormQuery { ...@@ -474,7 +475,8 @@ class QuickFormQuery {
$formAction->elements($recordId, $this->feSpecAction, FE_TYPE_BEFORE_INSERT . ',' . FE_TYPE_BEFORE_UPDATE . ',' . FE_TYPE_BEFORE_SAVE); $formAction->elements($recordId, $this->feSpecAction, FE_TYPE_BEFORE_INSERT . ',' . FE_TYPE_BEFORE_UPDATE . ',' . FE_TYPE_BEFORE_SAVE);
// If an old record exist: load it. Necessary to delete uploaded files which should be overwritten. // If an old record exist: load it. Necessary to delete uploaded files which should be overwritten.
$this->fillStoreWithRecord($this->formSpec[F_TABLE_NAME], $recordId, STORE_RECORD); $this->store->fillStoreWithRecord($this->formSpec[F_TABLE_NAME], $recordId,
$this->dbArray[$this->dbIndexData]);
// SAVE // SAVE
$save = new Save($this->formSpec, $this->feSpecAction, $this->feSpecNative, $this->feSpecNativeRaw); $save = new Save($this->formSpec, $this->feSpecAction, $this->feSpecNative, $this->feSpecNativeRaw);
...@@ -485,7 +487,7 @@ class QuickFormQuery { ...@@ -485,7 +487,7 @@ class QuickFormQuery {
$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.
$this->fillStoreWithRecord($this->formSpec[F_TABLE_NAME], $rc, STORE_RECORD); $this->store->fillStoreWithRecord($this->formSpec[F_TABLE_NAME], $rc, $this->dbArray[$this->dbIndexData]);
$save->processAllUploads($rc); $save->processAllUploads($rc);
...@@ -493,7 +495,7 @@ class QuickFormQuery { ...@@ -493,7 +495,7 @@ class QuickFormQuery {
$status = $formAction->elements($rc, $this->feSpecAction, FE_TYPE_AFTER_INSERT . ',' . FE_TYPE_AFTER_UPDATE . ',' . FE_TYPE_AFTER_SAVE); $status = $formAction->elements($rc, $this->feSpecAction, FE_TYPE_AFTER_INSERT . ',' . FE_TYPE_AFTER_UPDATE . ',' . FE_TYPE_AFTER_SAVE);
if ($status != ACTION_ELEMENT_NO_CHANGE) { if ($status != ACTION_ELEMENT_NO_CHANGE) {
// Reload fresh saved record and fill STORE_RECORD with it. // Reload fresh saved record and fill STORE_RECORD with it.
$this->fillStoreWithRecord($this->formSpec[F_TABLE_NAME], $rc, STORE_RECORD); $this->store->fillStoreWithRecord($this->formSpec[F_TABLE_NAME], $rc, $this->dbArray[$this->dbIndexData]);
} }
// Action: Paste // Action: Paste
...@@ -856,7 +858,7 @@ class QuickFormQuery { ...@@ -856,7 +858,7 @@ class QuickFormQuery {
// This is needed for filling templateGroup records with their default values // This is needed for filling templateGroup records with their default values
// and for evaluating variables in the Form title // and for evaluating variables in the Form title
$this->fillStoreWithRecord($form[F_TABLE_NAME], $recordId, STORE_RECORD); $this->store->fillStoreWithRecord($form[F_TABLE_NAME], $recordId, $this->dbArray[$this->dbIndexData]);
$formSpec = $this->eval->parseArray($form); $formSpec = $this->eval->parseArray($form);
...@@ -1311,24 +1313,6 @@ class QuickFormQuery { ...@@ -1311,24 +1313,6 @@ class QuickFormQuery {
return $sipFound; return $sipFound;
} }
/**
* Load record $id from $table and saves them in $store
*
* @param array $table tablename
* @param string $recordId record ID of current record
* @param string $store name of store where to save the record
*
* @throws CodeException
* @throws DbException
* @throws UserFormException
*/
private function fillStoreWithRecord($table, $recordId, $store = STORE_RECORD) {
if ($recordId !== false && $recordId > 0) {
$record = $this->dbArray[$this->dbIndexData]->sql("SELECT * FROM $table WHERE id = ?", ROW_EXPECT_1, [$recordId]);
$this->store->setStore($record, $store, true);
}
}
/** /**
* Searches the whole array $dataArray on the second level for API_ELEMENT_UPDATE. * Searches the whole array $dataArray on the second level for API_ELEMENT_UPDATE.
* All found elements collect under $collect[API_ELEMENT_UPDATE]... . Leave the rest unchanged. * All found elements collect under $collect[API_ELEMENT_UPDATE]... . Leave the rest unchanged.
...@@ -1518,7 +1502,7 @@ class QuickFormQuery { ...@@ -1518,7 +1502,7 @@ class QuickFormQuery {
// Subrecord DragAndDrop // Subrecord DragAndDrop
$subrecord = $this->dbArray[$this->dbIndexQfq]->sql(SQL_FORM_ELEMENT_BY_ID, ROW_REGULAR, [$dndSubrecordId]); $subrecord = $this->dbArray[$this->dbIndexQfq]->sql(SQL_FORM_ELEMENT_BY_ID, ROW_REGULAR, [$dndSubrecordId]);
$recordId = $this->store->getVar(DND_SUBRECORD_FORM_ID, STORE_SIP . STORE_ZERO); $recordId = $this->store->getVar(DND_SUBRECORD_FORM_ID, STORE_SIP . STORE_ZERO);
$this->fillStoreWithRecord('Form', $recordId); $this->store->fillStoreWithRecord('Form', $recordId, $this->dbArray[$this->dbIndexQfq]);
$dndOrderSql = $this->eval->parse($subrecord[0][FE_SQL1]); $dndOrderSql = $this->eval->parse($subrecord[0][FE_SQL1]);
foreach ($dndOrderSql as $i => $row) { foreach ($dndOrderSql as $i => $row) {
foreach ($row as $key => $value) { foreach ($row as $key => $value) {
......
...@@ -149,7 +149,7 @@ class FormAction { ...@@ -149,7 +149,7 @@ class FormAction {
break; break;
default: default:
// Always work on recent data: previous actions might have modified the data. // Always work on recent data: previous actions might have modified the data.
$this->fillStoreRecord($this->primaryTableName, $recordId); $this->store->fillStoreWithRecord($this->primaryTableName, $recordId, $this->db);
} }
if (!$this->checkRequiredList($fe)) { if (!$this->checkRequiredList($fe)) {
...@@ -196,28 +196,6 @@ class FormAction { ...@@ -196,28 +196,6 @@ class FormAction {
return $rc; return $rc;
} }
/**
* Copy the current primary record to STORE_RECORD
*
* @param $table
* @param $recordId
*
* @throws CodeException
* @throws DbException
* @throws UserFormException
*/
private function fillStoreRecord($table, $recordId) {
if (!is_string($table) || $table === '') {
throw new UserFormException("");
}
if ($recordId !== false && $recordId > 0) {
$record = $this->db->sql("SELECT * FROM $table WHERE id = ?", ROW_EXPECT_1, [$recordId]);
$this->store->setStore($record, STORE_RECORD, true);
}
}
/** /**
* Process all FormElements given in the `requiredList` identified by their name. * Process all FormElements given in the `requiredList` identified by their name.
* If none is empty in STORE_FORM return true, else false. * If none is empty in STORE_FORM return true, else false.
......
...@@ -54,6 +54,7 @@ class FillStoreForm { ...@@ -54,6 +54,7 @@ class FillStoreForm {
public function __construct() { public function __construct() {
$this->store = Store::getInstance(); $this->store = Store::getInstance();
$this->dbIndexData = $this->store->getVar(PARAM_DB_INDEX_DATA, STORE_SIP); $this->dbIndexData = $this->store->getVar(PARAM_DB_INDEX_DATA, STORE_SIP);
if ($this->dbIndexData === false) { if ($this->dbIndexData === false) {
$this->dbIndexData = DB_INDEX_DEFAULT; // Fallback for FORMs which are not called via SIP; $this->dbIndexData = DB_INDEX_DEFAULT; // Fallback for FORMs which are not called via SIP;
...@@ -66,6 +67,13 @@ class FillStoreForm { ...@@ -66,6 +67,13 @@ class FillStoreForm {
} }
$this->feSpecNative = $this->loadFormElementsBasedOnSIP(); $this->feSpecNative = $this->loadFormElementsBasedOnSIP();
$form = $this->store->getVar(SIP_FORM, STORE_SIP, SANITIZE_ALLOW_ALNUMX);
$recordId = $this->store->getVar(SIP_RECORD_ID, STORE_SIP, SANITIZE_ALLOW_DIGIT);
$tableFromFormSql = "SELECT f.tableName FROM Form AS f WHERE f.name=?";
$tableVars = $this->dbArray[$this->dbIndexQfq]->sql($tableFromFormSql,ROW_EXPECT_1, [$form]);
$this->store->fillStoreWithRecord($tableVars[F_TABLE_NAME], $recordId, $this->dbArray[$this->dbIndexData]);
$this->evaluate = new Evaluate($this->store, $this->dbArray[$this->dbIndexData]); $this->evaluate = new Evaluate($this->store, $this->dbArray[$this->dbIndexData]);
} }
......
...@@ -850,6 +850,25 @@ class Store { ...@@ -850,6 +850,25 @@ class Store {
self::setVar(SYSTEM_SHOW_DEBUG_INFO, $value, STORE_SYSTEM); self::setVar(SYSTEM_SHOW_DEBUG_INFO, $value, STORE_SYSTEM);
} }
/**
* Load $recordId from $tableName using $db and saves it in $store.
*
* @param $tableName
* @param $recordId
* @param $db
* @param string $store
* @throws CodeException
* @throws UserFormException
*/
public static function fillStoreWithRecord($tableName, $recordId, $db, $store = STORE_RECORD) {
if ($recordId !== false && $recordId > 0 &&
is_string($tableName) && $tableName !== '') {
$record = $db->sql("SELECT * FROM $tableName WHERE id = ?", ROW_EXPECT_1, [$recordId]);
self::setStore($record, $store, true);
}
}
/** /**
* Read SYSTEM_FILL_STORE_SYSTEM_BY_SQL_1|2|3 from SYSTEM_STORE and if set: * Read SYSTEM_FILL_STORE_SYSTEM_BY_SQL_1|2|3 from SYSTEM_STORE and if set:
* a) fire the SQL * a) fire the SQL
......
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