From 3ccef0cf67104632a223e72bc4f06939d379926d Mon Sep 17 00:00:00 2001 From: elvill <elias.villiger@uzh.ch> Date: Thu, 11 Oct 2018 18:19:18 +0200 Subject: [PATCH] F4649 - Add sqlBefore & sqlAfter to sendmail FE - refs #4649, closes #4649 --- extension/Documentation/Manual.rst | 1 + extension/qfq/qfq/form/FormAction.php | 37 ++++++++++++--------------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/extension/Documentation/Manual.rst b/extension/Documentation/Manual.rst index 05f9960d9..dd4def6c1 100644 --- a/extension/Documentation/Manual.rst +++ b/extension/Documentation/Manual.rst @@ -3848,6 +3848,7 @@ Type: sendmail * *sendMailMode* = `<string>` - **html** - if set, the e-mail body will be rendered as html. * *sendMailSubjectHtmlEntity* = `<string>` - **encode|decode|none** - the mail subject will be htmlspecialchar() encoded / decoded (default) or none (untouched). * *sendMailBodyHtmlEntity*= `<string>` - **encode|decode|none** - the mail body will be htmlspecialchar() encoded, decoded (default) or none (untouched). + * *sqlBefore* / *sqlAfter* = `<string>` - can be used like with other action elements (will be fired before/after sending the e-mail). * To use values of the submitted form, use the STORE_FORM. E.g. `{{name:F:allbut}}` * To use the `id` of a new created or already existing primary record, use the STORE_RECORD. E.g. `{{id:R}}`. diff --git a/extension/qfq/qfq/form/FormAction.php b/extension/qfq/qfq/form/FormAction.php index 74bcf745b..1cf4d1a8b 100644 --- a/extension/qfq/qfq/form/FormAction.php +++ b/extension/qfq/qfq/form/FormAction.php @@ -174,23 +174,27 @@ class FormAction { $this->store->setStore($arr, STORE_LDAP, true); } + // If given: fire a sqlBefore query + $this->evaluate->parse($fe[FE_SQL_BEFORE]); + if ($fe[FE_TYPE] === FE_TYPE_SENDMAIL) { $this->doSendMail($fe); - //no further processing of current element necessary. - continue; + } else { + $this->validate($fe); + + $rcTmp = $this->doSlave($fe, $recordId); + switch ($rcTmp) { + case ACTION_ELEMENT_MODIFIED: + case ACTION_ELEMENT_DELETED: + $rc = $rcTmp; + break; + default: + break; + } } - $this->validate($fe); - - $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]); } return $rc; @@ -327,7 +331,6 @@ class FormAction { * @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 - * $sqlAfter won't affect the $rc. * @throws CodeException * @throws DbException * @throws UserFormException @@ -352,9 +355,6 @@ class FormAction { // Store the slaveId: it's used and replaced in the update statement. $this->store->setVar(VAR_SLAVE_ID, $slaveId, STORE_VAR, true); - // If given: fire a sqlBefore query - $this->evaluate->parse($fe[FE_SQL_BEFORE]); - $doInsert = ($slaveId == 0); $doUpdate = ($slaveId != 0); $doDelete = ($slaveId != 0) && $fe[FE_SQL_DELETE] != ''; @@ -393,9 +393,6 @@ class FormAction { $this->db->sql("UPDATE " . $this->primaryTableName . " SET " . $fe[FE_NAME] . " = $slaveId WHERE id = ? LIMIT 1", ROW_REGULAR, [$recordId]); } - // If given: fire a $sqlAfter query. $sqlAfter won't affect $rc - $this->evaluate->parse($fe[FE_SQL_AFTER]); - return $rcStatus; } -- GitLab