Commit 116d7be5 authored by Carsten  Rose's avatar Carsten Rose

Implements #9352 - unit tests missing

parent 56054b44
Pipeline #2468 passed with stages
in 2 minutes and 48 seconds
......@@ -762,9 +762,8 @@ abstract class AbstractBuildForm {
$this->store->appendToStore($fe[FE_FILL_STORE_VAR], STORE_VAR);
}
// for Upload FormElements, it's necessary to pre-calculate an optional given 'slaveId'.
if ($fe[FE_TYPE] === FE_TYPE_UPLOAD) {
Support::setIfNotSet($fe, FE_SLAVE_ID);
// If given, slaveId will be copied to STORE_VAR
if (!empty($fe[FE_SLAVE_ID])) {
$this->store->setVar(SYSTEM_FORM_ELEMENT_COLUMN, FE_SLAVE_ID, STORE_SYSTEM); // debug
$slaveId = Support::falseEmptyToZero($this->evaluate->parse($fe[FE_SLAVE_ID]));
$this->store->setVar(VAR_SLAVE_ID, $slaveId, STORE_VAR);
......
......@@ -96,8 +96,9 @@ class Evaluate {
public function parseArray($tokenArray, array $skip = array(), &$debugStack = array()) {
$arr = array();
// In case there is an Element 'fillStoreVar', process that first.
if (!empty($tokenArray[FE_FILL_STORE_VAR]) && is_string($tokenArray[FE_FILL_STORE_VAR])) {
// In case there is an Element 'fillStoreVar', process that first (if not defined to skip).
$flagSkipFillStoreVar = (array_search(FE_FILL_STORE_VAR, $skip) !== false);
if (!$flagSkipFillStoreVar && !empty($tokenArray[FE_FILL_STORE_VAR]) && is_string($tokenArray[FE_FILL_STORE_VAR])) {
$arr = $this->parse($tokenArray[FE_FILL_STORE_VAR], ROW_REGULAR, 0, $debugStack);
if (!empty($arr)) {
......
......@@ -186,25 +186,19 @@ class FormAction {
$this->sqlValidate($fe);
// If given: fire a sqlBefore query
$this->evaluate->parse($fe[FE_SQL_BEFORE]);
if ($fe[FE_TYPE] === FE_TYPE_SENDMAIL) {
$this->doSendMail($fe);
} else {
$rcTmp = $this->doSlave($fe, $recordId);
switch ($rcTmp) {
case ACTION_ELEMENT_MODIFIED:
case ACTION_ELEMENT_DELETED:
$rc = $rcTmp;
break;
default:
break;
}
}
// If given: fire a $sqlAfter query
$this->evaluate->parse($fe[FE_SQL_AFTER]);
$rcTmp = $this->doSqlBeforeSlaveAfter($fe, $recordId, true);
switch ($rcTmp) {
case ACTION_ELEMENT_MODIFIED:
case ACTION_ELEMENT_DELETED:
$rc = $rcTmp;
break;
default:
break;
}
}
return $rc;
......@@ -338,6 +332,7 @@ class FormAction {
* @param array $fe
* @param int $recordId
*
* @param bool $flagFeAction indicates of the FE are of type 'native' or 'action'.
* @return int ACTION_ELEMENT_MODIFIED if there are potential(!) changes on the DB like INSERT / UPDATE,
* ACTION_ELEMENT_NO_CHANGE if nothing happened
* ACTION_ELEMENT_DELETED: if a record has been deleted
......@@ -346,15 +341,18 @@ class FormAction {
* @throws \UserFormException
* @throws \UserReportException
*/
private function doSlave(array $fe, $recordId) {
public function doSqlBeforeSlaveAfter(array $fe, $recordId, $flagFeAction) {
// If given: fire a sqlBefore query
$this->evaluate->parse($fe[FE_SQL_BEFORE]);
$rcStatus = ACTION_ELEMENT_NO_CHANGE;
// Get the slaveId
$slaveId = $this->evaluate->parse($fe[FE_SLAVE_ID]);
if ($slaveId === '' && $fe[FE_NAME] !== '') {
// if the current action element has the same name as a real master record column: take that value as an id
if ($flagFeAction && $slaveId === '' && $fe[FE_NAME] !== '') {
// If the current action element has the same name as a real master record column: take that value as an id.
$slaveId = $this->store->getVar($fe[FE_NAME], STORE_RECORD);
}
......@@ -367,10 +365,9 @@ class FormAction {
$doInsert = ($slaveId == 0);
$doUpdate = ($slaveId != 0);
$doDelete = ($slaveId != 0) && $fe[FE_SQL_DELETE] != '';
$doDelete = ($slaveId != 0) && !empty($fe[FE_SQL_DELETE]);
$flagHonor = isset($fe[FE_SQL_HONOR_FORM_ELEMENTS]) && $fe[FE_SQL_HONOR_FORM_ELEMENTS] != '';
if ($flagHonor) {
if (!empty($fe[FE_SQL_HONOR_FORM_ELEMENTS])) {
$filled = $this->checkFormElements($fe[FE_SQL_HONOR_FORM_ELEMENTS]);
$doInsert = $filled && $doInsert;
$doUpdate = $filled && $doUpdate;
......@@ -398,11 +395,14 @@ class FormAction {
}
// Check if there is a column with the same name as the 'action'-FormElement.
if (false !== $this->store->getVar($fe[FE_NAME], STORE_RECORD)) {
if ($flagFeAction && false !== $this->store->getVar($fe[FE_NAME], STORE_RECORD)) {
// After an insert or update, propagate the (new) slave id to the master record.
$this->db->sql("UPDATE " . $this->primaryTableName . " SET " . $fe[FE_NAME] . " = $slaveId WHERE id = ? LIMIT 1", ROW_REGULAR, [$recordId]);
}
// If given: fire a $sqlAfter query
$this->evaluate->parse($fe[FE_SQL_AFTER]);
return $rcStatus;
}
......
......@@ -50,12 +50,17 @@ class HelperFormElement {
*/
public static function formElementSetDefault(array $elements, array $formSpec) {
$default = [FE_SLAVE_ID => '', FE_SQL_BEFORE => '', FE_SQL_INSERT => '', FE_SQL_UPDATE => '', FE_SQL_DELETE => '', FE_SQL_AFTER => ''];
foreach ($elements AS $key => $element) {
$elements[$key][FE_TG_INDEX] = 0;
unset($elements[$key][FE_ADMIN_NOTE]);
// $elements[$key][FE_DATA_REFERENCE] = '';
$elements[$key] = array_merge($default, $elements[$key]);
}
return $elements;
}
......@@ -81,7 +86,7 @@ class HelperFormElement {
// Check if some of the exploded keys conflict with existing keys
$checkKeys = array_keys($arr);
foreach ($checkKeys AS $checkKey) {
if (isset($element[$checkKey])) {
if (!empty($element[$checkKey])) {
$store = Store::getInstance();
$store->setVar(SYSTEM_FORM_ELEMENT, Logger::formatFormElementName($element), STORE_SYSTEM);
$store->setVar(SYSTEM_FORM_ELEMENT_COLUMN, $keyName, STORE_SYSTEM);
......@@ -293,7 +298,7 @@ class HelperFormElement {
*/
public static function initActionFormElement(array $fe) {
$list = [FE_TYPE, FE_SLAVE_ID, FE_SQL_VALIDATE, FE_SQL_BEFORE, FE_SQL_INSERT, FE_SQL_UPDATE, FE_SQL_DELETE,
$list = [FE_TYPE, FE_SQL_VALIDATE, FE_SLAVE_ID, FE_SQL_BEFORE, FE_SQL_INSERT, FE_SQL_UPDATE, FE_SQL_DELETE,
FE_SQL_AFTER, FE_EXPECT_RECORDS, FE_REQUIRED_LIST, FE_MESSAGE_FAIL, FE_SENDMAIL_TO, FE_SENDMAIL_CC,
FE_SENDMAIL_BCC, FE_SENDMAIL_FROM, FE_SENDMAIL_SUBJECT, FE_SENDMAIL_REPLY_TO, FE_SENDMAIL_FLAG_AUTO_SUBMIT,
FE_SENDMAIL_GR_ID, FE_SENDMAIL_X_ID, FE_SENDMAIL_X_ID2, FE_SENDMAIL_X_ID3, FE_SENDMAIL_BODY_MODE,
......
......@@ -18,6 +18,7 @@ use IMATHUZH\Qfq\Core\Helper\Support;
use IMATHUZH\Qfq\Core\Store\Sip;
use IMATHUZH\Qfq\Core\Store\Store;
use IMATHUZH\Qfq\Core\Store\FillStoreForm;
use IMATHUZH\Qfq\Core\Form\FormAction;
/**
* Class Save
......@@ -29,6 +30,12 @@ class Save {
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 $feSpecNativeRaw = array(); // copy of all formElement.class='native' of the loaded form
/**
* @var FormAction
*/
private $formAction = null;
/**
* @var null|Store
*/
......@@ -58,6 +65,7 @@ class Save {
$this->store = Store::getInstance();
$this->db = new Database($formSpec[F_DB_INDEX]);
$this->evaluate = new Evaluate($this->store, $this->db);
$this->formAction = new FormAction($formSpec, $this->db);
$this->qfqLogFilename = $this->store->getVar(SYSTEM_QFQ_LOG, STORE_SYSTEM);
......@@ -213,8 +221,9 @@ class Save {
*
* @return int record id (in case of insert, it's different from $recordId)
* @throws \CodeException
* @throws \UserFormException
* @throws \DbException
* @throws \UserFormException
* @throws \UserReportException
*/
private function elements($recordId) {
$columnCreated = false;
......@@ -279,16 +288,33 @@ class Save {
$rc = $recordId;
}
$this->nativeDoSlave($rc);
return $rc;
}
/*
* Checks if there is a formElement with name '$feName' of type 'upload'
/**
* @param $recordId
*
* @param $feName
* @return bool
* @throws \CodeException
* @throws \DbException
* @throws \UserFormException
* @throws \UserReportException
*/
private function nativeDoSlave($recordId) {
foreach ($this->feSpecNative as $fe) {
// Preparation for Log, Debug
$this->store->setVar(SYSTEM_FORM_ELEMENT, Logger::formatFormElementName($fe), STORE_SYSTEM);
$this->store->setVar(SYSTEM_FORM_ELEMENT_ID, $fe[FE_ID], STORE_SYSTEM);
$this->formAction->doSqlBeforeSlaveAfter($fe, $recordId, false);
}
}
/**
* Checks if there is a formElement with name '$feName' of type 'upload'
*
* @param $feName
* @return bool
*/
......
......@@ -174,7 +174,7 @@ class FillStoreForm {
public function process($formMode = FORM_SAVE) {
// The following will never be used during load (fe.type='upload').
$skip = [FE_SQL_UPDATE, FE_SQL_INSERT, FE_SQL_DELETE, FE_SQL_AFTER, FE_SQL_BEFORE, FE_PARAMETER];
$skip = [FE_SLAVE_ID, FE_SQL_UPDATE, FE_SQL_INSERT, FE_SQL_DELETE, FE_SQL_AFTER, FE_SQL_BEFORE, FE_PARAMETER, FE_VALUE, FE_FILL_STORE_VAR];
$html = '';
$newValues = array();
......
......@@ -341,6 +341,7 @@ class FormActionTest extends AbstractDatabaseTest {
// get the new slave record
$result = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id, city, personId FROM Address', ROW_IMPLODE_ALL);
$this->assertEquals('1Downtown2', $result);
// get the updated id in the master record
$result = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id, name, adrId FROM Person WHERE id=2', ROW_IMPLODE_ALL);
$this->assertEquals('2Smith1', $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