define('DB_ADAPTER', $DB_ADAPTER);
     }
     eprintln('Processing workspace: ' . $workspace, 'green');
     try {
         switch ($cronName) {
             case 'cron':
                 processWorkspace();
                 break;
             case 'ldapcron':
                 require_once PATH_HOME . 'engine' . PATH_SEP . 'classes' . PATH_SEP . 'class.ldapAdvanced.php';
                 require_once PATH_HOME . 'engine' . PATH_SEP . 'methods' . PATH_SEP . 'services' . PATH_SEP . 'ldapadvanced.php';
                 $ldapadvancedClassCron = new ldapadvancedClassCron();
                 $ldapadvancedClassCron->executeCron(in_array('+debug', $argv));
                 break;
             case 'messageeventcron':
                 $messageApplication = new \ProcessMaker\BusinessModel\MessageApplication();
                 $messageApplication->catchMessageEvent(true);
                 break;
             case 'timereventcron':
                 $timerEvent = new \ProcessMaker\BusinessModel\TimerEvent();
                 $timerEvent->startContinueCaseByTimerEvent(date('Y-m-d H:i:s'), true);
                 break;
         }
     } catch (Exception $e) {
         echo $e->getMessage() . "\n";
         eprintln('Problem in workspace: ' . $workspace . ' it was omitted.', 'red');
     }
     eprintln();
 }
 if (file_exists(PATH_CORE . 'config' . PATH_SEP . '_databases_.php')) {
     unlink(PATH_CORE . 'config' . PATH_SEP . '_databases_.php');
Exemple #2
0
    /**
     * Catch Message-Events for the Cases
     *
     * @param bool $frontEnd Flag to represent progress bar
     *
     * return void
     */
    public function catchMessageEvent($frontEnd = false)
    {
        try {
            \G::LoadClass("wsBase");

            //Set variables
            $ws = new \wsBase();
            $case = new \Cases();

            $messageApplication = new \ProcessMaker\BusinessModel\MessageApplication();
            $messageApplication->setFrontEnd($frontEnd);

            //Get data
            $totalMessageEvent = 0;

            $counterStartMessageEvent = 0;
            $counterIntermediateCatchMessageEvent = 0;
            $counter = 0;

            $flagFirstTime = false;

            $messageApplication->frontEndShow("START");

            do {
                $flagNextRecords = false;

                $arrayMessageApplicationUnread = $messageApplication->getMessageApplications(array("messageApplicationStatus" => "UNREAD"), null, null, 0, 1000);

                if (!$flagFirstTime) {
                    $totalMessageEvent = $arrayMessageApplicationUnread["total"];

                    $flagFirstTime = true;
                }

                foreach ($arrayMessageApplicationUnread["data"] as $value) {
                    if ($counter + 1 > $totalMessageEvent) {
                        $flagNextRecords = false;
                        break;
                    }

                    $arrayMessageApplicationData = $value;

                    $processUid = $arrayMessageApplicationData["PRJ_UID"];
                    $taskUid = $arrayMessageApplicationData["TAS_UID"];

                    $messageApplicationUid         = $arrayMessageApplicationData["MSGAPP_UID"];
                    $messageApplicationCorrelation = $arrayMessageApplicationData["MSGAPP_CORRELATION"];

                    $messageEventDefinitionUserUid     = $arrayMessageApplicationData["MSGED_USR_UID"];
                    $messageEventDefinitionCorrelation = $arrayMessageApplicationData["MSGED_CORRELATION"];

                    $arrayVariable = $messageApplication->mergeVariables($arrayMessageApplicationData["MSGED_VARIABLES"], $arrayMessageApplicationData["MSGAPP_VARIABLES"]);

                    $flagCatched = false;

                    switch ($arrayMessageApplicationData["EVN_TYPE"]) {
                        case "START":
                            if ($messageEventDefinitionCorrelation == $messageApplicationCorrelation && $messageEventDefinitionUserUid != "") {
                                //Start and derivate new Case
                                $result = $ws->newCase($processUid, $messageEventDefinitionUserUid, $taskUid, $arrayVariable);

                                $arrayResult = json_decode(json_encode($result), true);

                                if ($arrayResult["status_code"] == 0) {
                                    $applicationUid = $arrayResult["caseId"];

                                    $result = $ws->derivateCase($messageEventDefinitionUserUid, $applicationUid, 1);

                                    $flagCatched = true;

                                    //Counter
                                    $counterStartMessageEvent++;
                                }
                            }
                            break;
                        case "INTERMEDIATE":
                            $criteria = new \Criteria("workflow");

                            $criteria->addSelectColumn(\AppDelegationPeer::APP_UID);
                            $criteria->addSelectColumn(\AppDelegationPeer::DEL_INDEX);
                            $criteria->addSelectColumn(\AppDelegationPeer::USR_UID);

                            $criteria->add(\AppDelegationPeer::PRO_UID, $processUid, \Criteria::EQUAL);
                            $criteria->add(\AppDelegationPeer::TAS_UID, $taskUid, \Criteria::EQUAL);
                            $criteria->add(\AppDelegationPeer::DEL_THREAD_STATUS, "OPEN", \Criteria::EQUAL);
                            $criteria->add(\AppDelegationPeer::DEL_FINISH_DATE, null, \Criteria::ISNULL);

                            $rsCriteria = \AppDelegationPeer::doSelectRS($criteria);
                            $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);

                            while ($rsCriteria->next()) {
                                $row = $rsCriteria->getRow();

                                $applicationUid = $row["APP_UID"];
                                $delIndex = $row["DEL_INDEX"];
                                $userUid = $row["USR_UID"];

                                $arrayApplicationData = $case->loadCase($applicationUid);

                                if (\G::replaceDataField($messageEventDefinitionCorrelation, $arrayApplicationData["APP_DATA"]) == $messageApplicationCorrelation) {
                                    //"Unpause" and derivate Case
                                    $arrayApplicationData["APP_DATA"] = array_merge($arrayApplicationData["APP_DATA"], $arrayVariable);

                                    $arrayResult = $case->updateCase($applicationUid, $arrayApplicationData);

                                    $result = $ws->derivateCase($userUid, $applicationUid, $delIndex);

                                    $flagCatched = true;
                                }
                            }

                            //Counter
                            if ($flagCatched) {
                                $counterIntermediateCatchMessageEvent++;
                            }
                            break;
                    }

                    //Message-Application catch
                    if ($flagCatched) {
                        $result = $messageApplication->update($messageApplicationUid, array("MSGAPP_STATUS" => "READ"));
                    }

                    $counter++;

                    //Progress bar
                    $messageApplication->frontEndShow("BAR", "Message-Events (unread): " . $counter . "/" . $totalMessageEvent . " " . $messageApplication->progressBar($totalMessageEvent, $counter));

                    $flagNextRecords = true;
                }
            } while ($flagNextRecords);

            $messageApplication->frontEndShow("TEXT", "Total Message-Events unread: " . $totalMessageEvent);
            $messageApplication->frontEndShow("TEXT", "Total cases started: " . $counterStartMessageEvent);
            $messageApplication->frontEndShow("TEXT", "Total cases continued: " . $counterIntermediateCatchMessageEvent);
            $messageApplication->frontEndShow("TEXT", "Total Message-Events pending: " . ($totalMessageEvent - ($counterStartMessageEvent + $counterIntermediateCatchMessageEvent)));

            $messageApplication->frontEndShow("END");
        } catch (\Exception $e) {
            throw $e;
        }
    }
 /**
  * Throw Events for the Case
  *
  * @param string $eventUid           Unique id of Event
  * @param array  $appFields          Case data
  *
  * @return void
  */
 private function throwEventsElemntOriginToElementDest($eventUid, $appFields)
 {
     try {
         //Verify if the Project is BPMN
         $bpmn = new \ProcessMaker\Project\Bpmn();
         if (!$bpmn->exists($appFields["PRO_UID"])) {
             return;
         }
         //Throw Events
         $messageApplication = new \ProcessMaker\BusinessModel\MessageApplication();
         $emailEvent = new \ProcessMaker\BusinessModel\EmailEvent();
         $event = \BpmnEventPeer::retrieveByPK($eventUid);
         if (!is_null($event)) {
             if (preg_match("/^(?:END|INTERMEDIATE)\$/", $event->getEvnType()) && $event->getEvnMarker() == "MESSAGETHROW") {
                 //Message-Application throw
                 $result = $messageApplication->create($appFields["APP_UID"], $appFields["PRO_UID"], $value[0], $appFields);
             }
             if (preg_match("/^(?:END|INTERMEDIATE)\$/", $event->getEvnType()) && $event->getEvnMarker() == "EMAIL") {
                 //Email-Event throw
                 $result = $emailEvent->sendEmail($appFields["APP_UID"], $appFields["PRO_UID"], $eventUid, $appFields);
             }
         }
     } catch (Exception $e) {
         throw $e;
     }
 }