Commit 324d4549 authored by Carsten  Rose's avatar Carsten Rose

Implements #5695 - fire FillStoreVar for multiForm elments during save

parent c9d81811
Pipeline #2471 passed with stages
in 2 minutes and 40 seconds
......@@ -68,6 +68,33 @@ class FormAction {
}
/**
* @param string $fillStoreVar
* @throws \CodeException
* @throws \DbException
* @throws \UserFormException
* @throws \UserReportException
*/
private function feFillStoreVar($fillStoreVar) {
if ($fillStoreVar != '') {
$this->store->setVar(SYSTEM_FORM_ELEMENT_COLUMN, FE_FILL_STORE_VAR, STORE_SYSTEM); // debug
$rows = $this->evaluate->parse($fillStoreVar, ROW_EXPECT_0_1);
if (is_array($rows)) {
$this->store->appendToStore($rows, STORE_VAR);
} else {
if (!empty($rows)) {
throw new \UserFormException(json_encode(
[ERROR_MESSAGE_TO_USER => "Invalid statement for 'fillStoreVar'.",
ERROR_MESSAGE_TO_DEVELOPER => $fillStoreVar]), ERROR_INVALID_OR_MISSING_PARAMETER);
}
}
}
}
/**
* @param integer $recordId
* @param array $feSpecAction
......@@ -106,20 +133,8 @@ class FormAction {
continue;
}
if (isset($fe[FE_FILL_STORE_VAR])) {
$this->store->setVar(SYSTEM_FORM_ELEMENT_COLUMN, FE_FILL_STORE_VAR, STORE_SYSTEM); // debug
$rows = $this->evaluate->parse($fe[FE_FILL_STORE_VAR], ROW_EXPECT_0_1);
if (is_array($rows)) {
$this->store->appendToStore($rows, STORE_VAR);
} else {
if (!empty($rows)) {
throw new \UserFormException(json_encode(
[ERROR_MESSAGE_TO_USER => "Invalid statement for 'fillStoreVar'.",
ERROR_MESSAGE_TO_DEVELOPER => $fe[FE_FILL_STORE_VAR]]), ERROR_INVALID_OR_MISSING_PARAMETER);
}
}
$fe[FE_FILL_STORE_VAR] = ''; // do not process the same later on.
}
$this->feFillStoreVar($fe[FE_FILL_STORE_VAR] ?? '');
$fe[FE_FILL_STORE_VAR] = ''; // do not process the same later on.
// Process templateGroup action elements
if (isset($fe[FE_ID_CONTAINER]) && $fe[FE_ID_CONTAINER] > 0) {
......@@ -345,6 +360,8 @@ class FormAction {
$rcStatus = ACTION_ELEMENT_NO_CHANGE;
$this->feFillStoreVar($fe[FE_FILL_STORE_VAR] ?? '');
// slaveId might be used in sqlBefore: get it first.
if (isset($fe[FE_SLAVE_ID])) {
// Get the slaveId
......
......@@ -125,8 +125,12 @@ class Save {
$fillStoreForm = new FillStoreForm();
foreach ($parentRecords as $row) {
$row[F_MULTI_COL_ID] = $row[$idName]; // In case '_id' is used, both '_id' and 'id' should be accessible.
$this->store->setStore($row, STORE_PARENT_RECORD, true);
$record = $this->db->sql('SELECT * FROM `' . $this->formSpec[F_TABLE_NAME] . '` WHERE id=' . $row[F_MULTI_COL_ID], ROW_EXPECT_1);
$this->store->setStore($record, STORE_RECORD, true);
// Fake current recordId
$this->store->setVar(SIP_RECORD_ID, $row[$idName], STORE_SIP);
$fillStoreForm->process(FORM_SAVE);
......
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