Commit 15439f12 authored by Carsten  Rose's avatar Carsten Rose

Implements #5695 - respect '{{slaveId:V}}' if it is given.

parent 324d4549
Pipeline #2472 passed with stages
in 2 minutes and 41 seconds
......@@ -4136,10 +4136,14 @@ Parameter: slaveId
Note:
* `{{slaveId}}` can be used in any query of the current *FormElement*.
* `{{slaveId:V}}` can be used in any query of the current *FormElement*.
* If the `action`-*FormElement* name exist as a column in the master record: Update that column *automatically* with the
recent slaveId
* After an INSERT the `last_insert_id()` becomes the *slaveId*).
* After an INSERT the `last_insert_id()` becomes the *{{slaveId:V}}*.
* `fillStoreVar` is fired first, than `slaveId`.
* If `slaveId` is known in `fillStoreVar`, set: `slaveId={{someId:V}}`.
Parameter: sqlBefore / sqlInsert / sqlUpdate / sqlDelete / sqlAfter
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
......
......@@ -69,6 +69,8 @@ class FormAction {
}
/**
* Parse $fillStoreVar and if something is given, add it to STORE_VAR.
*
* @param string $fillStoreVar
* @throws \CodeException
* @throws \DbException
......@@ -378,6 +380,12 @@ class FormAction {
// Store the slaveId: it's used and replaced in the update statement.
$this->store->setVar(VAR_SLAVE_ID, $slaveId, STORE_VAR, true);
} else {
if (false !== ($id = $this->store->getVar(VAR_SLAVE_ID, STORE_VAR))) {
$slaveId = $id;
$fe[FE_SLAVE_ID] = $id;
}
}
// If given: fire a sqlBefore query
......
......@@ -160,11 +160,6 @@ class SaveTest extends AbstractDatabaseTest {
[
FE_ID => 1,
FE_TYPE => FE_TYPE_TEXT,
FE_NAME => 'name',
],
[
FE_ID => 2,
FE_TYPE => FE_TYPE_TEXT,
FE_NAME => 'firstName',
FE_SQL_BEFORE => '{{UPDATE Address SET city=CONCAT(city, "-") WHERE id={{slaveId:V}} }}',
FE_SLAVE_ID => '{{SELECT id FROM Address WHERE street="deleteMe"}}',
......@@ -218,6 +213,40 @@ class SaveTest extends AbstractDatabaseTest {
// Compare
$this->assertEquals('Zurich+- Oerlikon+', $result);
/*
* Check: fillStoreVar['slaveId'] (no explicit fe.slaveId)
*
* slaveId becomes '0', cause there is no Address record 'street="deleteMe"'.
* sqlBefore does nothing, cause there is no Address record 'street="deleteMe"'.
* sqlInsert will create an Address record 'street="deleteMe"'.
* sqlAfter adds '+' after city name.
*/
// fillStoreVar
$feSpecNative = [
[
FE_ID => 1,
FE_TYPE => FE_TYPE_TEXT,
FE_NAME => 'firstName',
FE_FILL_STORE_VAR => '{{!SELECT id AS slaveId FROM Address WHERE street="deleteMe"}}',
FE_SQL_UPDATE => '{{UPDATE Address SET city="Schwamedingen" WHERE id={{slaveId:V}} }}',
]
];
$feSpecNative = HelperFormElement::formElementSetDefault($feSpecNative, $formSpec);
$save = new Save($formSpec, [], $feSpecNative, $feSpecNative);
$save->process();
// Get newly save record
$sql = "SELECT city FROM Address WHERE street like 'deleteMe'";
$result = $this->dbArray[DB_INDEX_DEFAULT]->sql($sql, ROW_IMPLODE_ALL);
// Compare
$this->assertEquals('Schwamedingen', $result);
}
/**
......
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