Esempio n. 1
0
 /**
  *
  * @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;
 }
 /**
  * This method removes all pending event flows that are 'sleeping' and are
  * associated this this event.
  *
  * @param $eventData Object Event
  */
 public function removeActiveTimerEvents($eventData)
 {
     $this->logger->debug("Removing sleeping timer events for the event: " . print_r($eventData, true));
     $bpmFlowBean = BeanFactory::newBean('pmse_BpmFlow');
     $sq = new SugarQuery();
     $sq->select(array('id'));
     $sq->from($bpmFlowBean);
     $sq->where()->equals('bpmn_id', $eventData['id'])->equals('cas_flow_status', 'SLEEPING');
     $result = $sq->execute();
     foreach ($result as $row) {
         $e = BeanFactory::getBean('pmse_BpmFlow', $row['id']);
         $e->cas_flow_status = 'DELETED';
         $e->save();
         // Update 'Process' to ERROR status
         $cas_id = $e->cas_id;
         $cf = new PMSECaseFlowHandler();
         $cf->changeCaseStatus($cas_id, 'TERMINATED');
     }
 }