HOR-4411
This commit is contained in:
committed by
Paula Quispe
parent
4e6fda2e6c
commit
f3800fdef5
@@ -1,48 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\BusinessModel;
|
||||
|
||||
use BasePeer;
|
||||
use Bootstrap;
|
||||
use Criteria;
|
||||
use EmailEvent as ModelEmailEvent;
|
||||
use EmailEventPeer;
|
||||
use EmailServerPeer;
|
||||
use Exception;
|
||||
use G;
|
||||
use ProcessMaker\Util\Common;
|
||||
use Propel;
|
||||
use ResultSet;
|
||||
use UsersPeer;
|
||||
|
||||
class EmailEvent
|
||||
{
|
||||
/*private $arrayFieldDefinition = array(
|
||||
"EMAIL_EVENT_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "emailEventUid"),
|
||||
"PRJ_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "projectUid"),
|
||||
"EVN_UID" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "eventUid"),
|
||||
"EMAIL_EVENT_FROM" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "messageTypeUid"),
|
||||
"EMAIL_EVENT_TO" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "EmailEventUserUid"),
|
||||
"EMAIL_EVENT_SUBJECT" => array("type" => "array", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "EmailEventVariables"),
|
||||
"PRF_UID" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "EmailEventCorrelation")
|
||||
);
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get the email accounts of the current workspace
|
||||
*
|
||||
* return array
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getEmailEventAccounts()
|
||||
{
|
||||
try {
|
||||
$criteria = new \Criteria("workflow");
|
||||
$criteria = new Criteria('workflow');
|
||||
$criteria->clearSelectColumns();
|
||||
$criteria->addSelectColumn(\UsersPeer::USR_UID);
|
||||
$criteria->addSelectColumn(\UsersPeer::USR_EMAIL);
|
||||
$criteria->addSelectColumn(UsersPeer::USR_UID);
|
||||
$criteria->addSelectColumn(UsersPeer::USR_EMAIL);
|
||||
$criteria->addAsColumn('UID', 'USR_UID');
|
||||
$criteria->addAsColumn('EMAIL', 'USR_EMAIL');
|
||||
$criteria->add(\UsersPeer::USR_STATUS, "ACTIVE");
|
||||
$result = \UsersPeer::doSelectRS($criteria);
|
||||
$result->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$result->next();
|
||||
$accountsArray = array();
|
||||
while ($aRow = $result->getRow()) {
|
||||
if (($aRow['USR_EMAIL'] != null) || ($aRow['USR_EMAIL'] != "")) {
|
||||
$accountsArray[] = array_change_key_case($aRow, CASE_LOWER);
|
||||
$criteria->add(UsersPeer::USR_STATUS, 'ACTIVE');
|
||||
$result = UsersPeer::doSelectRS($criteria);
|
||||
$result->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||
$accounts = [];
|
||||
while ($result->next()) {
|
||||
$row = $result->getRow();
|
||||
if (!empty($row['USR_EMAIL'])) {
|
||||
$accounts[] = array_change_key_case($row, CASE_LOWER);
|
||||
}
|
||||
$result->next();
|
||||
}
|
||||
return $accountsArray;
|
||||
} catch (\Exception $e) {
|
||||
return $accounts;
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
@@ -50,101 +51,116 @@ class EmailEvent
|
||||
/**
|
||||
* Get the email server accounts of the current workspace
|
||||
*
|
||||
* return array
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getEmailEventServerAccounts()
|
||||
{
|
||||
try {
|
||||
$criteria = new \Criteria("workflow");
|
||||
$criteria = new Criteria('workflow');
|
||||
$criteria->clearSelectColumns();
|
||||
$criteria->addSelectColumn(\EmailServerPeer::MESS_UID);
|
||||
$criteria->addSelectColumn(\EmailServerPeer::MESS_FROM_MAIL);
|
||||
$criteria->addSelectColumn(\EmailServerPeer::MESS_ACCOUNT);
|
||||
$criteria->addSelectColumn(EmailServerPeer::MESS_UID);
|
||||
$criteria->addSelectColumn(EmailServerPeer::MESS_FROM_MAIL);
|
||||
$criteria->addSelectColumn(EmailServerPeer::MESS_ACCOUNT);
|
||||
$criteria->addSelectColumn(EmailServerPeer::MESS_ENGINE);
|
||||
$criteria->addAsColumn('UID', 'MESS_UID');
|
||||
$result = \EmailServerPeer::doSelectRS($criteria);
|
||||
$result->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$result->next();
|
||||
$accountsArray = array();
|
||||
while ($aRow = $result->getRow()) {
|
||||
if ($aRow['MESS_UID'] != null) {
|
||||
$aRow['EMAIL'] = $aRow['MESS_ACCOUNT'];
|
||||
if($aRow['EMAIL'] != "") {
|
||||
$accountsArray[] = array_change_key_case($aRow, CASE_LOWER);
|
||||
$result = EmailServerPeer::doSelectRS($criteria);
|
||||
$result->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||
$accounts = [];
|
||||
while ($result->next()) {
|
||||
$row = $result->getRow();
|
||||
if (!empty($row['MESS_UID'])) {
|
||||
$row['EMAIL'] = $row['MESS_ACCOUNT'];
|
||||
|
||||
if (empty($row['EMAIL']) && $row['MESS_ENGINE'] === 'MAIL') {
|
||||
$row['MESS_ACCOUNT'] = $row['EMAIL'] = 'Mail (PHP)';
|
||||
}
|
||||
$row['MESS_LABEL'] = $row['MESS_FROM_MAIL'];
|
||||
if (empty($row['MESS_FROM_MAIL'])) {
|
||||
$row['MESS_LABEL'] = $row['MESS_ACCOUNT'];
|
||||
}
|
||||
$accounts[] = array_change_key_case($row, CASE_LOWER);
|
||||
}
|
||||
$result->next();
|
||||
}
|
||||
return $accountsArray;
|
||||
} catch (\Exception $e) {
|
||||
return $accounts;
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Email-Event data
|
||||
* @var string $evn_uid. uid for activity
|
||||
* @var string $pro_uid. uid for process
|
||||
* return array
|
||||
*
|
||||
* @var string $evn_uid . uid for activity
|
||||
* @var string $pro_uid . uid for process
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getEmailEventData($pro_uid, $evn_uid)
|
||||
{
|
||||
try {
|
||||
//Get data
|
||||
$criteria = $this->getEmailEventCriteria();
|
||||
$criteria->add(\EmailEventPeer::EVN_UID, $evn_uid, \Criteria::EQUAL);
|
||||
$criteria->add(\EmailEventPeer::PRJ_UID, $pro_uid, \Criteria::EQUAL);
|
||||
$rsCriteria = \EmailEventPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$criteria->add(EmailEventPeer::EVN_UID, $evn_uid, Criteria::EQUAL);
|
||||
$criteria->add(EmailEventPeer::PRJ_UID, $pro_uid, Criteria::EQUAL);
|
||||
$rsCriteria = EmailEventPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||
$rsCriteria->next();
|
||||
$row = $rsCriteria->getRow();
|
||||
if(is_array($row)) {
|
||||
if ($row) {
|
||||
$row = array_change_key_case($row, CASE_LOWER);
|
||||
}
|
||||
return $row;
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Email-Event data
|
||||
* @var string $emailEventUid. uid for email event
|
||||
* @var string $pro_uid. uid for process
|
||||
* return array
|
||||
*
|
||||
* @var string $emailEventUid . uid for email event
|
||||
* @var string $pro_uid . uid for process
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getEmailEventDataByUid($pro_uid, $emailEventUid)
|
||||
{
|
||||
try {
|
||||
//Get data
|
||||
$criteria = $this->getEmailEventCriteria();
|
||||
$criteria->add(\EmailEventPeer::EMAIL_EVENT_UID, $emailEventUid, \Criteria::EQUAL);
|
||||
$criteria->add(\EmailEventPeer::PRJ_UID, $pro_uid, \Criteria::EQUAL);
|
||||
$rsCriteria = \EmailEventPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$criteria->add(EmailEventPeer::EMAIL_EVENT_UID, $emailEventUid, Criteria::EQUAL);
|
||||
$criteria->add(EmailEventPeer::PRJ_UID, $pro_uid, Criteria::EQUAL);
|
||||
$rsCriteria = EmailEventPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||
$rsCriteria->next();
|
||||
$row = $rsCriteria->getRow();
|
||||
if(is_array($row)) {
|
||||
if ($row) {
|
||||
$row = array_change_key_case($row, CASE_LOWER);
|
||||
}
|
||||
return $row;
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save Data for Email-Event
|
||||
* @var string $prj_uid. Uid for Process
|
||||
* @var string $arrayData. Data for Trigger
|
||||
*
|
||||
* return array
|
||||
* @var string $prj_uid . Uid for Process
|
||||
* @var string $arrayData . Data for Trigger
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function save($prj_uid = '', $arrayData = array())
|
||||
public function save($prj_uid = '', $arrayData = [])
|
||||
{
|
||||
try {
|
||||
//Verify data
|
||||
$process = new \ProcessMaker\BusinessModel\Process();
|
||||
$validator = new \ProcessMaker\BusinessModel\Validator();
|
||||
$process = new Process();
|
||||
$validator = new Validator();
|
||||
|
||||
$validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");
|
||||
$validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
|
||||
@@ -153,17 +169,17 @@ class EmailEvent
|
||||
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
|
||||
|
||||
//Verify data
|
||||
$process->throwExceptionIfNotExistsProcess($prj_uid, "projectUid");
|
||||
$process->throwExceptionIfNotExistsProcess($prj_uid, 'projectUid');
|
||||
|
||||
//Create
|
||||
$db = \Propel::getConnection("workflow");
|
||||
$db = Propel::getConnection('workflow');
|
||||
|
||||
try {
|
||||
$emailEvent = new \EmailEvent();
|
||||
$emailEvent = new ModelEmailEvent();
|
||||
|
||||
$emailEvent->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
|
||||
$emailEvent->fromArray($arrayData, BasePeer::TYPE_FIELDNAME);
|
||||
|
||||
$emailEventUid = \ProcessMaker\Util\Common::generateUID();
|
||||
$emailEventUid = Common::generateUID();
|
||||
|
||||
$emailEvent->setEmailEventUid($emailEventUid);
|
||||
$emailEvent->setPrjUid($prj_uid);
|
||||
@@ -173,11 +189,11 @@ class EmailEvent
|
||||
$db->commit();
|
||||
|
||||
return $this->getEmailEvent($emailEventUid);
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
$db->rollback();
|
||||
throw $e;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
@@ -186,15 +202,16 @@ class EmailEvent
|
||||
* Update Email-Event
|
||||
*
|
||||
* @param string $emailEventUid Unique id of Email-Event
|
||||
* @param array $arrayData Data
|
||||
* @param array $arrayData Data
|
||||
*
|
||||
* return array Return data of the Email-Event updated
|
||||
* @return array Return data of the Email-Event updated
|
||||
* @throws Exception
|
||||
*/
|
||||
public function update($emailEventUid, array $arrayData)
|
||||
{
|
||||
try {
|
||||
//Verify data
|
||||
$validator = new \ProcessMaker\BusinessModel\Validator();
|
||||
$validator = new Validator();
|
||||
|
||||
$validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");
|
||||
$validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
|
||||
@@ -210,11 +227,11 @@ class EmailEvent
|
||||
$this->verifyIfEmailEventExists($emailEventUid);
|
||||
|
||||
//Update
|
||||
$db = \Propel::getConnection("workflow");
|
||||
$db = Propel::getConnection('workflow');
|
||||
|
||||
try {
|
||||
$emailEvent = \EmailEventPeer::retrieveByPK($emailEventUid);
|
||||
$emailEvent->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
|
||||
$emailEvent = EmailEventPeer::retrieveByPK($emailEventUid);
|
||||
$emailEvent->fromArray($arrayData, BasePeer::TYPE_FIELDNAME);
|
||||
|
||||
$db->begin();
|
||||
$result = $emailEvent->save();
|
||||
@@ -223,13 +240,12 @@ class EmailEvent
|
||||
$arrayData = $arrayDataBackup;
|
||||
$arrayData = array_change_key_case($arrayData, CASE_LOWER);
|
||||
return $arrayData;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$cnn->rollback();
|
||||
} catch (Exception $e) {
|
||||
$db->rollback();
|
||||
|
||||
throw $e;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
@@ -237,11 +253,14 @@ class EmailEvent
|
||||
/**
|
||||
* Delete Email-Event
|
||||
*
|
||||
* @param string $pro_uid
|
||||
* @param string $emailEventUid Unique id of Email-Event
|
||||
* @param boolean $passValidation
|
||||
* @param boolean $verifyRelation
|
||||
*
|
||||
* return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function delete($pro_uid, $emailEventUid, $passValidation = true)
|
||||
public function delete($pro_uid, $emailEventUid, $passValidation = true, $verifyRelation = true)
|
||||
{
|
||||
try {
|
||||
//Verify data
|
||||
@@ -249,20 +268,19 @@ class EmailEvent
|
||||
$this->verifyIfEmailEventExists($emailEventUid);
|
||||
|
||||
//Delete file
|
||||
$filesManager = new \ProcessMaker\BusinessModel\FilesManager();
|
||||
$filesManager = new FilesManager();
|
||||
$arrayData = $this->getEmailEventDataByUid($pro_uid, $emailEventUid);
|
||||
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
|
||||
if (sizeof($arrayData)) {
|
||||
if ($arrayData) {
|
||||
$prfUid = $arrayData['PRF_UID'];
|
||||
$filesManager->deleteProcessFilesManager($pro_uid, $prfUid, true);
|
||||
$filesManager->deleteProcessFilesManager($pro_uid, $prfUid, $verifyRelation);
|
||||
}
|
||||
}
|
||||
//Delete Email event
|
||||
$criteria = new \Criteria("workflow");
|
||||
$criteria->add(\EmailEventPeer::EMAIL_EVENT_UID, $emailEventUid, \Criteria::EQUAL);
|
||||
$result = \EmailEventPeer::doDelete($criteria);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$criteria = new Criteria('workflow');
|
||||
$criteria->add(EmailEventPeer::EMAIL_EVENT_UID, $emailEventUid, Criteria::EQUAL);
|
||||
$result = EmailEventPeer::doDelete($criteria);
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
@@ -270,21 +288,21 @@ class EmailEvent
|
||||
/**
|
||||
* Delete Email-Event by event uid
|
||||
*
|
||||
* @param string $emailEventUid Unique id of Email-Event
|
||||
* @param string $prj_uid Unique id of Process
|
||||
* @param string $evn_uid Unique id of Email-Event
|
||||
*
|
||||
* return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function deleteByEvent($prj_uid, $evn_uid)
|
||||
{
|
||||
try {
|
||||
//Verify data
|
||||
if (!$this->existsEvent($prj_uid, $evn_uid)) {
|
||||
throw new \Exception(G::LoadTranslation("ID_EMAIL_EVENT_DEFINITION_DOES_NOT_EXIST"));
|
||||
throw new Exception(G::LoadTranslation('ID_EMAIL_EVENT_DEFINITION_DOES_NOT_EXIST'));
|
||||
}
|
||||
$arrayData = $this->existsEvent($prj_uid, $evn_uid);
|
||||
$this->delete($prj_uid, $arrayData[0]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
@@ -293,27 +311,25 @@ class EmailEvent
|
||||
* Get data of a Email-Event
|
||||
*
|
||||
* @param string $emailEventUid Unique id of Email-Event
|
||||
* @param bool $flagGetRecord Value that set the getting
|
||||
*
|
||||
* return array Return an array with data of a Email-Event
|
||||
* @return array Return an array with data of a Email-Event
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getEmailEvent($emailEventUid)
|
||||
{
|
||||
try {
|
||||
//Verify data
|
||||
$this->verifyIfEmailEventExists($emailEventUid);
|
||||
$this->verifyIfEmailEventExists($emailEventUid);
|
||||
|
||||
//Get data
|
||||
$criteria = $this->getEmailEventCriteria();
|
||||
$criteria->add(\EmailEventPeer::EMAIL_EVENT_UID, $emailEventUid, \Criteria::EQUAL);
|
||||
$rsCriteria = \EmailEventPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$criteria->add(EmailEventPeer::EMAIL_EVENT_UID, $emailEventUid, Criteria::EQUAL);
|
||||
$rsCriteria = EmailEventPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||
$rsCriteria->next();
|
||||
$row = $rsCriteria->getRow();
|
||||
|
||||
//Return
|
||||
return $row;
|
||||
} catch (\Exception $e) {
|
||||
return $row ? $row : [];
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
@@ -323,15 +339,16 @@ class EmailEvent
|
||||
*
|
||||
* @param string $emailEventUid Unique id of Email-Event
|
||||
*
|
||||
* return bool Return true if exists the Email-Event, false otherwise
|
||||
* @return bool Return true if exists the Email-Event, false otherwise
|
||||
* @throws Exception
|
||||
*/
|
||||
public function exists($emailEventUid)
|
||||
{
|
||||
try {
|
||||
$obj = \EmailEventPeer::retrieveByPK($emailEventUid);
|
||||
$obj = EmailEventPeer::retrieveByPK($emailEventUid);
|
||||
|
||||
return (!is_null($obj))? true : false;
|
||||
} catch (\Exception $e) {
|
||||
return $obj ? true : false;
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
@@ -339,82 +356,92 @@ class EmailEvent
|
||||
/**
|
||||
* Get criteria for Email-Event
|
||||
*
|
||||
* return object
|
||||
* @return Criteria
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getEmailEventCriteria()
|
||||
{
|
||||
try {
|
||||
$criteria = new \Criteria("workflow");
|
||||
$criteria = new Criteria('workflow');
|
||||
|
||||
$criteria->addSelectColumn(\EmailEventPeer::EMAIL_EVENT_UID);
|
||||
$criteria->addSelectColumn(\EmailEventPeer::PRJ_UID);
|
||||
$criteria->addSelectColumn(\EmailEventPeer::EVN_UID);
|
||||
$criteria->addSelectColumn(\EmailEventPeer::EMAIL_EVENT_FROM);
|
||||
$criteria->addSelectColumn(\EmailEventPeer::EMAIL_EVENT_TO);
|
||||
$criteria->addSelectColumn(\EmailEventPeer::EMAIL_EVENT_SUBJECT);
|
||||
$criteria->addSelectColumn(\EmailEventPeer::PRF_UID);
|
||||
$criteria->addSelectColumn(\EmailEventPeer::EMAIL_SERVER_UID);
|
||||
$criteria->addSelectColumn(EmailEventPeer::EMAIL_EVENT_UID);
|
||||
$criteria->addSelectColumn(EmailEventPeer::PRJ_UID);
|
||||
$criteria->addSelectColumn(EmailEventPeer::EVN_UID);
|
||||
$criteria->addSelectColumn(EmailEventPeer::EMAIL_EVENT_FROM);
|
||||
$criteria->addSelectColumn(EmailEventPeer::EMAIL_EVENT_TO);
|
||||
$criteria->addSelectColumn(EmailEventPeer::EMAIL_EVENT_SUBJECT);
|
||||
$criteria->addSelectColumn(EmailEventPeer::PRF_UID);
|
||||
$criteria->addSelectColumn(EmailEventPeer::EMAIL_SERVER_UID);
|
||||
|
||||
return $criteria;
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Criteria
|
||||
* @throws \Exception
|
||||
* Get Criteria for Email Event when Server Uid is empty
|
||||
*
|
||||
* @return Criteria
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getEmailEventCriteriaEmailServer()
|
||||
{
|
||||
try {
|
||||
$criteria = new \Criteria("workflow");
|
||||
$criteria = new Criteria('workflow');
|
||||
|
||||
$criteria->addSelectColumn(\EmailEventPeer::EMAIL_EVENT_UID);
|
||||
$criteria->addSelectColumn(\EmailEventPeer::PRJ_UID);
|
||||
$criteria->addSelectColumn(\EmailEventPeer::EVN_UID);
|
||||
$criteria->addSelectColumn(\EmailEventPeer::EMAIL_EVENT_FROM);
|
||||
$criteria->addSelectColumn(\EmailEventPeer::EMAIL_EVENT_TO);
|
||||
$criteria->addSelectColumn(\EmailEventPeer::EMAIL_EVENT_SUBJECT);
|
||||
$criteria->addSelectColumn(\EmailEventPeer::PRF_UID);
|
||||
$criteria->addSelectColumn(\EmailEventPeer::EMAIL_SERVER_UID);
|
||||
$criteria->add(\EmailEventPeer::EMAIL_SERVER_UID, '',\Criteria::EQUAL);
|
||||
$criteria->addSelectColumn(EmailEventPeer::EMAIL_EVENT_UID);
|
||||
$criteria->addSelectColumn(EmailEventPeer::PRJ_UID);
|
||||
$criteria->addSelectColumn(EmailEventPeer::EVN_UID);
|
||||
$criteria->addSelectColumn(EmailEventPeer::EMAIL_EVENT_FROM);
|
||||
$criteria->addSelectColumn(EmailEventPeer::EMAIL_EVENT_TO);
|
||||
$criteria->addSelectColumn(EmailEventPeer::EMAIL_EVENT_SUBJECT);
|
||||
$criteria->addSelectColumn(EmailEventPeer::PRF_UID);
|
||||
$criteria->addSelectColumn(EmailEventPeer::EMAIL_SERVER_UID);
|
||||
$criteria->add(EmailEventPeer::EMAIL_SERVER_UID, '', Criteria::EQUAL);
|
||||
|
||||
return $criteria;
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if email Event exists
|
||||
*
|
||||
* @param $emailEventUid
|
||||
* @throws Exception
|
||||
*/
|
||||
public function verifyIfEmailEventExists($emailEventUid)
|
||||
{
|
||||
if (!$this->exists($emailEventUid)) {
|
||||
throw new \Exception(G::LoadTranslation("ID_EMAIL_EVENT_DEFINITION_DOES_NOT_EXIST", array("Email Event Uid", $emailEventUid)));
|
||||
throw new Exception(G::LoadTranslation('ID_EMAIL_EVENT_DEFINITION_DOES_NOT_EXIST', ['Email Event Uid', $emailEventUid]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if exists the Event of a Message-Event-Definition
|
||||
*
|
||||
* @param string $projectUid Unique id of Project
|
||||
* @param string $eventUid Unique id of Event
|
||||
* @param string $projectUid Unique id of Project
|
||||
* @param string $eventUid Unique id of Event
|
||||
*
|
||||
* return bool Return true if exists the Event of a Message-Event-Definition, false otherwise
|
||||
* @return bool Return true if exists the Event of a Message-Event-Definition, false otherwise
|
||||
* @throws Exception
|
||||
*/
|
||||
public function existsEvent($projectUid, $eventUid)
|
||||
{
|
||||
try {
|
||||
$criteria = $this->getEmailEventCriteria();
|
||||
$criteria->add(\EmailEventPeer::PRJ_UID, $projectUid, \Criteria::EQUAL);
|
||||
$criteria->add(\EmailEventPeer::EVN_UID, $eventUid, \Criteria::EQUAL);
|
||||
$rsCriteria = \EmailEventPeer::doSelectRS($criteria);
|
||||
$criteria->add(EmailEventPeer::PRJ_UID, $projectUid, Criteria::EQUAL);
|
||||
$criteria->add(EmailEventPeer::EVN_UID, $eventUid, Criteria::EQUAL);
|
||||
$rsCriteria = EmailEventPeer::doSelectRS($criteria);
|
||||
$rsCriteria->next();
|
||||
$row = $rsCriteria->getRow();
|
||||
if(is_array($row)) {
|
||||
$row = array_change_key_case($row, CASE_LOWER);
|
||||
if ($row) {
|
||||
return array_change_key_case($row, CASE_LOWER);
|
||||
}
|
||||
return (sizeof($row))? $row : false;
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
@@ -422,31 +449,32 @@ class EmailEvent
|
||||
/**
|
||||
* Email-event do function
|
||||
*
|
||||
* @param string $appUID Unique id of application
|
||||
* @param string $prj_uid Unique id of Project
|
||||
* @param string $eventUid Unique id of event
|
||||
* @param array $arrayApplicationData Case data
|
||||
* @param string $appUID Unique id of application
|
||||
* @param string $prj_uid Unique id of Project
|
||||
* @param string $eventUid Unique id of event
|
||||
* @param array $arrayApplicationData Case data
|
||||
*
|
||||
* return void
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function sendEmail($appUID, $prj_uid, $eventUid, $arrayApplicationData)
|
||||
{
|
||||
if (!$this->existsEvent($prj_uid, $eventUid)) {
|
||||
throw new \Exception(G::LoadTranslation("ID_EMAIL_EVENT_DEFINITION_DOES_NOT_EXIST"));
|
||||
throw new Exception(G::LoadTranslation('ID_EMAIL_EVENT_DEFINITION_DOES_NOT_EXIST'));
|
||||
}
|
||||
$arrayData = $this->existsEvent($prj_uid, $eventUid);
|
||||
if (sizeof($arrayData)) {
|
||||
$oEmailServer = new EmailServer();
|
||||
$configEmailData = $oEmailServer->getEmailServer($arrayData[7]);
|
||||
$emailGroupTo = array();
|
||||
$emailTo = "";
|
||||
$emailGroupTo = [];
|
||||
$emailTo = '';
|
||||
$prfUid = $arrayData[6];
|
||||
$filesManager = new \ProcessMaker\BusinessModel\FilesManager();
|
||||
$filesManager = new FilesManager();
|
||||
$contentFile = $filesManager->getProcessFileManager($prj_uid, $prfUid);
|
||||
if (strpos($arrayData[4], ",")) {
|
||||
$emailsArray = explode(",", $arrayData[4]);
|
||||
if (strpos($arrayData[4], ',')) {
|
||||
$emailsArray = explode(',', $arrayData[4]);
|
||||
foreach ($emailsArray as $email) {
|
||||
if (substr($email, 0, 1) == "@") {
|
||||
if (substr($email, 0, 1) === '@') {
|
||||
$email = substr($email, 2, strlen($email));
|
||||
if (isset($arrayApplicationData['APP_DATA'])) {
|
||||
if (is_array($arrayApplicationData['APP_DATA']) && isset($arrayApplicationData['APP_DATA'][$email])) {
|
||||
@@ -457,10 +485,10 @@ class EmailEvent
|
||||
$emailGroupTo[] = $email;
|
||||
}
|
||||
}
|
||||
$emailTo = implode(",", array_unique(array_filter($emailGroupTo)));
|
||||
$emailTo = implode(',', array_unique(array_filter($emailGroupTo)));
|
||||
} else {
|
||||
$email = $arrayData[4];
|
||||
if (substr($email, 0, 1) == "@") {
|
||||
if (substr($email, 0, 1) === '@') {
|
||||
$email = substr($email, 2, strlen($email));
|
||||
if (isset($arrayApplicationData['APP_DATA'])) {
|
||||
if (is_array($arrayApplicationData['APP_DATA']) && isset($arrayApplicationData['APP_DATA'][$email])) {
|
||||
@@ -472,12 +500,28 @@ class EmailEvent
|
||||
}
|
||||
}
|
||||
if (!empty($emailTo)) {
|
||||
$subject = $arrayData[5];
|
||||
$subject = G::replaceDataField($arrayData[5], $arrayApplicationData['APP_DATA']);
|
||||
PMFSendMessage($appUID, G::buildFrom($configEmailData), $emailTo, '', '', $subject,
|
||||
$contentFile['prf_filename'], array(), array(), true, 0, $configEmailData);
|
||||
PMFSendMessage(
|
||||
$appUID,
|
||||
G::buildFrom($configEmailData),
|
||||
$emailTo,
|
||||
'',
|
||||
'',
|
||||
G::replaceDataField($arrayData[5], $arrayApplicationData['APP_DATA']),
|
||||
$contentFile['prf_filename'],
|
||||
[],
|
||||
[],
|
||||
true,
|
||||
0,
|
||||
$configEmailData
|
||||
);
|
||||
} else {
|
||||
\Bootstrap::registerMonolog('EmailEventMailError', 200, G::LoadTranslation('ID_EMAIL_EVENT_CONFIGURATION_EMAIL', array($eventUid, $prj_uid)), ['eventUid' => $eventUid, 'prj_uid' => $prj_uid], config("system.workspace"), 'processmaker.log');
|
||||
Bootstrap::registerMonolog(
|
||||
'EmailEventMailError',
|
||||
200,
|
||||
G::LoadTranslation('ID_EMAIL_EVENT_CONFIGURATION_EMAIL', [$eventUid, $prj_uid]),
|
||||
['eventUid' => $eventUid, 'prj_uid' => $prj_uid],
|
||||
config('system.workspace'),
|
||||
'processmaker.log');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -485,22 +529,22 @@ class EmailEvent
|
||||
/**
|
||||
* Update process file Uid
|
||||
*
|
||||
* @param string $oldUid Unique id of old process file
|
||||
* @param string $newUid Unique id of new process file
|
||||
* @param string $projectUid Unique id of Project
|
||||
* @param string $oldUid Unique id of old process file
|
||||
* @param string $newUid Unique id of new process file
|
||||
* @param string $projectUid Unique id of Project
|
||||
*
|
||||
* return bool Return array if exists, false otherwise
|
||||
* @throws Exception
|
||||
*/
|
||||
public function updatePrfUid($oldUid, $newUid, $projectUid) {
|
||||
public function updatePrfUid($oldUid, $newUid, $projectUid)
|
||||
{
|
||||
try {
|
||||
$newValues = array();
|
||||
$newValues = [];
|
||||
$rowData = $this->verifyIfEmailEventExistsByPrfUid($oldUid, $projectUid);
|
||||
if(is_array($rowData)) {
|
||||
if ($rowData) {
|
||||
$newValues['PRF_UID'] = $newUid;
|
||||
$this->update($rowData['EMAIL_EVENT_UID'], $newValues);
|
||||
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
@@ -508,26 +552,27 @@ class EmailEvent
|
||||
/**
|
||||
* Verify if exists the Email Event of
|
||||
*
|
||||
* @param string $oldUid Unique id of old process file
|
||||
* @param string $projectUid Unique id of Project
|
||||
* @param string $oldUid Unique id of old process file
|
||||
* @param string $projectUid Unique id of Project
|
||||
*
|
||||
* return bool Return array if exists, false otherwise
|
||||
* @return bool Return array if exists, false otherwise
|
||||
* @throws Exception
|
||||
*/
|
||||
public function verifyIfEmailEventExistsByPrfUid($oldUid, $projectUid)
|
||||
{
|
||||
try {
|
||||
$criteria = $this->getEmailEventCriteria();
|
||||
$criteria->add(\EmailEventPeer::PRJ_UID, $projectUid, \Criteria::EQUAL);
|
||||
$criteria->add(\EmailEventPeer::PRF_UID, $oldUid, \Criteria::EQUAL);
|
||||
$rsCriteria = \EmailEventPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
$criteria->add(EmailEventPeer::PRJ_UID, $projectUid, Criteria::EQUAL);
|
||||
$criteria->add(EmailEventPeer::PRF_UID, $oldUid, Criteria::EQUAL);
|
||||
$rsCriteria = EmailEventPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||
$rsCriteria->next();
|
||||
$row = $rsCriteria->getRow();
|
||||
if(is_array($row)) {
|
||||
$row = array_change_key_case($row, CASE_UPPER);
|
||||
if ($row) {
|
||||
return array_change_key_case($row, CASE_UPPER);
|
||||
}
|
||||
return (sizeof($row))? $row : false;
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user