Solving bug: when a BPMN Project is updated a new Workflow::route is created, this is happening each time the project is updated: SOLVED

- now routes are being updated (if already exists) instead create new one each time
This commit is contained in:
Erik Amaru Ortiz
2014-03-25 11:30:56 -04:00
parent b6aed1a10b
commit f104861c36
2 changed files with 35 additions and 120 deletions

View File

@@ -364,9 +364,7 @@ class BpmnWorkflow extends Project\Bpmn
));
}
break;
// case 'PARALLEL_JOIN':
// $routeType = 'SEC-JOIN';
// break;
default:
throw new \LogicException(sprintf("Unsupported Gateway type: %s", $gateway['GAT_TYPE']));
}
@@ -389,116 +387,6 @@ class BpmnWorkflow extends Project\Bpmn
}
}
// public static function mapBpmnFlowsToWorkflowRoute2($flow, $flows, $gateways, $events)
// {
// $fromUid = $flow['FLO_ELEMENT_ORIGIN'];
// $result = array();
//
// if ($flow['FLO_ELEMENT_ORIGIN_TYPE'] != "bpmnActivity") {
// // skip flows that comes from a element that is not an Activity
// self::log("Skip map FlowsToWorkflowRoute for -> flow with FLO_UID: {$flow['FLO_UID']}, that have FLO_ELEMENT_ORIGIN: {$flow['FLO_ELEMENT_ORIGIN_TYPE']}:$fromUid");
// return null;
// }
//
// if ($flow['FLO_TYPE'] != 'SEQUENCE') {
// throw new \LogicException(sprintf(
// "Unsupported flow type: %s, ProcessMaker only support type '', Given: '%s'",
// 'SEQUENCE', $flow['FLO_TYPE']
// ));
// }
//
// switch ($flow['FLO_ELEMENT_DEST_TYPE']) {
// case 'bpmnActivity':
// // the most easy case, when the flow is connecting a activity with another activity
// $result[] = array("from" => $fromUid, "to" => $flow['FLO_ELEMENT_DEST'], "type" => 'SEQUENTIAL');
// break;
// case 'bpmnGateway':
// $gatUid = $flow['FLO_ELEMENT_DEST'];
//
// // if it is a gateway it can fork one or more routes
// $gatFlows = self::findInArray($gatUid, "FLO_ELEMENT_ORIGIN", $flows);
//
// foreach ($gatFlows as $gatFlow) {
// switch ($gatFlow['FLO_ELEMENT_DEST_TYPE']) {
// case 'bpmnActivity':
// // getting gateway properties
// $gateways = self::findInArray($gatUid, "GAT_UID", $gateways);
//
// if (! empty($gateways)) {
// $gateway = $gateways[0];
// $routeType = "";
//
// switch ($gateway['GAT_TYPE']) {
// case self::BPMN_GATEWAY_COMPLEX:
// $routeType = 'SELECT';
// break;
// case self::BPMN_GATEWAY_EXCLUSIVE:
// $routeType = 'EVALUATE';
// break;
// case self::BPMN_GATEWAY_INCLUSIVE:
// switch ($gateway['GAT_DIRECTION']) {
// case "DIVERGING":
// $routeType = 'PARALLEL-BY-EVALUATION';
// break;
// case "CONVERGING":
// $routeType = 'SEC-JOIN';
// break;
// default:
// throw new \LogicException(sprintf("Unsupported Gateway direction: %s", $gateway['GAT_DIRECTION']));
// }
// break;
// case self::BPMN_GATEWAY_PARALLEL:
// switch ($gateway['GAT_DIRECTION']) {
// case "DIVERGING":
// $routeType = 'PARALLEL';
// break;
// case "CONVERGING":
// $routeType = 'SEC-JOIN';
// break;
// default:
// throw new \LogicException(sprintf("Unsupported Gateway direction: %s", $gateway['GAT_DIRECTION']));
// }
// break;
// default:
// throw new \LogicException(sprintf("Unsupported Gateway type: %s", $gateway['GAT_TYPE']));
// }
//
// $result[] = array("from" => $fromUid, "to" => $gatFlow['FLO_ELEMENT_DEST'], "type" => $routeType);
// }
// break;
// default:
// // for processmaker is only allowed flows between "gateway -> activity"
// // any another flow is considered invalid
// throw new \LogicException(sprintf(
// "For ProcessMaker is only allowed flows between \"gateway -> activity\" " . PHP_EOL .
// "Given: bpmnGateway -> " . $gatFlow['FLO_ELEMENT_DEST_TYPE']
// ));
// }
// }
// break;
// case 'bpmnEvent':
// $evnUid = $flow['FLO_ELEMENT_DEST'];
// $events = self::findInArray($evnUid, "EVN_UID", $events);
//
//
// if (! empty($events)) {
// $event = $events[0];
//
// switch ($event['EVN_TYPE']) {
// case 'END':
// $routeType = 'SEQUENTIAL';
// $result[] = array("from" => $fromUid, "to" => "-1", "type" => $routeType);
// break;
// default:
// throw new \LogicException("Invalid connection to Event object type");
// }
// }
// break;
// }
//
// return empty($result) ? null : $result;
// }
public function remove()
{
parent::remove();

View File

@@ -286,11 +286,19 @@ class Workflow extends Handler
}
}
/**
* This method add a new or update a Route record
*
* @param $fromTasUid
* @param $toTasUid
* @param $type
* @param string $condition
* @return string
* @throws \Exception
*/
public function addRoute($fromTasUid, $toTasUid, $type, $condition = "")
{
try {
self::log("Add Route from task: $fromTasUid -> to task: $toTasUid ($type)");
$validTypes = array("SEQUENTIAL", "SELECT", "EVALUATE", "PARALLEL", "PARALLEL-BY-EVALUATION", "SEC-JOIN", "DISCRIMINATOR");
if (! in_array($type, $validTypes)) {
@@ -303,13 +311,26 @@ class Workflow extends Handler
//}
}
//if ($delete || $type == 'SEQUENTIAL' || $type == 'SEC-JOIN' || $type == 'DISCRIMINATOR') {
//if ($type == 'SEQUENTIAL' || $type == 'SEC-JOIN' || $type == 'DISCRIMINATOR') {
//$oTasks = new Tasks();
//$oTasks->deleteAllRoutesOfTask($this->proUid, $fromTasUid);
//}
$result = $this->saveNewPattern($this->proUid, $fromTasUid, $toTasUid, $type, $condition);
self::log("Add Route Success! - ROU_UID: ", $result);
$route = \Route::findOneBy(array(
\RoutePeer::TAS_UID => $fromTasUid,
\RoutePeer::ROU_NEXT_TASK => $toTasUid
));
if (is_null($route)) {
$result = $this->saveNewPattern($this->proUid, $fromTasUid, $toTasUid, $type, $condition);
} else {
$result = $this->updateRoute($route->getRouUid(), array(
"TAS_UID" => $fromTasUid,
"ROU_NEXT_TASK" => $toTasUid,
"ROU_TYPE" => $type,
"ROU_CONDITION" => $condition
));
}
return $result;
} catch (\Exception $e) {
@@ -331,8 +352,10 @@ class Workflow extends Handler
try {
self::log("Update Route: $rouUid with data:", $routeData);
$route = new Route();
$route->update($routeData);
$result = $route->update($routeData);
self::log("Update Route Success!");
return $result;
} catch (\Exception $e) {
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
throw $e;
@@ -412,6 +435,8 @@ class Workflow extends Handler
private function saveNewPattern($sProcessUID = '', $sTaskUID = '', $sNextTask = '', $sType = '', $condition = '')
{
try {
self::log("Add Route from task: $sTaskUID -> to task: $sNextTask ($sType)");
$oCriteria = new Criteria('workflow');
$oCriteria->addSelectColumn('COUNT(*) AS ROUTE_NUMBER');
//$oCriteria->addSelectColumn('GAT_UID AS GATEWAY_UID');
@@ -452,8 +477,10 @@ class Workflow extends Handler
//$aFields['GAT_UID'] = (isset($sGatewayUID)) ? $sGatewayUID : '';
$oRoute = new Route();
$result = $oRoute->create($aFields);
self::log("Add Route Success! - ROU_UID: ", $result);
return $oRoute->create($aFields);
return $result;
} catch (Exception $oError) {
throw ($oError);
}