/** * * @param type $flowData * @param type $createThread * @param type $bean * @param type $externalAction * @param type $arguments * @return boolean * @codeCoverageIgnore */ public function runEngine($flowData, $createThread = false, $bean = null, $externalAction = '', $arguments = array()) { // Load the bean if the request comes from a RESUME_EXECUTION related origin // like for example: a timer event execution. if (is_null($bean)) { $bean = BeanFactory::retrieveBean($flowData['cas_sugar_module'], $flowData['cas_sugar_object_id']); } // Validating unreferenced elements when cron jobs are executed, after MACAROON-518 shouldn't have // unreferenced elements. This will validate previous records created before this fix. if ($externalAction == 'WAKE_UP') { $elementBean = BeanFactory::getBean('pmse_BpmnEvent', $flowData['bpmn_id']); if (!isset($elementBean->id)) { // Setting active flow to deleted $fd = BeanFactory::getBean('pmse_BpmFlow', $flowData['id']); $fd->cas_flow_status = 'DELETED'; $fd->save(); // Updating process to error $cf = new PMSECaseFlowHandler(); $cf->changeCaseStatus($flowData['cas_id'], 'TERMINATED'); // Exiting without errors return true; } } $preparedData = $this->caseFlowHandler->prepareFlowData($flowData, $createThread); $this->logger->debug("Begin process Element {$flowData['bpmn_type']}"); try { $executionData = $this->processElement($preparedData, $bean, $externalAction, $arguments); if (isset($executionData['process_bean']) && !empty($executionData['process_bean'])) { $bean = $executionData['process_bean']; } $this->validateFailSafes($flowData, $executionData); $routeData = $this->flowRouter->routeFlow($executionData, $flowData, $createThread); } catch (PMSEElementException $e) { $this->logger->warning($e->getMessage()); $element = $e->getElement(); $flow = $e->getFlowData(); $state = empty($flow['id']) ? 'CREATE' : 'UPDATE'; $executionData = $element->prepareResponse($flow, 'ERROR', $state); // If the status is put into error then the Inbox record should be updated as well $this->caseFlowHandler->changeCaseStatus($executionData['flow_data']['cas_id'], 'ERROR'); $routeData = $this->flowRouter->routeFlow($executionData, $flowData, $createThread); } catch (Exception $e) { $this->logger->warning($e->getMessage()); $element = $this->retrievePMSEElement(''); $status = $e->getCode() == 0 ? 'QUEUE' : 'ERROR'; $preparedData['cas_flow_status'] = $status; $executionData = $element->prepareResponse($preparedData, $status, 'CREATE'); // If the status is put into error then the Inbox record should be updated as well if ($status == 'ERROR') { $this->caseFlowHandler->changeCaseStatus($executionData['flow_data']['cas_id'], 'ERROR'); } $routeData = $this->flowRouter->routeFlow($executionData, $flowData, $createThread); } if ($this->caseFlowHandler->numberOfCasesByStatus($flowData, 'ERROR') <= 0 && $externalAction == 'RESUME_EXECUTION') { $this->caseFlowHandler->changeCaseStatus($flowData['cas_id'], 'IN PROGRESS'); } if (!empty($routeData['next_elements'])) { $createThread = sizeof($routeData['next_elements']) > 1; if ($createThread) { $startTime = ($this->maxExecutionTimeout - $this->executionTime) / sizeof($routeData['next_elements']); } foreach ($routeData['next_elements'] as $elementData) { //reset execution time if the derivation is in parallel $this->executionTime = $createThread ? $startTime : $this->executionTime; $this->runEngine($elementData, $createThread, $bean); } } else { // Quick fix to the 0 output printed by some element, // TODO: Don't remove until the fix to the element is commited ob_get_clean(); return true; } return true; }
/** * Send the email based in an email template and with the email data parsed. * @param type $moduleName * @param type $beanId * @param type $addresses * @param type $templateId * @return type */ public function sendTemplateEmail($moduleName, $beanId, $addresses, $templateId) { $msgError = ''; $bean = $this->retrieveBean($moduleName, $beanId); $mailObject = $this->retrieveSugarPHPMailer(); $this->setupMailObject($mailObject); $OBCharset = $this->locale->getPrecedentPreference('default_email_charset'); if (isset($addresses->to)) { foreach ($addresses->to as $key => $email) { $mailObject->AddAddress($email->address, $this->locale->translateCharsetMIME(trim($email->name), 'UTF-8', $OBCharset)); } } else { $msgError = 'addresses field \'TO\' is not defined'; } if (isset($addresses->cc)) { foreach ($addresses->cc as $key => $email) { $mailObject->AddCC($email->address, $this->locale->translateCharsetMIME(trim($email->name), 'UTF-8', $OBCharset)); } } else { $this->logger->info('addresses field \'CC\' is not defined'); } if (isset($addresses->bcc)) { foreach ($addresses->bcc as $key => $email) { $mailObject->AddBCC($email->address, $this->locale->translateCharsetMIME(trim($email->name), 'UTF-8', $OBCharset)); } } else { $this->logger->info('addresses field \'BCC\' is not defined'); } // $email = trim($this->mergeBeanInTemplate($bean, $addressArray['to'][0][1], false)); $templateObject = $this->retrieveBean('pmse_Emails_Templates'); $templateObject->disable_row_level_security = true; if (isset($templateId) && $templateId != "") { $templateObject->retrieve($templateId); } else { $msgError = 'template_id is not defined'; } if (isset($templateObject->from_name) && $templateObject->from_name != '') { $mailObject->FromName = $templateObject->from_name; } if (isset($templateObject->from_address) && $templateObject->from_address != '') { $mailObject->From = $templateObject->from_address; } if (isset($templateObject->body) && empty($templateObject->body)) { $templateObject->body = strip_tags(from_html($templateObject->body_html)); } else { $this->logger->warning('template body is not defined'); } if (isset($templateObject->body) && isset($templateObject->body_html)) { if (!empty($templateObject->body_html)) { $mailObject->IsHTML(true); $mailObject->Body = from_html($this->beanUtils->mergeBeanInTemplate($bean, $templateObject->body_html)); $mailObject->AltBody = from_html($this->beanUtils->mergeBeanInTemplate($bean, $templateObject->body)); } else { $mailObject->AltBody = from_html($this->beanUtils->mergeBeanInTemplate($bean, $templateObject->body)); } } else { $this->logger->warning('template body_html is not defined'); } if (isset($templateObject->subject)) { $mailObject->Subject = from_html($this->beanUtils->mergeBeanInTemplate($bean, $templateObject->subject)); } else { $this->logger->warning('template subject is not defined'); } $mailObject->prepForOutbound(); $result = $mailObject->Send(); //if (isset($mailObject->ErrorInfo)) { //$this->bpmLog('ERROR', "mail error: " . $mailObject->ErrorInfo); //} return array('result' => $result, 'ErrorMessage' => $msgError, 'ErrorInfo' => $mailObject->ErrorInfo); }