예제 #1
0
 /**
  *
  * @param type $flowData
  */
 public function getNextShapeElements($flowData)
 {
     $nextElements = $this->caseFlowHandler->retrieveFollowingElements($flowData);
     $eventBean = $this->caseFlowHandler->retrieveBean('pmse_BpmnEvent');
     $nextShapeElements = array();
     foreach ($nextElements as $element) {
         $sugarQueryObject = $this->retrieveSugarQueryObject();
         $sugarQueryObject->select(array('id', 'evn_type', 'evn_behavior'));
         $sugarQueryObject->from($eventBean, array('alias' => 'a'));
         $sugarQueryObject->joinRaw("LEFT JOIN pmse_bpmn_flow b ON (b.flo_element_dest = a.id)", array('alias' => 'b'));
         $sugarQueryObject->where()->queryAnd()->addRaw('b.id=\'' . $element['bpmn_id'] . '\'');
         $queryResult = $sugarQueryObject->execute();
         $result = array_pop($queryResult);
         array_push($nextShapeElements, $result);
     }
     return $nextShapeElements;
 }
예제 #2
0
 /**
  *
  */
 public function wakeUpFreezedFlows()
 {
     //$this->bpmLog('DEBUG', "cron: checking flows with status freezed");
     $flowBean = BeanFactory::getBean('pmse_BpmFlow');
     $flows = $flowBean->get_list('', "cas_flow_status='FREEZE'");
     $n = 0;
     foreach ($flows['list'] as $flow) {
         $flowData = get_object_vars($flow);
         $bean = BeanFactory::getBean($flowData['cas_sugar_module'], $flowData['cas_sugar_object_id']);
         $caseHandler = new PMSECaseFlowHandler();
         $bpmnElement = $caseHandler->retrieveElementByType($flowData['bpmn_type']);
         $flowRouter = new PMSEFlowRouter();
         $executionResult = $bpmnElement->run($flowData, $bean);
         $executionResult['flow_action'] = 'UPDATE';
         $executionResult['flow_id'] = $flowData['id'];
         $flowRouter->wakeUpEngine($flowData, false, $bean, $executionResult);
         $n++;
     }
     // replace the bpmLog calls for the error handler classes
     if ($n == 0) {
         //$this->bpmLog('DEBUG', ": processed $n flows with status freezed");
     } else {
         //$this->bpmLog('INFO', "cron: processed $n flows with status freezed");
     }
 }
예제 #3
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');
     }
 }