From deb4999537050972d8743974f3501470d31fcde4 Mon Sep 17 00:00:00 2001 From: Paula Quispe Date: Wed, 9 Aug 2017 12:03:25 -0400 Subject: [PATCH] HOR-2949 --- gulliver/system/class.rbac.php | 7 + .../methods/emailServer/emailServerAjax.php | 2 +- .../BusinessModel/EmailServer.php | 293 +++++++++++++----- 3 files changed, 222 insertions(+), 80 deletions(-) diff --git a/gulliver/system/class.rbac.php b/gulliver/system/class.rbac.php index af9c6b321..253ff34b8 100644 --- a/gulliver/system/class.rbac.php +++ b/gulliver/system/class.rbac.php @@ -165,6 +165,13 @@ class RBAC 'updateCategory' => array('PM_SETUP', 'PM_SETUP_PROCESS_CATEGORIES'), 'canDeleteCategory' => array('PM_SETUP', 'PM_SETUP_PROCESS_CATEGORIES'), 'deleteCategory' => array('PM_SETUP', 'PM_SETUP_PROCESS_CATEGORIES') + ), + 'emailServerAjax.php' => array( + 'INS' => array('PM_SETUP'), + 'UPD' => array('PM_SETUP'), + 'DEL' => array('PM_SETUP'), + 'LST' => array('PM_SETUP'), + 'TEST' => array('PM_SETUP') ) ); } diff --git a/workflow/engine/methods/emailServer/emailServerAjax.php b/workflow/engine/methods/emailServer/emailServerAjax.php index 78dc6c652..6f3c246e3 100644 --- a/workflow/engine/methods/emailServer/emailServerAjax.php +++ b/workflow/engine/methods/emailServer/emailServerAjax.php @@ -1,8 +1,8 @@ allows(basename(__FILE__), $option); switch ($option) { case "INS": $arrayData = array(); diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/EmailServer.php b/workflow/engine/src/ProcessMaker/BusinessModel/EmailServer.php index b3e6d261b..0946e163d 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/EmailServer.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/EmailServer.php @@ -1,5 +1,8 @@ array("type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1), "fieldNameAux" => "emailServerDefault") ); + private $contextLog = array(); + private $formatFieldNameInUppercase = true; private $arrayFieldNameForException = array( @@ -37,17 +42,51 @@ class EmailServer foreach ($this->arrayFieldDefinition as $key => $value) { $this->arrayFieldNameForException[$value["fieldNameAux"]] = $key; } - } catch (\Exception $e) { + + //Define the variables for the logging + global $RBAC; + $currentUser = $RBAC->aUserInfo['USER_INFO']; + $info = array( + 'ip' => G::getIpAddress(), + 'workspace' => (defined("SYS_SYS"))? SYS_SYS : "Workspace undefined", + 'usrUid' => $currentUser['USR_UID'] + ); + $this->setContextLog($info); + + + } catch (Exception $e) { throw $e; } } + /** + * Get the $contextLog value. + * + * @return string + */ + public function getContextLog() + { + return $this->contextLog; + } + + /** + * Set the value of $contextLog. + * + * @param array $k + * @return void + */ + public function setContextLog($k) + { + $this->contextLog = array_merge($this->contextLog, $k); + } + /** * Set the format of the fields name (uppercase, lowercase) * * @param bool $flag Value that set the format * - * return void + * @return void + * @throws Exception */ public function setFormatFieldNameInUppercase($flag) { @@ -55,7 +94,7 @@ class EmailServer $this->formatFieldNameInUppercase = $flag; $this->setArrayFieldNameForException($this->arrayFieldNameForException); - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -65,7 +104,8 @@ class EmailServer * * @param array $arrayData Data with the fields * - * return void + * @return void + * @throws Exception */ public function setArrayFieldNameForException(array $arrayData) { @@ -73,7 +113,7 @@ class EmailServer foreach ($arrayData as $key => $value) { $this->arrayFieldNameForException[$key] = $this->getFieldNameByFormatFieldName($value); } - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -83,13 +123,14 @@ class EmailServer * * @param string $fieldName Field name * - * return string Return the field name according the format + * @return string, return the field name according the format + * @throws Exception */ public function getFieldNameByFormatFieldName($fieldName) { try { return ($this->formatFieldNameInUppercase)? strtoupper($fieldName) : strtolower($fieldName); - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -99,7 +140,8 @@ class EmailServer * * @param array $arrayData Data * - * return array Return array with result of send test mail + * @return array, return array with result of send test mail + * @throws Exception */ public function sendTestMail(array $arrayData) { @@ -117,20 +159,20 @@ class EmailServer "SMTPSecure" => (isset($arrayData["SMTPSecure"]))? $arrayData["SMTPSecure"] : "none" ); - $sFrom = \G::buildFrom($aConfiguration); + $sFrom = G::buildFrom($aConfiguration); - $sSubject = \G::LoadTranslation("ID_MESS_TEST_SUBJECT"); - $msg = \G::LoadTranslation("ID_MESS_TEST_BODY"); + $sSubject = G::LoadTranslation("ID_MESS_TEST_SUBJECT"); + $msg = G::LoadTranslation("ID_MESS_TEST_BODY"); switch ($arrayData["MESS_ENGINE"]) { case "MAIL": - $engine = \G::LoadTranslation("ID_MESS_ENGINE_TYPE_1"); + $engine = G::LoadTranslation("ID_MESS_ENGINE_TYPE_1"); break; case "PHPMAILER": - $engine = \G::LoadTranslation("ID_MESS_ENGINE_TYPE_2"); + $engine = G::LoadTranslation("ID_MESS_ENGINE_TYPE_2"); break; case "OPENMAIL": - $engine = \G::LoadTranslation("ID_MESS_ENGINE_TYPE_3"); + $engine = G::LoadTranslation("ID_MESS_ENGINE_TYPE_3"); break; } @@ -175,7 +217,7 @@ class EmailServer if ($oSpool->status == "sent") { $arrayTestMailResult["status"] = true; $arrayTestMailResult["success"] = true; - $arrayTestMailResult["msg"] = \G::LoadTranslation("ID_MAIL_TEST_SUCCESS"); + $arrayTestMailResult["msg"] = G::LoadTranslation("ID_MAIL_TEST_SUCCESS"); } else { $arrayTestMailResult["status"] = false; $arrayTestMailResult["success"] = false; @@ -183,7 +225,7 @@ class EmailServer } return $arrayTestMailResult; - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -194,7 +236,8 @@ class EmailServer * @param array $arrayData Data * @param int $step Step * - * return array Return array with result of test connection by step + * @return array, return array with result of test connection by step + * @throws Exception */ public function testConnectionByStep(array $arrayData, $step = 0) { @@ -208,7 +251,7 @@ class EmailServer $eregMail = "/^[0-9a-zA-Z]+(?:[._][0-9a-zA-Z]+)*@[0-9a-zA-Z]+(?:[._-][0-9a-zA-Z]+)*\.[0-9a-zA-Z]{2,3}$/"; $arrayDataMail["FROM_EMAIL"] = ($arrayData["MESS_FROM_MAIL"] != "" && preg_match($eregMail, $arrayData["MESS_FROM_MAIL"]))? $arrayData["MESS_FROM_MAIL"] : ""; - $arrayDataMail["FROM_NAME"] = ($arrayData["MESS_FROM_NAME"] != "")? $arrayData["MESS_FROM_NAME"] : \G::LoadTranslation("ID_MESS_TEST_BODY"); + $arrayDataMail["FROM_NAME"] = ($arrayData["MESS_FROM_NAME"] != "")? $arrayData["MESS_FROM_NAME"] : G::LoadTranslation("ID_MESS_TEST_BODY"); $arrayDataMail["MESS_ENGINE"] = "MAIL"; $arrayDataMail["MESS_SERVER"] = "localhost"; $arrayDataMail["MESS_PORT"] = 25; @@ -233,7 +276,7 @@ class EmailServer ); if ($arrayTestMailResult["status"] == false) { - $arrayResult["message"] = \G::LoadTranslation("ID_SENDMAIL_NOT_INSTALLED"); + $arrayResult["message"] = G::LoadTranslation("ID_SENDMAIL_NOT_INSTALLED"); } //Return @@ -252,7 +295,7 @@ class EmailServer $passwdHide = ""; } - $passwdDec = \G::decrypt($passwd,"EMAILENCRYPT"); + $passwdDec = G::decrypt($passwd,"EMAILENCRYPT"); $auxPass = explode("hash:", $passwdDec); if (count($auxPass) > 1) { @@ -378,7 +421,7 @@ class EmailServer $eregMail = "/^[0-9a-zA-Z]+(?:[._][0-9a-zA-Z]+)*@[0-9a-zA-Z]+(?:[._-][0-9a-zA-Z]+)*\.[0-9a-zA-Z]{2,3}$/"; $arrayDataPhpMailer["FROM_EMAIL"] = ($fromMail != "" && preg_match($eregMail, $fromMail))? $fromMail : ""; - $arrayDataPhpMailer["FROM_NAME"] = $arrayData["MESS_FROM_NAME"] != "" ? $arrayData["MESS_FROM_NAME"] : \G::LoadTranslation("ID_MESS_TEST_BODY"); + $arrayDataPhpMailer["FROM_NAME"] = $arrayData["MESS_FROM_NAME"] != "" ? $arrayData["MESS_FROM_NAME"] : G::LoadTranslation("ID_MESS_TEST_BODY"); $arrayDataPhpMailer["MESS_ENGINE"] = "PHPMAILER"; $arrayDataPhpMailer["MESS_SERVER"] = $server; $arrayDataPhpMailer["MESS_PORT"] = $port; @@ -421,7 +464,7 @@ class EmailServer //Return return $arrayResult; - } catch (\Exception $e) { + } catch (Exception $e) { $arrayResult = array(); $arrayResult["result"] = false; @@ -437,7 +480,8 @@ class EmailServer * * @param array $arrayData Data * - * return array Return array with result of test connection + * @return array, return array with result of test connection + * @throws Exception */ public function testConnection(array $arrayData) { @@ -467,11 +511,11 @@ class EmailServer $arrayDataAux["MAIL_TO"] = "admin@processmaker.com"; $arrayResult[$arrayMailTestName[1]] = $this->testConnectionByStep($arrayDataAux); - $arrayResult[$arrayMailTestName[1]]["title"] = \G::LoadTranslation("ID_EMAIL_SERVER_TEST_CONNECTION_VERIFYING_MAIL"); + $arrayResult[$arrayMailTestName[1]]["title"] = G::LoadTranslation("ID_EMAIL_SERVER_TEST_CONNECTION_VERIFYING_MAIL"); if ((int)($arrayData["MESS_TRY_SEND_INMEDIATLY"]) == 1 && $arrayData['MAIL_TO'] != '') { $arrayResult[$arrayMailTestName[2]] = $this->testConnectionByStep($arrayData); - $arrayResult[$arrayMailTestName[2]]["title"] = \G::LoadTranslation("ID_EMAIL_SERVER_TEST_CONNECTION_SENDING_EMAIL", array($arrayData["MAIL_TO"])); + $arrayResult[$arrayMailTestName[2]]["title"] = G::LoadTranslation("ID_EMAIL_SERVER_TEST_CONNECTION_SENDING_EMAIL", array($arrayData["MAIL_TO"])); } break; case "PHPMAILER": @@ -482,19 +526,19 @@ class EmailServer switch ($step) { case 1: - $arrayResult[$arrayPhpMailerTestName[$step]]["title"] = \G::LoadTranslation("ID_EMAIL_SERVER_TEST_CONNECTION_RESOLVING_NAME", array($arrayData["MESS_SERVER"])); + $arrayResult[$arrayPhpMailerTestName[$step]]["title"] = G::LoadTranslation("ID_EMAIL_SERVER_TEST_CONNECTION_RESOLVING_NAME", array($arrayData["MESS_SERVER"])); break; case 2: - $arrayResult[$arrayPhpMailerTestName[$step]]["title"] = \G::LoadTranslation("ID_EMAIL_SERVER_TEST_CONNECTION_CHECK_PORT", array($arrayData["MESS_PORT"])); + $arrayResult[$arrayPhpMailerTestName[$step]]["title"] = G::LoadTranslation("ID_EMAIL_SERVER_TEST_CONNECTION_CHECK_PORT", array($arrayData["MESS_PORT"])); break; case 3: - $arrayResult[$arrayPhpMailerTestName[$step]]["title"] = \G::LoadTranslation("ID_EMAIL_SERVER_TEST_CONNECTION_ESTABLISHING_CON_HOST", array($arrayData["MESS_SERVER"] . ":" . $arrayData["MESS_PORT"])); + $arrayResult[$arrayPhpMailerTestName[$step]]["title"] = G::LoadTranslation("ID_EMAIL_SERVER_TEST_CONNECTION_ESTABLISHING_CON_HOST", array($arrayData["MESS_SERVER"] . ":" . $arrayData["MESS_PORT"])); break; case 4: - $arrayResult[$arrayPhpMailerTestName[$step]]["title"] = \G::LoadTranslation("ID_EMAIL_SERVER_TEST_CONNECTION_LOGIN", array($arrayData["MESS_ACCOUNT"], $arrayData["MESS_SERVER"])); + $arrayResult[$arrayPhpMailerTestName[$step]]["title"] = G::LoadTranslation("ID_EMAIL_SERVER_TEST_CONNECTION_LOGIN", array($arrayData["MESS_ACCOUNT"], $arrayData["MESS_SERVER"])); break; case 5: - $arrayResult[$arrayPhpMailerTestName[$step]]["title"] = \G::LoadTranslation("ID_EMAIL_SERVER_TEST_CONNECTION_SENDING_EMAIL", array($arrayData["MAIL_TO"])); + $arrayResult[$arrayPhpMailerTestName[$step]]["title"] = G::LoadTranslation("ID_EMAIL_SERVER_TEST_CONNECTION_SENDING_EMAIL", array($arrayData["MAIL_TO"])); break; } } @@ -503,7 +547,7 @@ class EmailServer //Result return $arrayResult; - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -513,7 +557,8 @@ class EmailServer * * @param string $emailServerUid Unique id of Email Server * - * return bool Return true if is default Email Server, false otherwise + * @return bool, return true if is default Email Server, false otherwise + * @throws Exception */ public function checkIfIsDefault($emailServerUid) { @@ -530,7 +575,7 @@ class EmailServer } else { return false; } - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -541,7 +586,8 @@ class EmailServer * @param string $emailServerUid Unique id of Email Server * @param array $arrayData Data * - * return void Throw exception if data has an invalid value + * @return void Throw exception if data has an invalid value + * @throws Exception */ public function throwExceptionIfDataIsInvalid($emailServerUid, array $arrayData) { @@ -609,10 +655,10 @@ class EmailServer } if ($msg != "") { - throw new \Exception($msg); + throw new Exception($msg); } } - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -623,7 +669,8 @@ class EmailServer * @param string $emailServerUid Unique id of Email Server * @param string $fieldNameForException Field name for the exception * - * return void Throw exception if does not exist the Email Server in table EMAIL_SERVER + * @return void Throw exception if does not exist the Email Server in table EMAIL_SERVER + * @throws Exception */ public function throwExceptionIfNotExistsEmailServer($emailServerUid, $fieldNameForException) { @@ -631,9 +678,9 @@ class EmailServer $obj = \EmailServerPeer::retrieveByPK($emailServerUid); if (is_null($obj)) { - throw new \Exception(\G::LoadTranslation("ID_EMAIL_SERVER_DOES_NOT_EXIST", array($fieldNameForException, $emailServerUid))); + throw new Exception(G::LoadTranslation("ID_EMAIL_SERVER_DOES_NOT_EXIST", array($fieldNameForException, $emailServerUid))); } - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -644,15 +691,16 @@ class EmailServer * @param string $emailServerUid Unique id of Email Server * @param string $fieldNameForException Field name for the exception * - * return void Throw exception if is default Email Server + * @return void Throw exception if is default Email Server + * @throws Exception */ public function throwExceptionIfIsDefault($emailServerUid, $fieldNameForException) { try { if ($this->checkIfIsDefault($emailServerUid)) { - throw new \Exception(\G::LoadTranslation("ID_EMAIL_SERVER_IS_DEFAULT", array($fieldNameForException, $emailServerUid))); + throw new Exception(G::LoadTranslation("ID_EMAIL_SERVER_IS_DEFAULT", array($fieldNameForException, $emailServerUid))); } - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -662,7 +710,8 @@ class EmailServer * * @param string $emailServerUid Unique id of Email Server * - * return void + * @return void + * @throws Exception */ public function setEmailServerDefaultByUid($emailServerUid) { @@ -703,7 +752,8 @@ class EmailServer * * @param array $arrayData Data * - * return array Return data of the new Email Server created + * @return array, data of the new Email Server created + * @throws Exception */ public function create(array $arrayData) { @@ -729,7 +779,7 @@ class EmailServer $emailServer = new \EmailServer(); $passwd = $arrayData["MESS_PASSWORD"]; - $passwdDec = \G::decrypt($passwd, "EMAILENCRYPT"); + $passwdDec = G::decrypt($passwd, "EMAILENCRYPT"); $auxPass = explode("hash:", $passwdDec); if (count($auxPass) > 1) { @@ -745,7 +795,7 @@ class EmailServer if ($arrayData["MESS_PASSWORD"] != "") { $arrayData["MESS_PASSWORD"] = "hash:" . $arrayData["MESS_PASSWORD"]; - $arrayData["MESS_PASSWORD"] = \G::encrypt($arrayData["MESS_PASSWORD"], "EMAILENCRYPT"); + $arrayData["MESS_PASSWORD"] = G::encrypt($arrayData["MESS_PASSWORD"], "EMAILENCRYPT"); } $emailServer->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME); @@ -765,7 +815,28 @@ class EmailServer $this->setEmailServerDefaultByUid($emailServerUid); } - //Return + //Logging the create action + $info = array( + 'action' => 'Create email server', + 'messUid'=> $emailServerUid, + 'engine'=> $arrayData["MESS_ENGINE"], + 'server' => $arrayData["MESS_SERVER"], + 'port' => $arrayData["MESS_PORT"], + 'requireAuthentication' => $arrayData["MESS_RAUTH"], + 'account' => $arrayData["MESS_ACCOUNT"], + 'senderEmail' => $arrayData["MESS_FROM_MAIL"], + 'senderName' => $arrayData["MESS_FROM_NAME"], + 'useSecureConnection' => $arrayData["SMTPSECURE"], + 'sendTestEmail' => $arrayData["MESS_TRY_SEND_INMEDIATLY"], + 'setAsDefaultConfiguration' => $arrayData["MESS_DEFAULT"] + ); + $this->setContextLog($info); + $this->syslog( + 'CreateEmailServer', + 200, + 'New email server was created', + $this->getContextLog() + ); return $this->getEmailServer($emailServerUid); } else { $msg = ""; @@ -774,14 +845,14 @@ class EmailServer $msg = $msg . (($msg != "")? "\n" : "") . $validationFailure->getMessage(); } - throw new \Exception(\G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED") . (($msg != "")? "\n" . $msg : "")); + throw new Exception(G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED") . (($msg != "")? "\n" . $msg : "")); } - } catch (\Exception $e) { + } catch (Exception $e) { $cnn->rollback(); throw $e; } - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -791,7 +862,8 @@ class EmailServer * * @param array $arrayData Data * - * return array Return data of the new Email Server created + * @return array, return data of the new Email Server created + * @throws Exception */ public function create2(array $arrayData) { @@ -828,14 +900,14 @@ class EmailServer $msg = $msg . (($msg != "")? "\n" : "") . $validationFailure->getMessage(); } - throw new \Exception(\G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED") . (($msg != "")? "\n" . $msg : "")); + throw new Exception(G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED") . (($msg != "")? "\n" . $msg : "")); } - } catch (\Exception $e) { + } catch (Exception $e) { $cnn->rollback(); throw $e; } - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -846,7 +918,8 @@ class EmailServer * @param string $emailServerUid Unique id of Group * @param array $arrayData Data * - * return array Return data of the Email Server updated + * @return array Return data of the Email Server updated + * @throws Exception */ public function update($emailServerUid, $arrayData) { @@ -874,7 +947,7 @@ class EmailServer if (isset($arrayData['MESS_PASSWORD'])) { $passwd = $arrayData['MESS_PASSWORD']; - $passwdDec = \G::decrypt($passwd, 'EMAILENCRYPT'); + $passwdDec = G::decrypt($passwd, 'EMAILENCRYPT'); $auxPass = explode('hash:', $passwdDec); if (count($auxPass) > 1) { @@ -890,7 +963,7 @@ class EmailServer if ($arrayData['MESS_PASSWORD'] != '') { $arrayData['MESS_PASSWORD'] = 'hash:' . $arrayData['MESS_PASSWORD']; - $arrayData['MESS_PASSWORD'] = \G::encrypt($arrayData['MESS_PASSWORD'], 'EMAILENCRYPT'); + $arrayData['MESS_PASSWORD'] = G::encrypt($arrayData['MESS_PASSWORD'], 'EMAILENCRYPT'); } } @@ -912,6 +985,29 @@ class EmailServer $arrayData = array_change_key_case($arrayData, CASE_LOWER); } + //Logging the update action + $info = array( + 'action' => 'Update email server', + 'messUid' => $emailServerUid, + 'engine' => $arrayData["MESS_ENGINE"], + 'server' => $arrayData["MESS_SERVER"], + 'port' => $arrayData["MESS_PORT"], + 'requireAuthentication' => $arrayData["MESS_RAUTH"], + 'account' => $arrayData["MESS_ACCOUNT"], + 'senderEmail' => $arrayData["MESS_FROM_MAIL"], + 'senderName' => $arrayData["MESS_FROM_NAME"], + 'useSecureConnection' => $arrayData["SMTPSECURE"], + 'sendTestEmail' => $arrayData["MESS_TRY_SEND_INMEDIATLY"], + 'setAsDefaultConfiguration' => $arrayData["MESS_DEFAULT"] + ); + $this->setContextLog($info); + $this->syslog( + 'UpdateEmailServer', + 200, + 'The email server was updated', + $this->getContextLog() + ); + return $arrayData; } else { $msg = ""; @@ -920,14 +1016,14 @@ class EmailServer $msg = $msg . (($msg != "")? "\n" : "") . $validationFailure->getMessage(); } - throw new \Exception(\G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED") . (($msg != "")? "\n" . $msg : "")); + throw new Exception(G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED") . (($msg != "")? "\n" . $msg : "")); } - } catch (\Exception $e) { + } catch (Exception $e) { $cnn->rollback(); throw $e; } - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -937,22 +1033,32 @@ class EmailServer * * @param string $emailServerUid Unique id of Email Server * - * return void + * @return void + * @throws Exception */ public function delete($emailServerUid) { try { //Verify data $this->throwExceptionIfNotExistsEmailServer($emailServerUid, $this->arrayFieldNameForException["emailServerUid"]); - $this->throwExceptionIfIsDefault($emailServerUid, $this->arrayFieldNameForException["emailServerUid"]); - $criteria = $this->getEmailServerCriteria(); - $criteria->add(\EmailServerPeer::MESS_UID, $emailServerUid, \Criteria::EQUAL); - \EmailServerPeer::doDelete($criteria); - } catch (\Exception $e) { + + //Logging the delete action + $info = array( + 'action' => 'Delete email server', + 'messUid' => $emailServerUid + ); + $this->setContextLog($info); + $this->syslog( + 'DeleteEmailServer', + 200, + 'The email server was deleted', + $this->getContextLog() + ); + } catch (Exception $e) { throw $e; } } @@ -982,7 +1088,7 @@ class EmailServer $criteria->addSelectColumn(\EmailServerPeer::MESS_DEFAULT); return $criteria; - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -992,7 +1098,8 @@ class EmailServer * * @param array $record Record * - * return array Return an array with data Email Server + * @return array, return an array with data Email Server + * @throws Exception */ public function getEmailServerDataFromRecord(array $record) { @@ -1016,7 +1123,7 @@ class EmailServer $this->getFieldNameByFormatFieldName("MESS_EXECUTE_EVERY") => '', $this->getFieldNameByFormatFieldName("MESS_SEND_MAX") => '' ); - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -1064,7 +1171,7 @@ class EmailServer //Return return $arrayData; - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -1078,7 +1185,8 @@ class EmailServer * @param int $start Start * @param int $limit Limit * - * return array Return an array with all Email Servers + * @return array, return an array with all Email Servers + * @throws Exception */ public function getEmailServers($arrayFilterData = null, $sortField = null, $sortDir = null, $start = null, $limit = null) { @@ -1101,10 +1209,10 @@ class EmailServer if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) && trim($arrayFilterData["filter"]) != "") { $criteria->add( $criteria->getNewCriterion(\EmailServerPeer::MESS_ENGINE, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE)->addOr( - $criteria->getNewCriterion(\EmailServerPeer::MESS_SERVER, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE))->addOr( - $criteria->getNewCriterion(\EmailServerPeer::MESS_ACCOUNT, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE))->addOr( - $criteria->getNewCriterion(\EmailServerPeer::MESS_FROM_NAME, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE))->addOr( - $criteria->getNewCriterion(\EmailServerPeer::SMTPSECURE, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE)) + $criteria->getNewCriterion(\EmailServerPeer::MESS_SERVER, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE))->addOr( + $criteria->getNewCriterion(\EmailServerPeer::MESS_ACCOUNT, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE))->addOr( + $criteria->getNewCriterion(\EmailServerPeer::MESS_FROM_NAME, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE))->addOr( + $criteria->getNewCriterion(\EmailServerPeer::SMTPSECURE, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE)) ); } @@ -1156,7 +1264,7 @@ class EmailServer $row = $rsCriteria->getRow(); $passwd = $row["MESS_PASSWORD"]; - $passwdDec = \G::decrypt($passwd, "EMAILENCRYPT"); + $passwdDec = G::decrypt($passwd, "EMAILENCRYPT"); $auxPass = explode("hash:", $passwdDec); if (count($auxPass) > 1) { @@ -1181,7 +1289,7 @@ class EmailServer "filter" => (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]))? $arrayFilterData["filter"] : "", "data" => $arrayEmailServer ); - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -1192,7 +1300,8 @@ class EmailServer * @param string $emailServerUid Unique id of Email Server * @param bool $flagGetRecord Value that set the getting * - * return array Return an array with data of a Email Server + * @return array, return an array with data of a Email Server + * @throws Exception */ public function getEmailServer($emailServerUid, $flagGetRecord = false) { @@ -1224,7 +1333,7 @@ class EmailServer //Return return (!$flagGetRecord)? $this->getEmailServerDataFromRecord($row) : $row; - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -1246,5 +1355,31 @@ class EmailServer $rsCriteria->next(); return $rsCriteria->getRow(); } + + /** + * Logging information related to the email server + * When the user create, update, delete the email server + * + * @param string $channel + * @param string $level + * @param string $message + * @param array $context + * + * @return void + * @throws Exception + */ + private function syslog( + $channel, + $level, + $message, + $context = array() + ) + { + try { + Bootstrap::registerMonolog($channel, $level, $message, $context, $context['workspace'], 'processmaker.log'); + } catch (Exception $e) { + throw $e; + } + } }