Merge remote branch 'upstream/master'
This commit is contained in:
@@ -154,7 +154,7 @@ class System
|
||||
return false;
|
||||
}
|
||||
if (exec( "cd $dir && git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/^* \(.*\)$/(Branch \\1)/'", $target )) {
|
||||
exec( "cd $dir && git describe", $target );
|
||||
//exec( "cd $dir && git describe", $target ); ??? <-- thi is returning "fatal: No names found, cannot describe anything." on apache error log file
|
||||
return implode( ' ', $target );
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -23,6 +23,16 @@
|
||||
*/
|
||||
ini_set( 'max_execution_time', '0' );
|
||||
|
||||
|
||||
$ext = pathinfo($_FILES["PROCESS_FILENAME"]["name"], PATHINFO_EXTENSION);
|
||||
|
||||
if ($ext == "pmx") {
|
||||
$importer = new \ProcessMaker\Importer\XmlImporter();
|
||||
$importer->setSourceFromGlobals("PROCESS_FILENAME");
|
||||
$importer->import();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
function reservedWordsSqlValidate ($data)
|
||||
{
|
||||
$arrayAux = array ();
|
||||
|
||||
@@ -636,12 +636,16 @@ class Cases
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function putCancelCase($app_uid, $usr_uid, $del_index = false) {
|
||||
Validator::appUid($app_uid, '$cas_uid');
|
||||
Validator::isString($app_uid, '$app_uid');
|
||||
Validator::isString($usr_uid, '$usr_uid');
|
||||
|
||||
Validator::appUid($app_uid, '$app_uid');
|
||||
Validator::usrUid($usr_uid, '$usr_uid');
|
||||
|
||||
if ($del_index === false) {
|
||||
$del_index = \AppDelegation::getCurrentIndex($app_uid);
|
||||
}
|
||||
Validator::isInteger($del_index, '$del_index');
|
||||
|
||||
$case = new \Cases();
|
||||
$case->cancelCase( $app_uid, $del_index, $usr_uid );
|
||||
@@ -661,15 +665,20 @@ class Cases
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function putPauseCase($app_uid, $usr_uid, $del_index = false, $unpaused_date = null) {
|
||||
Validator::appUid($app_uid, '$cas_uid');
|
||||
Validator::isString($app_uid, '$app_uid');
|
||||
Validator::isString($usr_uid, '$usr_uid');
|
||||
|
||||
Validator::appUid($app_uid, '$app_uid');
|
||||
Validator::usrUid($usr_uid, '$usr_uid');
|
||||
if ($unpaused_date != null) {
|
||||
Validator::isDate($unpaused_date, 'Y-m-d', '$unpaused_date');
|
||||
}
|
||||
|
||||
if ($del_index === false) {
|
||||
$del_index = \AppDelegation::getCurrentIndex($app_uid);
|
||||
}
|
||||
Validator::isInteger($del_index, '$del_index');
|
||||
|
||||
if ($unpaused_date != null) {
|
||||
Validator::isDate($unpaused_date, 'Y-m-d', '$unpaused_date');
|
||||
}
|
||||
|
||||
$case = new \Cases();
|
||||
$case->pauseCase( $app_uid, $del_index, $usr_uid, $unpaused_date );
|
||||
@@ -687,12 +696,16 @@ class Cases
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function putUnpauseCase($app_uid, $usr_uid, $del_index = false) {
|
||||
Validator::appUid($app_uid, '$cas_uid');
|
||||
Validator::isString($app_uid, '$app_uid');
|
||||
Validator::isString($usr_uid, '$usr_uid');
|
||||
|
||||
Validator::appUid($app_uid, '$app_uid');
|
||||
Validator::usrUid($usr_uid, '$usr_uid');
|
||||
|
||||
if ($del_index === false) {
|
||||
$del_index = \AppDelegation::getCurrentIndex($app_uid);
|
||||
}
|
||||
Validator::isInteger($del_index, '$del_index');
|
||||
|
||||
$case = new \Cases();
|
||||
$case->unpauseCase( $app_uid, $del_index, $usr_uid );
|
||||
@@ -710,13 +723,18 @@ class Cases
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function putExecuteTriggerCase($app_uid, $tri_uid, $usr_uid, $del_index = false) {
|
||||
Validator::appUid($app_uid, '$cas_uid');
|
||||
Validator::isString($app_uid, '$app_uid');
|
||||
Validator::isString($tri_uid, '$tri_uid');
|
||||
Validator::isString($usr_uid, '$usr_uid');
|
||||
|
||||
Validator::appUid($app_uid, '$app_uid');
|
||||
Validator::triUid($tri_uid, '$tri_uid');
|
||||
Validator::usrUid($usr_uid, '$usr_uid');
|
||||
|
||||
if ($del_index === false) {
|
||||
$del_index = \AppDelegation::getCurrentIndex($app_uid);
|
||||
}
|
||||
Validator::isInteger($del_index, '$del_index');
|
||||
|
||||
$case = new \wsBase();
|
||||
$case->executeTrigger( $usr_uid, $app_uid, $tri_uid, $del_index );
|
||||
@@ -733,7 +751,8 @@ class Cases
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function deleteCase($app_uid) {
|
||||
Validator::appUid($app_uid, '$cas_uid');
|
||||
Validator::isString($app_uid, '$app_uid');
|
||||
Validator::appUid($app_uid, '$app_uid');
|
||||
$case = new \Cases();
|
||||
$case->removeCase( $app_uid );
|
||||
}
|
||||
|
||||
@@ -6,15 +6,15 @@ class InputDocument
|
||||
/**
|
||||
* Get data of Cases InputDocument
|
||||
*
|
||||
* @param string $caseUid
|
||||
* @param string $applicationUid
|
||||
* @param string $userUid
|
||||
*
|
||||
* return array Return an array with data of an InputDocument
|
||||
*/
|
||||
public function getCasesInputDocuments($caseUid, $userUid)
|
||||
public function getCasesInputDocuments($applicationUid, $userUid)
|
||||
{
|
||||
try {
|
||||
$sApplicationUID = $caseUid;
|
||||
$sApplicationUID = $applicationUid;
|
||||
$sUserUID = $userUid;
|
||||
\G::LoadClass('case');
|
||||
$oCase = new \Cases();
|
||||
@@ -49,16 +49,16 @@ class InputDocument
|
||||
/**
|
||||
* Get data of Cases InputDocument
|
||||
*
|
||||
* @param string $caseUid
|
||||
* @param string $applicationUid
|
||||
* @param string $userUid
|
||||
* @param string $inputDocumentUid
|
||||
*
|
||||
* return array Return an array with data of an InputDocument
|
||||
*/
|
||||
public function getCasesInputDocument($caseUid, $userUid, $inputDocumentUid)
|
||||
public function getCasesInputDocument($applicationUid, $userUid, $inputDocumentUid)
|
||||
{
|
||||
try {
|
||||
$sApplicationUID = $caseUid;
|
||||
$sApplicationUID = $applicationUid;
|
||||
$sUserUID = $userUid;
|
||||
\G::LoadClass('case');
|
||||
$oCase = new \Cases();
|
||||
@@ -117,17 +117,18 @@ class InputDocument
|
||||
/**
|
||||
* Get data of Cases InputDocument
|
||||
*
|
||||
* @param string $caseUid
|
||||
* @param string $applicationUid
|
||||
* @param string $taskUid
|
||||
* @param string $inputDocumentUid
|
||||
* @param string $userUid
|
||||
*
|
||||
* return array Return an array with data of an InputDocument
|
||||
*/
|
||||
public function addCasesInputDocument($caseUid, $inputDocumentUid, $userUid)
|
||||
public function addCasesInputDocument($applicationUid, $taskUid, $inputDocumentUid, $userUid)
|
||||
{
|
||||
try {
|
||||
if ((isset( $_FILES['form'] )) && ($_FILES['form']['error']['APP_DOC_FILENAME'] != 0)) {
|
||||
$code = $_FILES['form']['error']['APP_DOC_FILENAME'];
|
||||
if ((isset( $_FILES['form'] )) && ($_FILES['form']['error'] != 0)) {
|
||||
$code = $_FILES['form']['error'];
|
||||
switch ($code) {
|
||||
case UPLOAD_ERR_INI_SIZE:
|
||||
$message = \G::LoadTranslation( 'ID_UPLOAD_ERR_INI_SIZE' );
|
||||
@@ -159,31 +160,23 @@ class InputDocument
|
||||
\G::header( "location: " . "/sys" . SYS_SYS . $backUrlObj[1] );
|
||||
die();
|
||||
}
|
||||
|
||||
\G::LoadClass("case");
|
||||
|
||||
//$inputDocumentUid = $_GET["UID"]; //$_POST["form"]["DOC_UID"]
|
||||
$appDocUid = '';
|
||||
//$appDocUid = $_POST["form"]["APP_DOC_UID"];
|
||||
$appDocUid = \G::generateUniqueID();
|
||||
$docVersion = '';
|
||||
//$docVersion = intval($_POST["form"]["docVersion"]);
|
||||
$appDocType = 'INPUT';
|
||||
//$appDocType = $_POST["form"]["APP_DOC_TYPE"];
|
||||
$appDocComment = (isset($_POST["form"]["APP_DOC_COMMENT"]))? $_POST["form"]["APP_DOC_COMMENT"] : "";
|
||||
$actionType = $_POST["form"]["actionType"];
|
||||
|
||||
$appDocComment = (isset($_POST["form"]))? $_POST["form"] : "";
|
||||
$case = new \Cases();
|
||||
$case->thisIsTheCurrentUser($_SESSION["APPLICATION"], $_SESSION["INDEX"], $_SESSION["USER_LOGGED"], "REDIRECT", "casesListExtJs");
|
||||
|
||||
$delIndex = \AppDelegation::getCurrentIndex($applicationUid);
|
||||
$case->thisIsTheCurrentUser($applicationUid, $delIndex, $userUid, "REDIRECT", "casesListExtJs");
|
||||
//Load the fields
|
||||
$arrayField = $case->loadCase($_SESSION["APPLICATION"]);
|
||||
$arrayField = $case->loadCase($applicationUid);
|
||||
$arrayField["APP_DATA"] = array_merge($arrayField["APP_DATA"], \G::getSystemConstants());
|
||||
|
||||
//Triggers
|
||||
$arrayTrigger = $case->loadTriggers($_SESSION["TASK"], "INPUT_DOCUMENT", $inputDocumentUid, "AFTER");
|
||||
|
||||
|
||||
$arrayTrigger = $case->loadTriggers($taskUid, "INPUT_DOCUMENT", $inputDocumentUid, "AFTER");
|
||||
//Add Input Document
|
||||
if (!$_FILES["form"]["error"]) {
|
||||
$_FILES["form"]["error"] = 0;
|
||||
}
|
||||
if (isset($_FILES) && isset($_FILES["form"]) && count($_FILES["form"]) > 0) {
|
||||
$appDocUid = $case->addInputDocument(
|
||||
$inputDocumentUid,
|
||||
@@ -191,44 +184,39 @@ class InputDocument
|
||||
$docVersion,
|
||||
$appDocType,
|
||||
$appDocComment,
|
||||
$actionType,
|
||||
$_SESSION["APPLICATION"],
|
||||
$_SESSION["INDEX"],
|
||||
$_SESSION["TASK"],
|
||||
$_SESSION["USER_LOGGED"],
|
||||
'',
|
||||
$applicationUid,
|
||||
$delIndex,
|
||||
$taskUid,
|
||||
$userUid,
|
||||
"xmlform",
|
||||
$_FILES["form"]["name"]["APP_DOC_FILENAME"],
|
||||
$_FILES["form"]["error"]["APP_DOC_FILENAME"],
|
||||
$_FILES["form"]["tmp_name"]["APP_DOC_FILENAME"]
|
||||
$_FILES["form"]["name"],
|
||||
$_FILES["form"]["error"],
|
||||
$_FILES["form"]["tmp_name"]
|
||||
);
|
||||
}
|
||||
|
||||
if ($_SESSION["TRIGGER_DEBUG"]["NUM_TRIGGERS"] > 0) {
|
||||
}
|
||||
if ($_SESSION["TRIGGER_DEBUG"]["NUM_TRIGGERS"] > 0) {
|
||||
//Trigger - Execute after - Start
|
||||
$arrayField["APP_DATA"] = $case->executeTriggers(
|
||||
$_SESSION["TASK"],
|
||||
$taskUid,
|
||||
"INPUT_DOCUMENT",
|
||||
$inputDocumentUid,
|
||||
"AFTER",
|
||||
$arrayField["APP_DATA"]
|
||||
);
|
||||
//Trigger - Execute after - End
|
||||
}
|
||||
|
||||
}
|
||||
//Save data
|
||||
$arrayData = array();
|
||||
$arrayData["APP_NUMBER"] = $arrayField["APP_NUMBER"];
|
||||
//$arrayData["APP_PROC_STATUS"] = $arrayField["APP_PROC_STATUS"];
|
||||
$arrayData["APP_DATA"] = $arrayField["APP_DATA"];
|
||||
$arrayData["DEL_INDEX"] = $_SESSION["INDEX"];
|
||||
$arrayData["TAS_UID"] = $_SESSION["TASK"];
|
||||
|
||||
$case->updateCase($_SESSION["APPLICATION"], $arrayData);
|
||||
|
||||
$arrayData["DEL_INDEX"] = $delIndex;
|
||||
$arrayData["TAS_UID"] = $taskUid;
|
||||
$case->updateCase($applicationUid, $arrayData);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -6,21 +6,21 @@ class OutputDocument
|
||||
/**
|
||||
* Get data of Cases OutputDocument
|
||||
*
|
||||
* @param string $caseUid
|
||||
* @param string $applicationUid
|
||||
* @param string $userUid
|
||||
*
|
||||
* return array Return an array with data of an OutputDocument
|
||||
*/
|
||||
public function getCasesOutputDocuments($caseUid, $userUid)
|
||||
public function getCasesOutputDocuments($applicationUid, $userUid)
|
||||
{
|
||||
try {
|
||||
\G::LoadClass('case');
|
||||
$oCase = new \Cases();
|
||||
$fields = $oCase->loadCase( $caseUid );
|
||||
$fields = $oCase->loadCase( $applicationUid );
|
||||
$sProcessUID = $fields['PRO_UID'];
|
||||
$sTaskUID = '';
|
||||
$oCriteria = new \BusinessModel\Cases();
|
||||
$oCriteria->getAllGeneratedDocumentsCriteria( $sProcessUID, $caseUid, $sTaskUID, $userUid);
|
||||
$oCriteria->getAllGeneratedDocumentsCriteria( $sProcessUID, $applicationUid, $sTaskUID, $userUid);
|
||||
$result = array ();
|
||||
global $_DBArray;
|
||||
foreach ($_DBArray['outputDocuments'] as $key => $row) {
|
||||
@@ -47,16 +47,16 @@ class OutputDocument
|
||||
/**
|
||||
* Get data of Cases OutputDocument
|
||||
*
|
||||
* @param string $caseUid
|
||||
* @param string $applicationUid
|
||||
* @param string $userUid
|
||||
* @param string $outputDocumentUid
|
||||
*
|
||||
* return array Return an array with data of an OutputDocument
|
||||
*/
|
||||
public function getCasesOutputDocument($caseUid, $userUid, $outputDocumentUid)
|
||||
public function getCasesOutputDocument($applicationUid, $userUid, $outputDocumentUid)
|
||||
{
|
||||
try {
|
||||
$sApplicationUID = $caseUid;
|
||||
$sApplicationUID = $applicationUid;
|
||||
$sUserUID = $userUid;
|
||||
\G::LoadClass('case');
|
||||
$oCase = new \Cases();
|
||||
@@ -115,114 +115,15 @@ class OutputDocument
|
||||
/**
|
||||
* Get data of Cases OutputDocument
|
||||
*
|
||||
* @param string $caseUid
|
||||
* @param string $applicationUid
|
||||
* @param string $outputDocumentUid
|
||||
* @param string $userUid
|
||||
*
|
||||
* return array Return an array with data of an OutputDocument
|
||||
*/
|
||||
public function addCasesOutputDocument($caseUid, $outputDocumentUid, $userUid)
|
||||
public function addCasesOutputDocument($applicationUid, $outputDocumentUid, $userUid)
|
||||
{
|
||||
try {
|
||||
if ((isset( $_FILES['form'] )) && ($_FILES['form']['error']['APP_DOC_FILENAME'] != 0)) {
|
||||
$code = $_FILES['form']['error']['APP_DOC_FILENAME'];
|
||||
switch ($code) {
|
||||
case UPLOAD_ERR_INI_SIZE:
|
||||
$message = \G::LoadTranslation( 'ID_UPLOAD_ERR_INI_SIZE' );
|
||||
break;
|
||||
case UPLOAD_ERR_FORM_SIZE:
|
||||
$message = \G::LoadTranslation( 'ID_UPLOAD_ERR_FORM_SIZE' );
|
||||
break;
|
||||
case UPLOAD_ERR_PARTIAL:
|
||||
$message = \G::LoadTranslation( 'ID_UPLOAD_ERR_PARTIAL' );
|
||||
break;
|
||||
case UPLOAD_ERR_NO_FILE:
|
||||
$message = \G::LoadTranslation( 'ID_UPLOAD_ERR_NO_FILE' );
|
||||
break;
|
||||
case UPLOAD_ERR_NO_TMP_DIR:
|
||||
$message = \G::LoadTranslation( 'ID_UPLOAD_ERR_NO_TMP_DIR' );
|
||||
break;
|
||||
case UPLOAD_ERR_CANT_WRITE:
|
||||
$message = \G::LoadTranslation( 'ID_UPLOAD_ERR_CANT_WRITE' );
|
||||
break;
|
||||
case UPLOAD_ERR_EXTENSION:
|
||||
$message = \G::LoadTranslation( 'ID_UPLOAD_ERR_EXTENSION' );
|
||||
break;
|
||||
default:
|
||||
$message = \G::LoadTranslation( 'ID_UPLOAD_ERR_UNKNOWN' );
|
||||
break;
|
||||
}
|
||||
\G::SendMessageText( $message, "ERROR" );
|
||||
$backUrlObj = explode( "sys" . SYS_SYS, $_SERVER['HTTP_REFERER'] );
|
||||
\G::header( "location: " . "/sys" . SYS_SYS . $backUrlObj[1] );
|
||||
die();
|
||||
}
|
||||
|
||||
\G::LoadClass("case");
|
||||
|
||||
//$inputDocumentUid = $_GET["UID"]; //$_POST["form"]["DOC_UID"]
|
||||
$appDocUid = '';
|
||||
//$appDocUid = $_POST["form"]["APP_DOC_UID"];
|
||||
$docVersion = '';
|
||||
//$docVersion = intval($_POST["form"]["docVersion"]);
|
||||
$appDocType = 'INPUT';
|
||||
//$appDocType = $_POST["form"]["APP_DOC_TYPE"];
|
||||
$appDocComment = (isset($_POST["form"]["APP_DOC_COMMENT"]))? $_POST["form"]["APP_DOC_COMMENT"] : "";
|
||||
$actionType = $_POST["form"]["actionType"];
|
||||
|
||||
$case = new \Cases();
|
||||
$case->thisIsTheCurrentUser($_SESSION["APPLICATION"], $_SESSION["INDEX"], $_SESSION["USER_LOGGED"], "REDIRECT", "casesListExtJs");
|
||||
|
||||
//Load the fields
|
||||
$arrayField = $case->loadCase($_SESSION["APPLICATION"]);
|
||||
$arrayField["APP_DATA"] = array_merge($arrayField["APP_DATA"], \G::getSystemConstants());
|
||||
|
||||
//Triggers
|
||||
$arrayTrigger = $case->loadTriggers($_SESSION["TASK"], "INPUT_DOCUMENT", $outputDocumentUid, "AFTER");
|
||||
|
||||
|
||||
//Add Input Document
|
||||
if (isset($_FILES) && isset($_FILES["form"]) && count($_FILES["form"]) > 0) {
|
||||
$appDocUid = $case->addInputDocument(
|
||||
$outputDocumentUid,
|
||||
$appDocUid,
|
||||
$docVersion,
|
||||
$appDocType,
|
||||
$appDocComment,
|
||||
$actionType,
|
||||
$_SESSION["APPLICATION"],
|
||||
$_SESSION["INDEX"],
|
||||
$_SESSION["TASK"],
|
||||
$_SESSION["USER_LOGGED"],
|
||||
"xmlform",
|
||||
$_FILES["form"]["name"]["APP_DOC_FILENAME"],
|
||||
$_FILES["form"]["error"]["APP_DOC_FILENAME"],
|
||||
$_FILES["form"]["tmp_name"]["APP_DOC_FILENAME"]
|
||||
);
|
||||
}
|
||||
|
||||
if ($_SESSION["TRIGGER_DEBUG"]["NUM_TRIGGERS"] > 0) {
|
||||
//Trigger - Execute after - Start
|
||||
$arrayField["APP_DATA"] = $case->executeTriggers(
|
||||
$_SESSION["TASK"],
|
||||
"INPUT_DOCUMENT",
|
||||
$outputDocumentUid,
|
||||
"AFTER",
|
||||
$arrayField["APP_DATA"]
|
||||
);
|
||||
//Trigger - Execute after - End
|
||||
}
|
||||
|
||||
//Save data
|
||||
$arrayData = array();
|
||||
$arrayData["APP_NUMBER"] = $arrayField["APP_NUMBER"];
|
||||
//$arrayData["APP_PROC_STATUS"] = $arrayField["APP_PROC_STATUS"];
|
||||
$arrayData["APP_DATA"] = $arrayField["APP_DATA"];
|
||||
$arrayData["DEL_INDEX"] = $_SESSION["INDEX"];
|
||||
$arrayData["TAS_UID"] = $_SESSION["TASK"];
|
||||
|
||||
$case->updateCase($_SESSION["APPLICATION"], $arrayData);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
@@ -237,11 +237,11 @@ class Validator{
|
||||
{
|
||||
$date = trim($date);
|
||||
if ($date == '') {
|
||||
throw (new \Exception("The value '' is not valid fot the format '$format'."));
|
||||
throw (new \Exception("The value '' is not a valid date for the format '$format'."));
|
||||
}
|
||||
$d = \DateTime::createFromFormat($format, $date);
|
||||
if (!($d && $d->format($format) == $date)) {
|
||||
throw (new \Exception("The value '$date' is not valid fot the format '$format'."));
|
||||
throw (new \Exception("The value '$date' is not a valid date for the format '$format'."));
|
||||
}
|
||||
return $date;
|
||||
}
|
||||
@@ -263,6 +263,40 @@ class Validator{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate is string
|
||||
* @var array $field. Field type string
|
||||
*
|
||||
* @access public
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
static public function isString($field, $nameField)
|
||||
{
|
||||
if (!is_string($field)) {
|
||||
throw (new \Exception("Invalid value for '$nameField' it must be a string."));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate is integer
|
||||
* @var array $field. Field type integer
|
||||
*
|
||||
* @access public
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
static public function isInteger($field, $nameField)
|
||||
{
|
||||
if (!is_integer($field)) {
|
||||
throw (new \Exception("Invalid value for '$nameField' it must be a integer."));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate is boolean
|
||||
* @var boolean $field. Field type boolean
|
||||
|
||||
@@ -1,928 +0,0 @@
|
||||
<?php
|
||||
namespace ProcessMaker\Adapter\Bpmn;
|
||||
|
||||
use \BpmnProject as Project;
|
||||
use \BpmnProcess as Process;
|
||||
use \BpmnDiagram as Diagram;
|
||||
use \BpmnLaneset as Laneset;
|
||||
use \BpmnLane as Lane;
|
||||
use \BpmnActivity as Activity;
|
||||
use \BpmnBound as Bound;
|
||||
use \BpmnEvent as Event;
|
||||
use \BpmnGateway as Gateway;
|
||||
use \BpmnFlow as Flow;
|
||||
use \BpmnArtifact as Artifact;
|
||||
|
||||
use \BpmnProjectPeer as ProjectPeer;
|
||||
use \BpmnProcessPeer as ProcessPeer;
|
||||
use \BpmnDiagramPeer as DiagramPeer;
|
||||
use \BpmnLanesetPeer as LanesetPeer;
|
||||
use \BpmnLanePeer as LanePeer;
|
||||
use \BpmnActivityPeer as ActivityPeer;
|
||||
use \BpmnBoundPeer as BoundPeer;
|
||||
use \BpmnEventPeer as EventPeer;
|
||||
use \BpmnGatewayPeer as GatewayPeer;
|
||||
use \BpmnFlowPeer as FlowPeer;
|
||||
use \BpmnArtifactPeer as ArtifactPeer;
|
||||
|
||||
use \ProcessMaker\Util\Hash;
|
||||
use \BasePeer;
|
||||
|
||||
use \ProcessMaker\Util\Logger;
|
||||
use System;
|
||||
|
||||
|
||||
/**
|
||||
* Class Model
|
||||
*
|
||||
* @package ProcessMaker\Adapter\Bpmn
|
||||
* @author Erik Amaru Ortiz <aortiz.erik@gmail.com, erik@colosa.com>
|
||||
*/
|
||||
class Model
|
||||
{
|
||||
private static $diagramElements = array(
|
||||
'act_uid' => 'activities',
|
||||
'evn_uid' => 'events',
|
||||
'flo_uid' => 'flows',
|
||||
'art_uid' => 'artifacts',
|
||||
'lns_uid' => 'laneset',
|
||||
'lan_uid' => 'lanes'
|
||||
);
|
||||
|
||||
public function createProject($data, $replaceUids = false)
|
||||
{
|
||||
$data = array_change_key_case($data, CASE_UPPER);
|
||||
$uids = array();
|
||||
$diagrams = array_key_exists('DIAGRAMS', $data) && is_array($data['DIAGRAMS'])
|
||||
&& count($data['DIAGRAMS']) > 0 ? $data['DIAGRAMS'] : null;
|
||||
$mapId = array();
|
||||
|
||||
/*
|
||||
* 1. Create a project record
|
||||
* 2. Create a default diagram record
|
||||
* 3. Create a default process record
|
||||
*/
|
||||
|
||||
$project = new Project();
|
||||
$project->fromArray($data, BasePeer::TYPE_FIELDNAME);
|
||||
|
||||
if (array_key_exists('PRJ_UID', $data)) {
|
||||
if ($replaceUids) {
|
||||
$oldPrjUid = $data['PRJ_UID'];
|
||||
$project->setPrjUid(Hash::generateUID());
|
||||
}
|
||||
} else {
|
||||
$project->setPrjUid(Hash::generateUID());
|
||||
}
|
||||
|
||||
$project->setPrjCreateDate(date("Y-m-d H:i:s"));
|
||||
$project->save();
|
||||
$prjUid = $project->getPrjUid();
|
||||
$prjName = $project->getPrjName();
|
||||
|
||||
if ($replaceUids) {
|
||||
$uids[] = array('old_uid' => $oldPrjUid, 'new_uid' => $prjUid, 'object' => 'project');
|
||||
}
|
||||
|
||||
/*if (! isset($diagrams)) {
|
||||
if ($replaceUids) {
|
||||
return $uids;
|
||||
} else {
|
||||
return self::loadProject($prjUid);
|
||||
}
|
||||
}*/
|
||||
|
||||
$diagram = new Diagram();
|
||||
|
||||
if (isset($diagrams) && array_key_exists('dia_uid', $diagrams[0])) {
|
||||
if ($replaceUids) {
|
||||
$oldDiaUid = $diagrams[0]['dia_uid'];
|
||||
$diagram->setDiaUid(Hash::generateUID());
|
||||
} else {
|
||||
$diagram->setDiaUid($diagrams[0]['dia_uid']);
|
||||
}
|
||||
} else {
|
||||
$diagram->setDiaUid(Hash::generateUID());
|
||||
}
|
||||
|
||||
$diagram->setPrjUid($prjUid);
|
||||
$diagram->setDiaName($prjName);
|
||||
$diagram->save();
|
||||
$diaUid = $diagram->getDiaUid();
|
||||
|
||||
if ($replaceUids) {
|
||||
$uids[] = array('old_uid' => (isset($oldDiaUid) ? $oldDiaUid : ''), 'new_uid' => $diaUid, 'object' => 'diagram');
|
||||
}
|
||||
|
||||
$process = new Process();
|
||||
|
||||
if (isset($diagrams) && array_key_exists('pro_uid', $diagrams[0])) {
|
||||
if ($replaceUids) {
|
||||
$oldProUid = $data['pro_uid'];
|
||||
$process->setProUid(Hash::generateUID());
|
||||
} else {
|
||||
$process->setProUid($diagrams[0]['pro_uid']);
|
||||
}
|
||||
} else {
|
||||
$process->setProUid(Hash::generateUID());
|
||||
}
|
||||
|
||||
$process->setPrjUid($prjUid);
|
||||
$process->setDiaUid($diaUid);
|
||||
$process->setProName($prjName);
|
||||
$process->save();
|
||||
$proUid = $process->getProUid();
|
||||
|
||||
if ($replaceUids) {
|
||||
$uids[] = array('old_uid' => (isset($oldProUid) ? $oldProUid : ''), 'new_uid' => $proUid, 'object' => 'project');
|
||||
}
|
||||
|
||||
|
||||
if (isset($diagrams)) {
|
||||
// By now, is thought create only one diagram for each project (1:1)
|
||||
$diagramData = (array) $diagrams[0];
|
||||
|
||||
// there is not a defined diagram to save
|
||||
$diagramUids = $this->createDiagram($prjUid, $proUid, $diaUid, $diagramData, $replaceUids);
|
||||
|
||||
if ($replaceUids) {
|
||||
$uids = array_merge($uids, $diagramUids);
|
||||
}
|
||||
}
|
||||
|
||||
if ($replaceUids) {
|
||||
return $uids;
|
||||
} else {
|
||||
return self::loadProject($prjUid);
|
||||
}
|
||||
}
|
||||
|
||||
private function createDiagram($prjUid, $proUid, $diaUid, $diagramData)
|
||||
{
|
||||
$uids = array();
|
||||
$mapId = array();
|
||||
|
||||
/*
|
||||
* 1. ensure that all related data of objects are defined, if not we define them as empty
|
||||
* 2. create all related objects
|
||||
*/
|
||||
|
||||
$lanesets = array_key_exists('laneset', $diagramData) ? $diagramData['laneset'] : array();
|
||||
$lanes = array_key_exists('lanes', $diagramData) ? $diagramData['lanes'] : array();
|
||||
$activities = array_key_exists('activities', $diagramData) ? $diagramData['activities'] : array();
|
||||
$events = array_key_exists('events', $diagramData) ? $diagramData['events'] : array();
|
||||
$gateways = array_key_exists('gateways', $diagramData) ? $diagramData['gateways'] : array();
|
||||
$flows = array_key_exists('flows', $diagramData) ? $diagramData['flows'] : array();
|
||||
$artifacts = array_key_exists('artifacts', $diagramData) ? $diagramData['artifacts'] : array();
|
||||
|
||||
foreach ($lanesets as $lanesetData) {
|
||||
$lanesetData = array_change_key_case((array) $lanesetData, CASE_UPPER);
|
||||
|
||||
$laneset = new Laneset();
|
||||
$laneset->fromArray($lanesetData, BasePeer::TYPE_FIELDNAME);
|
||||
$laneset->setLnsUid(Hash::generateUID());
|
||||
$laneset->setPrjUid($prjUid);
|
||||
$laneset->setProUid($proUid);
|
||||
$laneset->save();
|
||||
$lnsUid = $laneset->getLnsUid();
|
||||
$oldLnsUid = $lanesetData['LNS_UID'];
|
||||
|
||||
$uids[] = array('old_uid' => $oldLnsUid, 'new_uid' => $lnsUid, 'object' => 'laneset');
|
||||
$mapId['laneset'][$oldLnsUid] = $lnsUid;
|
||||
}
|
||||
|
||||
foreach ($lanes as $laneData) {
|
||||
$laneData = array_change_key_case((array) $laneData, CASE_UPPER);
|
||||
$oldLanUid = $laneData['LNS_UID'];
|
||||
|
||||
$lane = new Lane();
|
||||
$lane->fromArray($laneData, BasePeer::TYPE_FIELDNAME);
|
||||
$lane->setLanUid(Hash::generateUID());
|
||||
$lane->setPrjUid($prjUid);
|
||||
$lane->setLnsUid($mapId['laneset'][$oldLanUid]);
|
||||
$lane->save();
|
||||
$lanUid = $lane->getLanUid();
|
||||
|
||||
$uids[] = array('old_uid' => $oldLanUid, 'new_uid' => $lanUid, 'object' => 'lane');
|
||||
$mapId['lane'][$oldLanUid] = $lanUid;
|
||||
}
|
||||
|
||||
/*
|
||||
* 1. crate project related object
|
||||
* 2. crate bound record for each object created previously
|
||||
*/
|
||||
|
||||
foreach ($activities as $activityData) {
|
||||
$activityData = array_change_key_case((array) $activityData, CASE_UPPER);
|
||||
|
||||
$activity = new Activity();
|
||||
$activity->fromArray($activityData, BasePeer::TYPE_FIELDNAME);
|
||||
$activity->setActUid(Hash::generateUID());
|
||||
$activity->setPrjUid($prjUid);
|
||||
$activity->setProUid($proUid);
|
||||
$activity->save();
|
||||
|
||||
$actUid = $activity->getActUid();
|
||||
$oldActUid = $activityData['ACT_UID'];
|
||||
$uids[] = array('old_uid' => $oldActUid, 'new_uid' => $actUid, 'object' => 'activity');
|
||||
$mapId['activity'][$oldActUid] = $actUid;
|
||||
|
||||
$bound = new Bound();
|
||||
$bound->fromArray($activityData, BasePeer::TYPE_FIELDNAME);
|
||||
$bound->setBouUid(Hash::generateUID());
|
||||
$bound->setPrjUid($prjUid);
|
||||
$bound->setDiaUid($diaUid);
|
||||
$bound->setElementUid($activity->getActUid());
|
||||
$bound->setBouElementType(str_replace('Bpmn', 'bpmn', get_class($activity)));
|
||||
$bound->setBouElement('pm_canvas');
|
||||
$bound->setBouContainer('bpmnDiagram');
|
||||
$bound->save();
|
||||
}
|
||||
|
||||
foreach ($events as $eventData) {
|
||||
$eventData = array_change_key_case((array) $eventData, CASE_UPPER);
|
||||
|
||||
$event = new Event();
|
||||
$event->fromArray($eventData, BasePeer::TYPE_FIELDNAME);
|
||||
$event->setEvnUid(Hash::generateUID());
|
||||
$event->setPrjUid($prjUid);
|
||||
$event->setProUid($proUid);
|
||||
$event->save();
|
||||
|
||||
$evnUid = $event->getEvnUid();
|
||||
$oldEvnUid = $eventData['EVN_UID'];
|
||||
$uids[] = array('old_uid' => $oldEvnUid, 'new_uid' => $evnUid, 'object' => 'event');
|
||||
$mapId['event'][$oldEvnUid] = $evnUid;
|
||||
|
||||
$bound = new Bound();
|
||||
$bound->fromArray($eventData, BasePeer::TYPE_FIELDNAME);
|
||||
$bound->setBouUid(Hash::generateUID());
|
||||
$bound->setPrjUid($prjUid);
|
||||
$bound->setDiaUid($diaUid);
|
||||
$bound->setElementUid($event->getEvnUid());
|
||||
$bound->setBouElementType(str_replace('Bpmn', 'bpmn', get_class($activity)));
|
||||
$bound->setBouElement('pm_canvas');
|
||||
$bound->setBouContainer('bpmnDiagram');
|
||||
$bound->save();
|
||||
}
|
||||
|
||||
foreach ($gateways as $gatewayData) {
|
||||
$gatewayData = array_change_key_case((array) $gatewayData, CASE_UPPER);
|
||||
|
||||
// fix data
|
||||
if ($gatewayData['GAT_DIRECTION'] === null) {
|
||||
unset($gatewayData['GAT_DIRECTION']);
|
||||
}
|
||||
|
||||
$gateway = new Gateway();
|
||||
$gateway->fromArray($gatewayData, BasePeer::TYPE_FIELDNAME);
|
||||
$gateway->setGatUid(Hash::generateUID());
|
||||
$gateway->setPrjUid($prjUid);
|
||||
$gateway->setProUid($proUid);
|
||||
$gateway->save();
|
||||
|
||||
$gatUid = $gateway->getGatUid();
|
||||
$oldGatUid = $gatewayData['GAT_UID'];
|
||||
$uids[] = array('old_uid' => $oldGatUid, 'new_uid' => $gatUid, 'object' => 'gateway');
|
||||
$mapId['gateway'][$oldGatUid] = $gatUid;
|
||||
|
||||
$bound = new Bound();
|
||||
$bound->fromArray($gatewayData, BasePeer::TYPE_FIELDNAME);
|
||||
$bound->setBouUid(Hash::generateUID());
|
||||
$bound->setPrjUid($prjUid);
|
||||
$bound->setDiaUid($diaUid);
|
||||
$bound->setElementUid($gateway->getGatUid());
|
||||
$bound->setBouElementType(str_replace('Bpmn', 'bpmn', get_class($activity)));
|
||||
$bound->setBouElement('pm_canvas');
|
||||
$bound->setBouContainer('bpmnDiagram');
|
||||
$bound->save();
|
||||
}
|
||||
|
||||
foreach ($flows as $flowData) {
|
||||
$flowData = array_change_key_case((array) $flowData, CASE_UPPER);
|
||||
|
||||
$floState = json_encode($flowData['FLO_STATE']);
|
||||
unset($flowData['FLO_STATE']);
|
||||
|
||||
$flow = new Flow();
|
||||
$flow->fromArray($flowData, BasePeer::TYPE_FIELDNAME);
|
||||
$flow->setFloUid(Hash::generateUID());
|
||||
$flow->setPrjUid($prjUid);
|
||||
$flow->setDiaUid($diaUid);
|
||||
$flow->setFloState($floState);
|
||||
|
||||
switch ($flow->getFloElementOriginType()) {
|
||||
case 'bpmnEvent':
|
||||
$flow->setFloElementOrigin($mapId['event'][$flowData['FLO_ELEMENT_ORIGIN']]);
|
||||
break;
|
||||
case 'bpmnGateway':
|
||||
$flow->setFloElementOrigin($mapId['gateway'][$flowData['FLO_ELEMENT_ORIGIN']]);
|
||||
break;
|
||||
case 'bpmnActivity':
|
||||
$flow->setFloElementOrigin($mapId['activity'][$flowData['FLO_ELEMENT_ORIGIN']]);
|
||||
break;
|
||||
}
|
||||
|
||||
switch ($flow->getFloElementDestType()) {
|
||||
case 'bpmnEvent':
|
||||
$flow->setFloElementDest($mapId['event'][$flowData['FLO_ELEMENT_DEST']]);
|
||||
break;
|
||||
case 'bpmnGateway':
|
||||
$flow->setFloElementDest($mapId['gateway'][$flowData['FLO_ELEMENT_DEST']]);
|
||||
break;
|
||||
case 'bpmnActivity':
|
||||
$flow->setFloElementDest($mapId['activity'][$flowData['FLO_ELEMENT_DEST']]);
|
||||
break;
|
||||
}
|
||||
|
||||
$flow->save();
|
||||
|
||||
$floUid = $flow->getFloUid();
|
||||
$oldFloUid = $flowData['FLO_UID'];
|
||||
$uids[] = array('old_uid' => $oldFloUid, 'new_uid' => $floUid, 'object' => 'flow');
|
||||
}
|
||||
|
||||
foreach ($artifacts as $artifactData) {
|
||||
$artifactData = array_change_key_case((array) $artifactData, CASE_UPPER);
|
||||
|
||||
$artifact = new Artifact();
|
||||
$artifact->fromArray($artifactData, BasePeer::TYPE_FIELDNAME);
|
||||
$artifact->setArtUid(Hash::generateUID());
|
||||
$artifact->setPrjUid($prjUid);
|
||||
$artifact->setProUid($proUid);
|
||||
$artifact->save();
|
||||
|
||||
$artUid = $artifact->getFloUid();
|
||||
$oldArtUid = $artifactData['ART_UID'];
|
||||
$uids[] = array('old_uid' => $oldArtUid, 'new_uid' => $artUid, 'object' => 'artifact');
|
||||
}
|
||||
|
||||
return $uids;
|
||||
}
|
||||
|
||||
public static function loadProject($prjUid)
|
||||
{
|
||||
/*
|
||||
* 1. load object of project
|
||||
* 2. load object of process
|
||||
* 3. load object of diagram
|
||||
* 4. load collection of lanesets
|
||||
* 5. load collection of lanes
|
||||
* 6. load collection of activities
|
||||
* 7. load collection of events
|
||||
* 8. load collection of gateways
|
||||
* 9. load collection of flows
|
||||
* 10. load collection of artifacts
|
||||
* 11. compose project data structure
|
||||
*/
|
||||
|
||||
$project = self::getBpmnObjectBy('Project', ProjectPeer::PRJ_UID, $prjUid, true);
|
||||
|
||||
if (empty($project)) {
|
||||
throw new \RuntimeException("Project with id: $prjUid, doesn't exist. ");
|
||||
}
|
||||
|
||||
$process = self::getBpmnObjectBy('Process', ProcessPeer::PRJ_UID, $prjUid, true);
|
||||
$diagram = self::getBpmnObjectBy('Diagram', DiagramPeer::DIA_UID, $process['dia_uid'], true);
|
||||
|
||||
$project = array_change_key_case($project);
|
||||
|
||||
//if (! empty($diagram)) {
|
||||
$lanesets = self::getBpmnCollectionBy('Laneset', LanesetPeer::PRJ_UID, $prjUid, true);
|
||||
$lanes = self::getBpmnCollectionBy('Lane', LanePeer::PRJ_UID, $prjUid, true);
|
||||
|
||||
//$activities = self::getBpmnCollectionBy('Activity', ActivityPeer::PRJ_UID, $prjUid, true);
|
||||
$activities = Activity::getAll($prjUid, null, null, null, 'object', CASE_LOWER);
|
||||
//$activities = Activity::getAll(array('prjUid' => $prjUid, 'changeCaseTo' => CASE_LOWER));
|
||||
//print_r($activities); die;
|
||||
|
||||
$events = self::getBpmnCollectionBy('Event', EventPeer::PRJ_UID, $prjUid, true);
|
||||
$gateways = self::getBpmnCollectionBy('Gateway', GatewayPeer::PRJ_UID, $prjUid, true);
|
||||
$flows = self::getBpmnCollectionBy('Flow', FlowPeer::PRJ_UID, $prjUid, true);
|
||||
$artifacts = self::getBpmnCollectionBy('Artifact', ArtifactPeer::PRJ_UID, $prjUid, true);
|
||||
|
||||
// getting activity bound data
|
||||
foreach ($activities as $i => $activity) {
|
||||
$bound = self::getBpmnObjectBy('Bound', BoundPeer::ELEMENT_UID, $activity['act_uid'], true);
|
||||
|
||||
if (is_object($bound)) {
|
||||
$activities[$i] = array_merge($activities[$i], $bound);
|
||||
}
|
||||
}
|
||||
|
||||
// getting event bound data
|
||||
foreach ($events as $i => $event) {
|
||||
$bound = self::getBpmnObjectBy('Bound', BoundPeer::ELEMENT_UID, $event['evn_uid'], true);
|
||||
|
||||
if (is_object($bound)) {
|
||||
$events[$i] = array_merge($events[$i], $bound);
|
||||
}
|
||||
}
|
||||
|
||||
// getting gateway bound data
|
||||
foreach ($gateways as $i => $gateway) {
|
||||
$bound = self::getBpmnObjectBy('Bound', BoundPeer::ELEMENT_UID, $gateway['gat_uid'], true);
|
||||
|
||||
if (is_object($bound)) {
|
||||
$gateways[$i] = array_merge($gateways[$i], $bound);
|
||||
}
|
||||
}
|
||||
|
||||
$project['diagrams'] = array($diagram);
|
||||
$project['diagrams'][0]['pro_uid'] = $process['pro_uid'];
|
||||
$project['diagrams'][0]['laneset'] = $lanesets;
|
||||
$project['diagrams'][0]['lanes'] = $lanes;
|
||||
$project['diagrams'][0]['activities'] = $activities;
|
||||
$project['diagrams'][0]['events'] = $events;
|
||||
$project['diagrams'][0]['gateways'] = $gateways;
|
||||
$project['diagrams'][0]['flows'] = $flows;
|
||||
$project['diagrams'][0]['artifacts'] = $artifacts;
|
||||
//}
|
||||
|
||||
return $project;
|
||||
}
|
||||
|
||||
public static function loadProjects()
|
||||
{
|
||||
$projectsList = self::getAllBpmnCollectionFrom('Project', true);
|
||||
$projects = array();
|
||||
|
||||
foreach ($projectsList as $project) {
|
||||
$projects[] = self::loadProject($project['prj_uid']);
|
||||
}
|
||||
|
||||
return $projects;
|
||||
}
|
||||
|
||||
public static function updateProject($prjUid, $projectUpdated)
|
||||
{
|
||||
$project = ProjectPeer::retrieveByPK($prjUid);
|
||||
$project->setPrjName($projectUpdated['prj_name']);
|
||||
$project->setPrjUpdateDate(date("Y-m-d H:i:s"));
|
||||
$project->save();
|
||||
|
||||
//print_r($project->toArray());
|
||||
|
||||
$diagramData = $projectUpdated['diagrams'][0];
|
||||
|
||||
//print_r($diagramData); die;
|
||||
|
||||
$diagram = DiagramPeer::retrieveByPK($diagramData['dia_uid']);
|
||||
|
||||
if (! is_object($diagram)) {
|
||||
throw new \RuntimeException("Project's diagram with id: {$diagramData['dia_uid']}, doesn't exist.");
|
||||
}
|
||||
|
||||
if (array_key_exists('dia_name', $diagramData)) {
|
||||
$diagram->setDiaName($diagramData['dia_name']);
|
||||
}
|
||||
|
||||
if (!empty($diagramData['dia_is_closable'])) {
|
||||
$diagram->setDiaIsClosable($diagramData['dia_is_closable']);
|
||||
}
|
||||
|
||||
$diagram->save();
|
||||
|
||||
$processData = self::getBpmnObjectBy('Process', ProcessPeer::PRJ_UID, $prjUid, true);
|
||||
|
||||
//print_r($processData); die;
|
||||
|
||||
$process = ProcessPeer::retrieveByPK($processData['pro_uid']);
|
||||
|
||||
//print_r($process); die;
|
||||
|
||||
$process->setProName($process->getProName());
|
||||
$process->save();
|
||||
|
||||
$savedProject = self::loadProject($prjUid);
|
||||
$diff = self::getDiffFromProjects($savedProject, $projectUpdated);
|
||||
|
||||
$result = self::updateDiagram($prjUid, $process->getProUid(), $diff);
|
||||
|
||||
self::log("Method: ".__METHOD__, 'Returns: ', $result);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function updateDiagram($prjUid, $proUid, $diff)
|
||||
{
|
||||
self::log("Method: ".__METHOD__, 'Params: ', "\$prjUid: $prjUid", "\$proUid: $proUid", "\$diff:", $diff);
|
||||
|
||||
//return false;
|
||||
$uids = array();
|
||||
|
||||
/*
|
||||
* Updating Records
|
||||
*/
|
||||
foreach ($diff['updated'] as $element => $items) {
|
||||
foreach ($items as $data) {
|
||||
$data = array_change_key_case((array) $data, CASE_UPPER);
|
||||
|
||||
// the calls in switch sentence are setting and saving the related BpmnBound objects too,
|
||||
// because methods: save(), fromArray(), toArray() are beautifully extended
|
||||
|
||||
switch ($element) {
|
||||
case 'laneset':
|
||||
break;
|
||||
case 'lanes':
|
||||
break;
|
||||
case 'activities':
|
||||
$activity = ActivityPeer::retrieveByPk($data['ACT_UID']);
|
||||
|
||||
// fixing data
|
||||
//$data['ELEMENT_UID'] = $data['BOU_ELEMENT_UID'];
|
||||
//unset($data['BOU_ELEMENT_UID']);
|
||||
|
||||
$activity->fromArray($data);
|
||||
$activity->save();
|
||||
break;
|
||||
case 'events':
|
||||
$event = EventPeer::retrieveByPk($data['EVN_UID']);
|
||||
$event->fromArray($data);
|
||||
$event->save();
|
||||
break;
|
||||
case 'gateways':
|
||||
$gateway = GatewayPeer::retrieveByPk($data['GAT_UID']);
|
||||
$gateway->fromArray($data);
|
||||
$gateway->save();
|
||||
break;
|
||||
case 'flows':
|
||||
break;
|
||||
case 'artifacts':
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Deleting Records
|
||||
*/
|
||||
foreach ($diff['deleted'] as $element => $items) {
|
||||
foreach ($items as $uid) {
|
||||
$data = array_change_key_case((array) $data, CASE_UPPER);
|
||||
|
||||
switch ($element) {
|
||||
case 'laneset':
|
||||
break;
|
||||
case 'lanes':
|
||||
break;
|
||||
case 'activities':
|
||||
$activity = ActivityPeer::retrieveByPK($uid);
|
||||
$activity->delete();
|
||||
break;
|
||||
case 'events':
|
||||
break;
|
||||
case 'gateways':
|
||||
break;
|
||||
case 'flows':
|
||||
break;
|
||||
case 'artifacts':
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Creating new records
|
||||
*/
|
||||
foreach ($diff['new'] as $element => $items) {
|
||||
foreach ($items as $data) {
|
||||
$data = array_change_key_case((array) $data, CASE_UPPER);
|
||||
|
||||
switch ($element) {
|
||||
case 'laneset':
|
||||
break;
|
||||
case 'lanes':
|
||||
break;
|
||||
case 'activities':
|
||||
$uidData = array('old_uid' => $data['ACT_UID'], 'object' => 'Activity');
|
||||
|
||||
$activity = new Activity();
|
||||
$activity->fromArray($data, BasePeer::TYPE_FIELDNAME);
|
||||
$activity->setActUid(Hash::generateUID());
|
||||
$activity->setPrjUid($prjUid);
|
||||
$activity->setProUid($proUid);
|
||||
$activity->getBound()->setBouUid(Hash::generateUID());
|
||||
$activity->save();
|
||||
|
||||
$uidData['new_uid'] = $activity->getActUid();
|
||||
$uids[] = $uidData;
|
||||
break;
|
||||
case 'events':
|
||||
break;
|
||||
case 'gateways':
|
||||
break;
|
||||
case 'flows':
|
||||
break;
|
||||
case 'artifacts':
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $uids;
|
||||
}
|
||||
|
||||
public function deleteProject($prjUid)
|
||||
{
|
||||
$projectData = self::loadProject($prjUid);
|
||||
|
||||
// TODO first at all, make validation, the project can only deleted if there are not any started case for it
|
||||
|
||||
// Delete related objects
|
||||
$diagramData = $projectData['diagrams'][0];
|
||||
|
||||
foreach ($diagramData['flows'] as $data) {
|
||||
$flow = FlowPeer::retrieveByPK($data['flo_uid']);
|
||||
$flow->delete();
|
||||
}
|
||||
foreach ($diagramData['artifacts'] as $data) {
|
||||
$artifact = ArtifactPeer::retrieveByPK($data['art_uid']);
|
||||
$artifact->delete();
|
||||
}
|
||||
foreach ($diagramData['lanes'] as $data) {
|
||||
$lane = LanePeer::retrieveByPK($data['lan_uid']);
|
||||
$lane->delete();
|
||||
}
|
||||
foreach ($diagramData['laneset'] as $data) {
|
||||
$laneset = LanesetPeer::retrieveByPK($data['lns_uid']);
|
||||
$laneset->delete();
|
||||
}
|
||||
foreach ($diagramData['laneset'] as $data) {
|
||||
$laneset = LanesetPeer::retrieveByPK($data['lns_uid']);
|
||||
$laneset->delete();
|
||||
}
|
||||
foreach ($diagramData['activities'] as $data) {
|
||||
$activity = ActivityPeer::retrieveByPK($data['act_uid']);
|
||||
$activity->delete();
|
||||
}
|
||||
foreach ($diagramData['events'] as $data) {
|
||||
$event = EventPeer::retrieveByPK($data['evn_uid']);
|
||||
$event->delete();
|
||||
}
|
||||
foreach ($diagramData['gateways'] as $data) {
|
||||
$gateway = GatewayPeer::retrieveByPK($data['gat_uid']);
|
||||
$gateway->delete();
|
||||
}
|
||||
|
||||
$process = ProcessPeer::retrieveByPK($diagramData['pro_uid']);
|
||||
$process->delete();
|
||||
|
||||
$diagram = DiagramPeer::retrieveByPK($diagramData['dia_uid']);
|
||||
$diagram->delete();
|
||||
|
||||
$project = ProjectPeer::retrieveByPK($prjUid);
|
||||
$project->delete();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Others functions
|
||||
*/
|
||||
|
||||
public static function getDiffFromProjects($savedProject, $updatedProject)
|
||||
{
|
||||
// preparing target project
|
||||
$diagramElements = array(
|
||||
'act_uid' => 'activities',
|
||||
'evn_uid' => 'events',
|
||||
'flo_uid' => 'flows',
|
||||
'art_uid' => 'artifacts',
|
||||
'lns_uid' => 'laneset',
|
||||
'lan_uid' => 'lanes'
|
||||
);
|
||||
|
||||
// Getting Differences
|
||||
$newRecords = array();
|
||||
$newRecordsUids = array();
|
||||
$deletedRecords = array();
|
||||
$updatedRecords = array();
|
||||
|
||||
// Get new records
|
||||
foreach ($diagramElements as $key => $element) {
|
||||
if (! array_key_exists($element, $updatedProject['diagrams'][0])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/*print_r($savedProject['diagrams'][0][$element]);
|
||||
print_r($updatedProject['diagrams'][0][$element]);
|
||||
var_dump($key);*/
|
||||
|
||||
$arrayDiff = self::arrayDiff(
|
||||
$savedProject['diagrams'][0][$element],
|
||||
$updatedProject['diagrams'][0][$element],
|
||||
$key
|
||||
);
|
||||
|
||||
if (! empty($arrayDiff)) {
|
||||
$newRecordsUids[$element] = $arrayDiff;
|
||||
|
||||
foreach ($updatedProject['diagrams'][0][$element] as $item) {
|
||||
if (in_array($item[$key], $newRecordsUids[$element])) {
|
||||
$newRecords[$element][] = $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get deleted records
|
||||
foreach ($diagramElements as $key => $element) {
|
||||
if (! array_key_exists($element, $updatedProject['diagrams'][0])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$arrayDiff = self::arrayDiff(
|
||||
$updatedProject['diagrams'][0][$element],
|
||||
$savedProject['diagrams'][0][$element],
|
||||
$key
|
||||
);
|
||||
|
||||
if (! empty($arrayDiff)) {
|
||||
$deletedRecords[$element] = $arrayDiff;
|
||||
}
|
||||
}
|
||||
|
||||
// Get updated records
|
||||
$checksum = array();
|
||||
foreach ($diagramElements as $key => $element) {
|
||||
$checksum[$element] = self::getArrayChecksum($savedProject['diagrams'][0][$element], $key);
|
||||
}
|
||||
|
||||
|
||||
foreach ($diagramElements as $key => $element) {
|
||||
if (! array_key_exists($element, $updatedProject['diagrams'][0])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($updatedProject['diagrams'][0][$element] as $item) {
|
||||
if ((array_key_exists($element, $newRecordsUids) && in_array($item[$key], $newRecordsUids[$element])) ||
|
||||
(array_key_exists($element, $deletedRecords) && in_array($item[$key], $deletedRecords[$element]))
|
||||
) {
|
||||
// skip new or deleted records
|
||||
continue;
|
||||
}
|
||||
|
||||
if (self::getChecksum($item) !== $checksum[$element][$item[$key]]) {
|
||||
$updatedRecords[$element][] = $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$diff = array(
|
||||
'new' => $newRecords,
|
||||
'deleted' => $deletedRecords,
|
||||
'updated' => $updatedRecords
|
||||
);
|
||||
|
||||
return $diff;
|
||||
}
|
||||
|
||||
public static function getRelatedFlows($actUid)
|
||||
{
|
||||
$flows = array(
|
||||
'origin' => self::getBpmnCollectionBy('Flow', FlowPeer::FLO_ELEMENT_ORIGIN, $actUid, true),
|
||||
'dest' => self::getBpmnCollectionBy('Flow', FlowPeer::FLO_ELEMENT_DEST, $actUid, true)
|
||||
);
|
||||
|
||||
return $flows;
|
||||
}
|
||||
|
||||
|
||||
/*** Private Functions ***/
|
||||
|
||||
public static function getAllBpmnCollectionFrom($class, $changeCase = false)
|
||||
{
|
||||
$data = array();
|
||||
|
||||
$c = new \Criteria('workflow');
|
||||
//$c->add($field, $value);
|
||||
|
||||
$classPeer = 'Bpmn' . $class . 'Peer';
|
||||
$rs = $classPeer::doSelectRS($c);
|
||||
|
||||
$rs->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
while ($rs->next()) {
|
||||
$data[] = $changeCase ? array_change_key_case($rs->getRow(), CASE_LOWER) : $rs->getRow();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function select($select, $from, $where = '', $changeCase = false)
|
||||
{
|
||||
$data = array();
|
||||
|
||||
$c = new \Criteria('workflow');
|
||||
if ($select != '*') {
|
||||
if (is_array($select)) {
|
||||
foreach ($select as $column) {
|
||||
$c->addSelectColumn($column);
|
||||
}
|
||||
} else {
|
||||
$c->addSelectColumn($field);
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($where)) {
|
||||
foreach ($where as $column => $value) {
|
||||
$c->add($column, $value);
|
||||
}
|
||||
}
|
||||
|
||||
$classPeer = 'Bpmn' . $from . 'Peer';
|
||||
$rs = $classPeer::doSelectRS($c);
|
||||
|
||||
$rs->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
while ($rs->next()) {
|
||||
$data[] = $changeCase ? array_change_key_case($rs->getRow(), CASE_LOWER) : $rs->getRow();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getBpmnCollectionBy($class, $field, $value, $changeCase = false)
|
||||
{
|
||||
$data = array();
|
||||
|
||||
$c = new \Criteria('workflow');
|
||||
$c->add($field, $value);
|
||||
|
||||
$classPeer = 'Bpmn' . $class . 'Peer';
|
||||
$rs = $classPeer::doSelectRS($c);
|
||||
|
||||
$rs->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
while ($rs->next()) {
|
||||
$data[] = $changeCase ? array_change_key_case($rs->getRow(), CASE_LOWER) : $rs->getRow();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getBpmnObjectBy($class, $field, $value, $changeCase = false)
|
||||
{
|
||||
$record = self::getBpmnCollectionBy($class, $field, $value, $changeCase);
|
||||
|
||||
return empty($record) ? null : $record[0];
|
||||
}
|
||||
|
||||
private static function arrayDiff($list, $targetList, $key)
|
||||
{
|
||||
$uid = array();
|
||||
$diff = array();
|
||||
|
||||
foreach ($list as $item) {
|
||||
if (array_key_exists($key, $item)) {
|
||||
$uid[] = $item[$key];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($targetList as $item) {
|
||||
if (! in_array($item[$key], $uid)) {
|
||||
$diff[] = $item[$key];
|
||||
}
|
||||
}
|
||||
|
||||
return $diff;
|
||||
}
|
||||
|
||||
private static function getArrayChecksum($list, $key = null)
|
||||
{
|
||||
$checksum = array();
|
||||
|
||||
foreach ($list as $k => $item) {
|
||||
if (empty($key)) {
|
||||
$checksum[$k] = self::getChecksum($item);
|
||||
} else {
|
||||
$checksum[$item[$key]] = self::getChecksum($item);
|
||||
}
|
||||
}
|
||||
|
||||
return $checksum;
|
||||
}
|
||||
|
||||
private static function getChecksum($data)
|
||||
{
|
||||
if (! is_string($data)) {
|
||||
$data = ksort(var_export($data, true));
|
||||
}
|
||||
|
||||
return sha1($data);
|
||||
}
|
||||
|
||||
protected static function log()
|
||||
{
|
||||
if (System::isDebugMode()) {
|
||||
|
||||
$me = Logger::getInstance();
|
||||
$args = func_get_args();
|
||||
//array_unshift($args, 'Class '.__CLASS__.' ');
|
||||
|
||||
call_user_func_array(array($me, 'setLog'), $args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,185 +0,0 @@
|
||||
<?php
|
||||
namespace ProcessMaker\Adapter;
|
||||
|
||||
use \Process;
|
||||
use \ProcessMaker\Adapter\Bpmn\Model as BpmnModel;
|
||||
use \ProcessMaker\Util\Hash;
|
||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||
|
||||
/**
|
||||
* Class Workflow
|
||||
*
|
||||
* @package ProcessMaker\Adapter
|
||||
* @author Erik Amaru Ortiz <aortiz.erik@gmail.com, erik@colosa.com>
|
||||
*/
|
||||
class Workflow
|
||||
{
|
||||
public static function loadFromBpmnProject($prjUid)
|
||||
{
|
||||
$project = BpmnModel::getBpmnObjectBy('Project', \BpmnProjectPeer::PRJ_UID, $prjUid);
|
||||
|
||||
$process = array();
|
||||
$process['PRO_UID'] = $prjUid;
|
||||
$process['PRO_TITLE'] = $project['PRJ_NAME'];
|
||||
$process['PRO_DESCRIPTION'] = '';
|
||||
$process['PRO_CATEGORY'] = '';
|
||||
|
||||
$process['tasks'] = array();
|
||||
$process['routes'] = array();
|
||||
|
||||
$projectActivities = BpmnModel::getBpmnCollectionBy('Activity', \BpmnActivityPeer::PRJ_UID, $prjUid);
|
||||
|
||||
foreach ($projectActivities as $activity) {
|
||||
$activityBound = BpmnModel::getBpmnObjectBy('Bound', \BpmnBoundPeer::ELEMENT_UID, $activity['ACT_UID']);
|
||||
|
||||
$process['tasks'][] = array(
|
||||
'TAS_UID' => $activity['ACT_UID'],
|
||||
'TAS_TITLE' => $activity['ACT_NAME'],
|
||||
'TAS_DESCRIPTION' => $activity['ACT_NAME'],
|
||||
'TAS_POSX' => $activityBound['BOU_X'],
|
||||
'TAS_POSY' => $activityBound['BOU_Y'],
|
||||
'TAS_START' => (self::activityIsStartTask($activity['ACT_UID']) ? 'TRUE' : 'FALSE'),
|
||||
'_action' => 'CREATE'
|
||||
);
|
||||
|
||||
$process['routes'] = array_merge($process['routes'], self::getRoutesFromBpmnFlows($prjUid, $activity['ACT_UID']));
|
||||
}
|
||||
|
||||
return $process;
|
||||
}
|
||||
|
||||
private static function getRoutesFromBpmnFlows($prjUid, $actUid)
|
||||
{
|
||||
$flows = BpmnModel::select('*', 'Flow', array(
|
||||
\BpmnFlowPeer::FLO_ELEMENT_ORIGIN => $actUid,
|
||||
\BpmnFlowPeer::FLO_ELEMENT_ORIGIN_TYPE => 'bpmnActivity'
|
||||
));
|
||||
$routes = array();
|
||||
|
||||
foreach ($flows as $flow) {
|
||||
$fromUid = $flow['FLO_ELEMENT_ORIGIN'];
|
||||
|
||||
switch ($flow['FLO_TYPE']) {
|
||||
case 'SEQUENCE':
|
||||
break;
|
||||
default:
|
||||
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
|
||||
$routes[] = array(
|
||||
'ROU_UID' => $flow['FLO_UID'], //Hash::generateUID(),
|
||||
'PRO_UID' => $prjUid,
|
||||
'TAS_UID' => $fromUid,
|
||||
'ROU_NEXT_TASK' => $flow['FLO_ELEMENT_DEST'],
|
||||
'ROU_TYPE' => 'SEQUENTIAL',
|
||||
'_action' => 'CREATE'
|
||||
);
|
||||
break;
|
||||
case 'bpmnGateway':
|
||||
$gatUid = $flow['FLO_ELEMENT_DEST'];
|
||||
// if it is a gateway it can fork one or more routes
|
||||
$gatFlows = BpmnModel::getBpmnCollectionBy('Flow', \BpmnFlowPeer::FLO_ELEMENT_ORIGIN, $gatUid);
|
||||
|
||||
foreach ($gatFlows as $gatFlow) {
|
||||
switch ($gatFlow['FLO_ELEMENT_DEST_TYPE']) {
|
||||
case 'bpmnActivity':
|
||||
// getting gateway properties
|
||||
$gateway = BpmnModel::getBpmnObjectBy('Gateway', \BpmnGatewayPeer::GAT_UID, $gatUid);
|
||||
|
||||
switch ($gateway['GAT_TYPE']) {
|
||||
case 'SELECTION':
|
||||
$routeType = 'SELECT';
|
||||
break;
|
||||
case 'EVALUATION':
|
||||
$routeType = 'EVALUATE';
|
||||
break;
|
||||
case 'PARALLEL':
|
||||
$routeType = 'PARALLEL';
|
||||
break;
|
||||
case 'PARALLEL_EVALUATION':
|
||||
$routeType = 'PARALLEL-BY-EVALUATION';
|
||||
break;
|
||||
case 'PARALLEL_JOIN':
|
||||
$routeType = 'SEC-JOIN';
|
||||
break;
|
||||
default:
|
||||
throw new \LogicException(sprintf("Unsupported Gateway type: %s", $gateway['GAT_TYPE']));
|
||||
}
|
||||
|
||||
$routes[] = array(
|
||||
'ROU_UID' => $gatFlow['FLO_UID'], //Hash::generateUID(),
|
||||
'PRO_UID' => $prjUid,
|
||||
'TAS_UID' => $fromUid,
|
||||
'ROU_NEXT_TASK' => $gatFlow['FLO_ELEMENT_DEST'],
|
||||
'ROU_TYPE' => $routeType,
|
||||
'_action' => 'CREATE'
|
||||
);
|
||||
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'];
|
||||
$event = BpmnModel::getBpmnObjectBy('Event', \BpmnEventPeer::EVN_UID, $evnUid);
|
||||
|
||||
switch ($event['EVN_TYPE']) {
|
||||
case 'END':
|
||||
$routeType = 'SEQUENTIAL';
|
||||
$routes[] = array(
|
||||
'ROU_UID' => $flow['FLO_UID'], //Hash::generateUID(),
|
||||
'PRO_UID' => $prjUid,
|
||||
'TAS_UID' => $fromUid,
|
||||
'ROU_NEXT_TASK' => '-1',
|
||||
'ROU_TYPE' => $routeType,
|
||||
'_action' => 'CREATE'
|
||||
);
|
||||
break;
|
||||
default:
|
||||
throw new \LogicException("Invalid connection to Event object type");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $routes;
|
||||
}
|
||||
|
||||
private static function activityIsStartTask($actUid)
|
||||
{
|
||||
/*
|
||||
* 1. find bpmn flows related to target activity
|
||||
* 2. verify is the flow_element_origin_type is a BpmnEvent and it have a evn_type=start
|
||||
*/
|
||||
$selection = BpmnModel::select('*', 'Flow', array(
|
||||
\BpmnFlowPeer::FLO_ELEMENT_DEST => $actUid,
|
||||
\BpmnFlowPeer::FLO_ELEMENT_DEST_TYPE => 'bpmnActivity'
|
||||
));
|
||||
|
||||
foreach ($selection as $elementOrigin) {
|
||||
if ($elementOrigin['FLO_ELEMENT_ORIGIN_TYPE'] == 'bpmnEvent') {
|
||||
$event = BpmnModel::getBpmnObjectBy('Event', \BpmnEventPeer::EVN_UID, $elementOrigin['FLO_ELEMENT_ORIGIN']);
|
||||
|
||||
if ($event['EVN_TYPE'] == 'START') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ abstract class Exporter
|
||||
/**
|
||||
* Exporter version
|
||||
*/
|
||||
const VERSION = "2.0";
|
||||
const VERSION = "3.0";
|
||||
|
||||
/**
|
||||
* @var \ProcessMaker\Project\Adapter\BpmnWorkflow
|
||||
@@ -67,8 +67,8 @@ abstract class Exporter
|
||||
{
|
||||
$data = array();
|
||||
|
||||
$data["Metadata"] = $this->getMetadata();
|
||||
$data["Metadata"]["project_name"] = $this->getProjectName();
|
||||
$data["metadata"] = $this->getMetadata();
|
||||
$data["metadata"]["project_name"] = $this->getProjectName();
|
||||
|
||||
$bpmnStruct["ACTIVITY"] = \BpmnActivity::getAll($this->prjUid);
|
||||
$bpmnStruct["BOUND"] = \BpmnBound::getAll($this->prjUid);
|
||||
@@ -95,9 +95,9 @@ abstract class Exporter
|
||||
$workflowData["processCategory"] = empty($workflowData["processCategory"]) ? array() : $workflowData["processCategory"];
|
||||
|
||||
|
||||
$data["BPMN-Definition"] = $bpmnStruct;
|
||||
$data["Workflow-Definition"] = $workflowData;
|
||||
$data["Workflow-Files"] = array();
|
||||
$data["bpmn-definition"] = $bpmnStruct;
|
||||
$data["workflow-definition"] = $workflowData;
|
||||
$data["workflow-files"] = array();
|
||||
|
||||
// getting dynaforms
|
||||
$dynaforms = array();
|
||||
@@ -113,7 +113,7 @@ abstract class Exporter
|
||||
$htmlFile = PATH_DYNAFORM . $dynaform['DYN_FILENAME'] . '.html';
|
||||
|
||||
if (file_exists($htmlFile)) {
|
||||
$data["Workflow-Files"]["DYNAFORMS"][] = array(
|
||||
$data["workflow-files"]["DYNAFORMS"][] = array(
|
||||
"filename" => $dynaform['DYN_FILENAME'] . '.html',
|
||||
"filepath" => $dynaform['DYN_FILENAME'] . '.html',
|
||||
"file_content" => file_get_contents($htmlFile)
|
||||
@@ -132,7 +132,7 @@ abstract class Exporter
|
||||
foreach ($templatesFiles as $templatesFile) {
|
||||
if (is_dir($templatesFile)) continue;
|
||||
|
||||
$data["Workflow-Files"][$target][] = array(
|
||||
$data["workflow-files"][$target][] = array(
|
||||
"filename" => basename($templatesFile),
|
||||
"filepath" => str_replace($templatesDir, "", $templatesFile),
|
||||
"file_content" => file_get_contents($templatesFile)
|
||||
@@ -148,7 +148,7 @@ abstract class Exporter
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContainerName()
|
||||
public static function getContainerName()
|
||||
{
|
||||
return "ProcessMaker-Project";
|
||||
}
|
||||
|
||||
@@ -38,21 +38,20 @@ class XmlExporter extends Exporter
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
$this->rootNode = $this->dom->createElement($this->getContainerName());
|
||||
$this->rootNode = $this->dom->createElement(self::getContainerName());
|
||||
$this->rootNode->setAttribute("version", self::getVersion());
|
||||
$this->dom->appendChild($this->rootNode);
|
||||
|
||||
$data = $this->buildData();
|
||||
|
||||
// metadata set up
|
||||
$metadata = $data["Metadata"];
|
||||
$metadataNode = $this->dom->createElement("Metadata");
|
||||
$metadata = $data["metadata"];
|
||||
$metadataNode = $this->dom->createElement("metadata");
|
||||
|
||||
foreach ($metadata as $key => $value) {
|
||||
$metaNode = $this->dom->createElement("meta:$key");
|
||||
//$metaNode->setAttribute("key", $key);
|
||||
//$metaNode->setAttribute("value", $value);
|
||||
$metaNode->appendChild($this->dom->createTextNode($value));
|
||||
$metaNode = $this->dom->createElement("meta");
|
||||
$metaNode->setAttribute("key", $key);
|
||||
$metaNode->appendChild($this->getTextNode($value));
|
||||
$metadataNode->appendChild($metaNode);
|
||||
}
|
||||
|
||||
@@ -60,10 +59,10 @@ class XmlExporter extends Exporter
|
||||
// end setting metadata
|
||||
|
||||
// bpmn struct data set up
|
||||
$dbData = array("BPMN" => $data["BPMN-Definition"], "Workflow" => $data["Workflow-Definition"]);
|
||||
//file_put_contents("/home/erik/out.log", print_r($dbData, true)); die;
|
||||
$dbData = array("BPMN" => $data["bpmn-definition"], "workflow" => $data["workflow-definition"]);
|
||||
|
||||
foreach ($dbData as $sectionName => $sectionData) {
|
||||
$dataNode = $this->dom->createElement("Definition");
|
||||
$dataNode = $this->dom->createElement("definition");
|
||||
$dataNode->setAttribute("class", $sectionName);
|
||||
|
||||
foreach ($sectionData as $elementName => $elementData) {
|
||||
@@ -73,19 +72,10 @@ class XmlExporter extends Exporter
|
||||
foreach ($elementData as $recordData) {
|
||||
$recordNode = $this->dom->createElement("record");
|
||||
$recordData = array_change_key_case($recordData, CASE_LOWER);
|
||||
//var_dump($recordData); die;
|
||||
|
||||
|
||||
foreach ($recordData as $key => $value) {
|
||||
$columnNode = $this->dom->createElement($key);
|
||||
|
||||
if (preg_match('/^[\w\s\.]+$/', $value, $match) || empty($value)) {
|
||||
$textNode = $this->dom->createTextNode($value);
|
||||
} else {
|
||||
$textNode = $this->dom->createCDATASection($value);
|
||||
}
|
||||
|
||||
$columnNode->appendChild($textNode);
|
||||
$columnNode->appendChild($this->getTextNode($value));
|
||||
$recordNode->appendChild($columnNode);
|
||||
}
|
||||
|
||||
@@ -98,20 +88,16 @@ class XmlExporter extends Exporter
|
||||
$this->rootNode->appendChild($dataNode);
|
||||
}
|
||||
|
||||
$workflowFilesNode = $this->dom->createElement("Workflow-Files");
|
||||
$workflowFilesNode = $this->dom->createElement("workflow-files");
|
||||
|
||||
// workflow dynaforms files
|
||||
foreach ($data["Workflow-Files"] as $elementName => $elementData) {
|
||||
foreach ($data["workflow-files"] as $elementName => $elementData) {
|
||||
foreach ($elementData as $fileData) {
|
||||
$fileNode = $this->dom->createElement("file");
|
||||
$fileNode->setAttribute("target", strtolower($elementName));
|
||||
|
||||
$filenameNode = $this->dom->createElement("file_name");
|
||||
if (preg_match('/^[\w\s\.\-]+$/', $fileData["filename"], $match)) {
|
||||
$filenameNode->appendChild($this->dom->createTextNode($fileData["filename"]));
|
||||
} else {
|
||||
$filenameNode->appendChild($this->dom->createCDATASection($fileData["filename"]));
|
||||
}
|
||||
$filenameNode->appendChild($this->getTextNode($fileData["filename"]));
|
||||
$fileNode->appendChild($filenameNode);
|
||||
|
||||
$filepathNode = $this->dom->createElement("file_path");
|
||||
@@ -146,4 +132,13 @@ class XmlExporter extends Exporter
|
||||
$this->build();
|
||||
return $this->dom->saveXml();
|
||||
}
|
||||
|
||||
private function getTextNode($value)
|
||||
{
|
||||
if (preg_match('/^[\w\s\.\-]+$/', $value, $match)) {
|
||||
return $this->dom->createTextNode($value);
|
||||
} else {
|
||||
return $this->dom->createCDATASection($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,16 +24,66 @@ abstract class Importer
|
||||
const IMPORT_STAT_INVALID_SOURCE_FILE = 102;
|
||||
|
||||
|
||||
public abstract function import();
|
||||
public abstract function validateSource();
|
||||
public abstract function targetExists();
|
||||
public function import($option = self::IMPORT_OPTION_CREATE_NEW)
|
||||
{
|
||||
switch ($option) {
|
||||
case self::IMPORT_OPTION_CREATE_NEW:
|
||||
$this->prepare();
|
||||
$this->createNewProject();
|
||||
break;
|
||||
case self::IMPORT_OPTION_DISABLE_AND_CREATE_NEW:
|
||||
break;
|
||||
case self::IMPORT_OPTION_OVERWRITE:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the source file
|
||||
* @return mixed
|
||||
*/
|
||||
public function validateSource()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if the project already exists
|
||||
* @return mixed
|
||||
*/
|
||||
public function targetExists()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function createNewProject()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function updateProject()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function disableCurrentProject()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the temporal file save directory
|
||||
* @param $dirName
|
||||
*/
|
||||
public function setSaveDir($dirName)
|
||||
{
|
||||
$this->saveDir = rtrim($dirName, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the temporal file save directory
|
||||
* @return string
|
||||
*/
|
||||
public function getSaveDir()
|
||||
{
|
||||
if (empty($this->saveDir)) {
|
||||
@@ -43,11 +93,20 @@ abstract class Importer
|
||||
return $this->saveDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the temporal source file
|
||||
* @param $filename
|
||||
*/
|
||||
public function setSourceFile($filename)
|
||||
{
|
||||
$this->filename = $filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set source from Global Http Request resource
|
||||
* @param $varName
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function setSourceFromGlobals($varName)
|
||||
{
|
||||
/*[PROCESS_FILENAME] => Array
|
||||
@@ -77,6 +136,11 @@ abstract class Importer
|
||||
umask($oldUmask);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare for import, it makes all validations needed
|
||||
* @return int
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function prepare()
|
||||
{
|
||||
if ($this->validateSource() === false) {
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
<?php
|
||||
namespace ProcessMaker\Importer;
|
||||
|
||||
class WorkflowImporter extends Importer
|
||||
{
|
||||
public function validateSource()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function targetExists()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function import($option = self::IMPORT_OPTION_CREATE_NEW)
|
||||
{
|
||||
switch ($option) {
|
||||
case self::IMPORT_OPTION_CREATE_NEW:
|
||||
$this->prepare();
|
||||
$this->createNewProject();
|
||||
break;
|
||||
case self::IMPORT_OPTION_DISABLE_AND_CREATE_NEW:
|
||||
break;
|
||||
case self::IMPORT_OPTION_OVERWRITE:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function createNewProject()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function updateProject()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function disableCurrentProject()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,133 @@
|
||||
<?php
|
||||
namespace ProcessMaker\Importer;
|
||||
|
||||
class XmlImporter
|
||||
class XmlImporter extends Importer
|
||||
{
|
||||
public $filename = "";
|
||||
/**
|
||||
* @var \DOMDocument
|
||||
*/
|
||||
protected $dom;
|
||||
protected $root;
|
||||
protected $version = "";
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->dom = new \DOMDocument();
|
||||
}
|
||||
|
||||
public function setSourceFile($filename)
|
||||
{
|
||||
$this->filename = $filename;
|
||||
}
|
||||
|
||||
public function load()
|
||||
{
|
||||
$this->dom->load($this->filename);
|
||||
$this->root = $this->dom->documentElement;
|
||||
|
||||
// validate version
|
||||
$this->version = $this->root->getAttribute("version");
|
||||
|
||||
if (empty($this->version)) {
|
||||
throw new \Exception("ProcessMaker Project version is missing on file source.");
|
||||
}
|
||||
|
||||
// read metadata section
|
||||
$metadata = $this->root->getElementsByTagName("metadata");
|
||||
|
||||
if ($metadata->length != 1) {
|
||||
throw new \Exception("Invalid Document format, metadata section is missing or has multiple definition.");
|
||||
}
|
||||
|
||||
$metadata = $metadata->item(0);
|
||||
|
||||
// load project definition
|
||||
/** @var \DOMElement[]|\DomNodeList $definitions */
|
||||
$definitions = $this->root->getElementsByTagName("definition");
|
||||
|
||||
if ($definitions->length == 0) {
|
||||
throw new \Exception("Definition section is missing.");
|
||||
} elseif ($definitions->length < 2) {
|
||||
throw new \Exception("Definition section is incomplete.");
|
||||
}
|
||||
|
||||
$tables = array();
|
||||
|
||||
foreach ($definitions as $definition) {
|
||||
$defClass = strtoupper($definition->getAttribute("class"));
|
||||
$tables[$defClass] = array();
|
||||
|
||||
// getting tables def
|
||||
// first we need to know if the project already exists
|
||||
/** @var \DOMElement[] $tablesNodeList */
|
||||
$tablesNodeList = $definition->getElementsByTagName("table");
|
||||
|
||||
foreach ($tablesNodeList as $tableNode) {
|
||||
$tableName = strtoupper($tableNode->getAttribute("name"));
|
||||
$tables[$defClass][$tableName] = array();
|
||||
/** @var \DOMElement[] $recordsNodeList */
|
||||
$recordsNodeList = $tableNode->getElementsByTagName("record");
|
||||
|
||||
foreach ($recordsNodeList as $recordsNode) {
|
||||
if (! $recordsNode->hasChildNodes()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$columns = array();
|
||||
|
||||
foreach ($recordsNode->childNodes as $columnNode) {
|
||||
if ($columnNode->nodeName == "#text") continue;
|
||||
$columns[strtoupper($columnNode->nodeName)] = self::getNodeText($columnNode);;
|
||||
}
|
||||
|
||||
$tables[$defClass][$tableName][] = $columns;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$wfFilesNodeList = $this->root->getElementsByTagName("workflow-files");
|
||||
$wfFiles = array();
|
||||
|
||||
if ($wfFilesNodeList->length > 0) {
|
||||
$filesNodeList = $wfFilesNodeList->item(0)->getElementsByTagName("file");
|
||||
|
||||
foreach ($filesNodeList as $fileNode) {
|
||||
$target = $fileNode->getAttribute("target");
|
||||
|
||||
if (! isset($wfFiles[$target])) {
|
||||
$wfFiles[$target] = array();
|
||||
}
|
||||
|
||||
$fileContent = self::getNodeText($fileNode->getElementsByTagName("file_content")->item(0));
|
||||
$fileContent = base64_decode($fileContent);
|
||||
|
||||
$wfFiles[$target][] = array(
|
||||
"file_name" => self::getNodeText($fileNode->getElementsByTagName("file_name")->item(0)),
|
||||
"file_path" => self::getNodeText($fileNode->getElementsByTagName("file_path")->item(0)),
|
||||
"file_content" => $fileContent
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
print_r($tables);
|
||||
print_r($wfFiles);
|
||||
|
||||
|
||||
// load workflow definition
|
||||
// load workflow files
|
||||
}
|
||||
|
||||
public function import()
|
||||
{
|
||||
$this->load();
|
||||
}
|
||||
|
||||
private static function getNodeText($node)
|
||||
{
|
||||
if ($node->nodeType == XML_ELEMENT_NODE) {
|
||||
return $node->textContent;
|
||||
} else if ($node->nodeType == XML_TEXT_NODE || $node->nodeType == XML_CDATA_SECTION_NODE) {
|
||||
return (string) simplexml_import_dom($node->parentNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -12,16 +12,16 @@ use \Luracast\Restler\RestException;
|
||||
class InputDocument extends Api
|
||||
{
|
||||
/**
|
||||
* @url GET /:cas_uid/input-documents
|
||||
* @url GET /:app_uid/input-documents
|
||||
*
|
||||
* @param string $cas_uid {@min 32}{@max 32}
|
||||
* @param string $app_uid {@min 32}{@max 32}
|
||||
*/
|
||||
public function doGetInputDocuments($cas_uid)
|
||||
public function doGetInputDocuments($app_uid)
|
||||
{
|
||||
try {
|
||||
$userUid = $this->getUserId();
|
||||
$inputDocument = new \BusinessModel\Cases\InputDocument();
|
||||
$response = $inputDocument->getCasesInputDocuments($cas_uid, $userUid);
|
||||
$response = $inputDocument->getCasesInputDocuments($app_uid, $userUid);
|
||||
return $response;
|
||||
} catch (\Exception $e) {
|
||||
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
||||
@@ -29,17 +29,17 @@ class InputDocument extends Api
|
||||
}
|
||||
|
||||
/**
|
||||
* @url GET /:cas_uid/input-document/:inp_doc_uid
|
||||
* @url GET /:app_uid/input-document/:inp_doc_uid
|
||||
*
|
||||
* @param string $cas_uid {@min 32}{@max 32}
|
||||
* @param string $app_uid {@min 32}{@max 32}
|
||||
* @param string $inp_doc_uid {@min 32}{@max 32}
|
||||
*/
|
||||
public function doGetInputDocument($cas_uid, $inp_doc_uid)
|
||||
public function doGetInputDocument($app_uid, $inp_doc_uid)
|
||||
{
|
||||
try {
|
||||
$userUid = $this->getUserId();
|
||||
$inputDocument = new \BusinessModel\Cases\InputDocument();
|
||||
$response = $inputDocument->getCasesInputDocument($cas_uid, $userUid, $inp_doc_uid);
|
||||
$response = $inputDocument->getCasesInputDocument($app_uid, $userUid, $inp_doc_uid);
|
||||
return $response;
|
||||
} catch (\Exception $e) {
|
||||
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
||||
@@ -47,12 +47,12 @@ class InputDocument extends Api
|
||||
}
|
||||
|
||||
/**
|
||||
* @url DELETE /:cas_uid/input-document/:inp_doc_uid
|
||||
* @url DELETE /:app_uid/input-document/:inp_doc_uid
|
||||
*
|
||||
* @param string $cas_uid {@min 32}{@max 32}
|
||||
* @param string $app_uid {@min 32}{@max 32}
|
||||
* @param string $inp_doc_uid {@min 32}{@max 32}
|
||||
*/
|
||||
public function doDeleteInputDocument($cas_uid, $inp_doc_uid)
|
||||
public function doDeleteInputDocument($app_uid, $inp_doc_uid)
|
||||
{
|
||||
try {
|
||||
$inputDocument = new \BusinessModel\Cases\InputDocument();
|
||||
@@ -62,22 +62,21 @@ class InputDocument extends Api
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @url POST /:cas_uid/input-document
|
||||
* @url POST /:app_uid/input-document
|
||||
*
|
||||
* @param string $cas_uid {@min 32}{@max 32}
|
||||
* @param string $app_uid { @min 32}{@max 32}
|
||||
* @param string $tas_uid {@min 32}{@max 32}
|
||||
* @param string $inp_doc_uid {@min 32}{@max 32}
|
||||
*/
|
||||
public function doPostInputDocument($cas_uid, $inp_doc_uid)
|
||||
public function doPostInputDocument($app_uid, $tas_uid, $inp_doc_uid)
|
||||
{
|
||||
try {
|
||||
$userUid = $this->getUserId();
|
||||
$inputDocument = new \BusinessModel\Cases\InputDocument();
|
||||
$response = $inputDocument->addCasesInputDocument($cas_uid, $inp_doc_uid, $userUid);
|
||||
$response = $inputDocument->addCasesInputDocument($app_uid, $tas_uid, $inp_doc_uid, $userUid);
|
||||
return $response;
|
||||
} catch (\Exception $e) {
|
||||
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -12,16 +12,16 @@ use \Luracast\Restler\RestException;
|
||||
class OutputDocument extends Api
|
||||
{
|
||||
/**
|
||||
* @url GET /:cas_uid/output-documents
|
||||
* @url GET /:app_uid/output-documents
|
||||
*
|
||||
* @param string $cas_uid {@min 32}{@max 32}
|
||||
* @param string $app_uid {@min 32}{@max 32}
|
||||
*/
|
||||
public function doGetOutputDocuments($cas_uid)
|
||||
public function doGetOutputDocuments($app_uid)
|
||||
{
|
||||
try {
|
||||
$userUid = $this->getUserId();
|
||||
$outputDocument = new \BusinessModel\Cases\OutputDocument();
|
||||
$response = $outputDocument->getCasesOutputDocuments($cas_uid, $userUid);
|
||||
$response = $outputDocument->getCasesOutputDocuments($app_uid, $userUid);
|
||||
return $response;
|
||||
} catch (\Exception $e) {
|
||||
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
||||
@@ -29,17 +29,17 @@ class OutputDocument extends Api
|
||||
}
|
||||
|
||||
/**
|
||||
* @url GET /:cas_uid/output-document/:out_doc_uid
|
||||
* @url GET /:app_uid/output-document/:out_doc_uid
|
||||
*
|
||||
* @param string $cas_uid {@min 32}{@max 32}
|
||||
* @param string $app_uid {@min 32}{@max 32}
|
||||
* @param string $out_doc_uid {@min 32}{@max 32}
|
||||
*/
|
||||
public function doGetOutputDocument($cas_uid, $out_doc_uid)
|
||||
public function doGetOutputDocument($app_uid, $out_doc_uid)
|
||||
{
|
||||
try {
|
||||
$userUid = $this->getUserId();
|
||||
$outputDocument = new \BusinessModel\Cases\OutputDocument();
|
||||
$response = $outputDocument->getCasesOutputDocument($cas_uid, $userUid, $out_doc_uid);
|
||||
$response = $outputDocument->getCasesOutputDocument($app_uid, $userUid, $out_doc_uid);
|
||||
return $response;
|
||||
} catch (\Exception $e) {
|
||||
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
||||
@@ -47,12 +47,12 @@ class OutputDocument extends Api
|
||||
}
|
||||
|
||||
/**
|
||||
* @url DELETE /:cas_uid/output-document/:out_doc_uid
|
||||
* @url DELETE /:app_uid/output-document/:out_doc_uid
|
||||
*
|
||||
* @param string $cas_uid {@min 32}{@max 32}
|
||||
* @param string $app_uid {@min 32}{@max 32}
|
||||
* @param string $out_doc_uid {@min 32}{@max 32}
|
||||
*/
|
||||
public function doDeleteOutputDocument($cas_uid, $out_doc_uid)
|
||||
public function doDeleteOutputDocument($app_uid, $out_doc_uid)
|
||||
{
|
||||
try {
|
||||
$outputDocument = new \BusinessModel\Cases\OutputDocument();
|
||||
@@ -62,17 +62,17 @@ class OutputDocument extends Api
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @url POST /:cas_uid/output-document
|
||||
* @url POST /:app_uid/output-document
|
||||
*
|
||||
* @param string $cas_uid {@min 32}{@max 32}
|
||||
* @param string $app_uid {@min 32}{@max 32}
|
||||
* @param string $out_doc_uid {@min 32}{@max 32}
|
||||
*/
|
||||
public function doPostOutputDocument($cas_uid, $out_doc_uid)
|
||||
public function doPostOutputDocument($app_uid, $out_doc_uid)
|
||||
{
|
||||
try {
|
||||
$userUid = $this->getUserId();
|
||||
$outputDocument = new \BusinessModel\Cases\OutputDocument();
|
||||
$response = $outputDocument->addCasesOutputDocument($cas_uid, $out_doc_uid, $userUid);
|
||||
$response = $outputDocument->addCasesOutputDocument($app_uid, $out_doc_uid, $userUid);
|
||||
return $response;
|
||||
} catch (\Exception $e) {
|
||||
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
||||
|
||||
392
workflow/engine/src/Tests/BusinessModel/CasesActionTest13_17.php
Normal file
392
workflow/engine/src/Tests/BusinessModel/CasesActionTest13_17.php
Normal file
@@ -0,0 +1,392 @@
|
||||
<?php
|
||||
namespace Tests\BusinessModel;
|
||||
|
||||
if (!class_exists("Propel")) {
|
||||
include_once (__DIR__ . "/../bootstrap.php");
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Cases Test
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @protected
|
||||
* @package Tests\BusinessModel
|
||||
*/
|
||||
class CasesAction13_17Test extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $oCases;
|
||||
protected $nowCountTodo = 0;
|
||||
protected $nowCountDraft = 0;
|
||||
protected $nowCountPaused = 0;
|
||||
protected $idCaseToDo = '';
|
||||
protected $idCaseDraft = '';
|
||||
|
||||
/**
|
||||
* Set class for test
|
||||
*
|
||||
* @coversNothing
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
\G::loadClass('pmFunctions');
|
||||
|
||||
$usrUid = '00000000000000000000000000000001';
|
||||
$proUid = '2317283235320c1a36972b2028131767';
|
||||
$tasUid = '7983935495320c1a75e1df6068322280';
|
||||
$idCaseToDo = PMFNewCase($proUid, $usrUid, $tasUid, array());
|
||||
PMFDerivateCase($idCaseToDo, 1);
|
||||
$this->idCaseToDo = $idCaseToDo;
|
||||
|
||||
$idCaseDraft = PMFNewCase($proUid, $usrUid, $tasUid, array());
|
||||
$this->idCaseDraft = $idCaseDraft;
|
||||
|
||||
$this->oCases = new \BusinessModel\Cases();
|
||||
$listToDo = $this->oCases->getList(array('userId' => '00000000000000000000000000000001'));
|
||||
$this->nowCountTodo = $listToDo['total'];
|
||||
|
||||
$listDraft = $this->oCases->getList(array('userId' => '00000000000000000000000000000001', 'action' => 'draft'));
|
||||
$this->nowCountDraft = $listDraft['total'];
|
||||
|
||||
$listPaused = $this->oCases->getList(array('userId' => '00000000000000000000000000000001', 'action' => 'paused'));
|
||||
$this->nowCountPaused = $listPaused['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test error for type in first field the function
|
||||
*
|
||||
* @covers \BusinessModel\Cases::putCancelCase
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Invalid value for '$app_uid' it must be a string.
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function testPutCancelCaseErrorAppUidArray()
|
||||
{
|
||||
$this->oCases->putCancelCase(array(), '00000000000000000000000000000001');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test error for type in first field the function
|
||||
*
|
||||
* @covers \BusinessModel\Cases::putCancelCase
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The application with $app_uid: 'IdDoesNotExists' does not exist.
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function testPutCancelCaseErrorAppUidIncorrect()
|
||||
{
|
||||
$this->oCases->putCancelCase('IdDoesNotExists', '00000000000000000000000000000001');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test error for type in second field the function
|
||||
*
|
||||
* @covers \BusinessModel\Cases::putCancelCase
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Invalid value for '$usr_uid' it must be a string.
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function testPutCancelCaseErrorUsrUidArray()
|
||||
{
|
||||
$this->oCases->putCancelCase($this->idCaseDraft, array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test error for type in second field the function
|
||||
*
|
||||
* @covers \BusinessModel\Cases::putCancelCase
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The user with $usr_uid: 'IdDoesNotExists' does not exist.
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function testPutCancelCaseErrorUsrUidIncorrect()
|
||||
{
|
||||
$this->oCases->putCancelCase($this->idCaseDraft, 'IdDoesNotExists');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test error for type in third field the function
|
||||
*
|
||||
* @covers \BusinessModel\Cases::putCancelCase
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Invalid value for '$del_index' it must be a integer.
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function testPutCancelCaseErrorDelIndexIncorrect()
|
||||
{
|
||||
$this->oCases->putCancelCase($this->idCaseDraft, '00000000000000000000000000000001', 'string');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for cancel case
|
||||
*
|
||||
* @covers \BusinessModel\Cases::putCancelCase
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function testPutCancelCase()
|
||||
{
|
||||
$this->oCases->putCancelCase($this->idCaseDraft, '00000000000000000000000000000001');
|
||||
$this->oCases = new \BusinessModel\Cases();
|
||||
$listDraft = $this->oCases->getList(array('userId' => '00000000000000000000000000000001', 'action' => 'draft'));
|
||||
$this->assertNotEquals($this->nowCountDraft, $listDraft['total']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test error for type in first field the function
|
||||
*
|
||||
* @covers \BusinessModel\Cases::putPauseCase
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Invalid value for '$app_uid' it must be a string.
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function testPutPauseCaseErrorAppUidArray()
|
||||
{
|
||||
$this->oCases->putPauseCase(array(), '00000000000000000000000000000001');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test error for type in first field the function
|
||||
*
|
||||
* @covers \BusinessModel\Cases::putPauseCase
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The application with $app_uid: 'IdDoesNotExists' does not exist.
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function testPutPauseCaseErrorAppUidIncorrect()
|
||||
{
|
||||
$this->oCases->putPauseCase('IdDoesNotExists', '00000000000000000000000000000001');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test error for type in second field the function
|
||||
*
|
||||
* @covers \BusinessModel\Cases::putPauseCase
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Invalid value for '$usr_uid' it must be a string.
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function testPutPauseCaseErrorUsrUidArray()
|
||||
{
|
||||
$this->oCases->putPauseCase($this->idCaseDraft, array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test error for type in second field the function
|
||||
*
|
||||
* @covers \BusinessModel\Cases::putPauseCase
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The user with $usr_uid: 'IdDoesNotExists' does not exist.
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function testPutPauseCaseErrorUsrUidIncorrect()
|
||||
{
|
||||
$this->oCases->putPauseCase($this->idCaseDraft, 'IdDoesNotExists');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test error for type in third field the function
|
||||
*
|
||||
* @covers \BusinessModel\Cases::putPauseCase
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Invalid value for '$del_index' it must be a integer.
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function testPutPauseCaseErrorDelIndexIncorrect()
|
||||
{
|
||||
$this->oCases->putPauseCase($this->idCaseDraft, '00000000000000000000000000000001', 'string');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test error for type in fourth field the function
|
||||
*
|
||||
* @covers \BusinessModel\Cases::putPauseCase
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The value '2014-44-44' is not a valid date for the format 'Y-m-d'.
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function testPutPauseCaseErrorDateIncorrect()
|
||||
{
|
||||
$this->oCases->putPauseCase($this->idCaseDraft, '00000000000000000000000000000001', false, '2014-44-44');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for cancel case
|
||||
*
|
||||
* @covers \BusinessModel\Cases::putPauseCase
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function testPutPauseCase()
|
||||
{
|
||||
$this->oCases->putPauseCase($this->idCaseToDo, '00000000000000000000000000000001');
|
||||
$this->oCases = new \BusinessModel\Cases();
|
||||
$listPaused = $this->oCases->getList(array('userId' => '00000000000000000000000000000001', 'action' => 'paused'));
|
||||
$this->assertNotEquals($this->nowCountPaused, $listPaused['total']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test error for type in first field the function
|
||||
*
|
||||
* @covers \BusinessModel\Cases::putUnpauseCase
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Invalid value for '$app_uid' it must be a string.
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function testPutUnpauseCaseErrorAppUidArray()
|
||||
{
|
||||
$this->oCases->putUnpauseCase(array(), '00000000000000000000000000000001');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test error for type in first field the function
|
||||
*
|
||||
* @covers \BusinessModel\Cases::putUnpauseCase
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The application with $app_uid: 'IdDoesNotExists' does not exist.
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function testPutUnpauseCaseErrorAppUidIncorrect()
|
||||
{
|
||||
$this->oCases->putUnpauseCase('IdDoesNotExists', '00000000000000000000000000000001');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test error for type in second field the function
|
||||
*
|
||||
* @covers \BusinessModel\Cases::putUnpauseCase
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Invalid value for '$usr_uid' it must be a string.
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function testPutUnpauseCaseErrorUsrUidArray()
|
||||
{
|
||||
$this->oCases->putUnpauseCase($this->idCaseDraft, array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test error for type in second field the function
|
||||
*
|
||||
* @covers \BusinessModel\Cases::putUnpauseCase
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The user with $usr_uid: 'IdDoesNotExists' does not exist.
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function testPutUnpauseCaseErrorUsrUidIncorrect()
|
||||
{
|
||||
$this->oCases->putUnpauseCase($this->idCaseDraft, 'IdDoesNotExists');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test error for type in third field the function
|
||||
*
|
||||
* @covers \BusinessModel\Cases::putUnpauseCase
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Invalid value for '$del_index' it must be a integer.
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function testPutUnpauseCaseErrorDelIndexIncorrect()
|
||||
{
|
||||
$this->oCases->putUnpauseCase($this->idCaseDraft, '00000000000000000000000000000001', 'string');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for cancel case
|
||||
*
|
||||
* @covers \BusinessModel\Cases::putUnpauseCase
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function testPutUnpauseCase()
|
||||
{
|
||||
$this->oCases->putUnpauseCase($this->idCaseToDo, '00000000000000000000000000000001');
|
||||
$this->oCases = new \BusinessModel\Cases();
|
||||
$listPaused = $this->oCases->getList(array('userId' => '00000000000000000000000000000001', 'action' => 'paused'));
|
||||
$this->assertEquals($this->nowCountPaused, $listPaused['total']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test error for type in first field the function
|
||||
*
|
||||
* @covers \BusinessModel\Cases::deleteCase
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Invalid value for '$app_uid' it must be a string.
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function testDeleteCaseErrorAppUidArray()
|
||||
{
|
||||
$this->oCases->deleteCase(array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test error for type in first field the function
|
||||
*
|
||||
* @covers \BusinessModel\Cases::deleteCase
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The application with $app_uid: 'IdDoesNotExists' does not exist.
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function testDeleteCaseErrorAppUidIncorrect()
|
||||
{
|
||||
$this->oCases->deleteCase('IdDoesNotExists');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for cancel case
|
||||
*
|
||||
* @covers \BusinessModel\Cases::deleteCase
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function testDeleteCase()
|
||||
{
|
||||
$this->oCases->deleteCase($this->idCaseToDo);
|
||||
$this->oCases = new \BusinessModel\Cases();
|
||||
$listToDo = $this->oCases->getList(array('userId' => '00000000000000000000000000000001'));
|
||||
$this->assertNotEquals($this->nowCountTodo, $listToDo['total']);
|
||||
}
|
||||
}
|
||||
@@ -67,14 +67,14 @@ class CasesTest extends \PHPUnit_Framework_TestCase
|
||||
*
|
||||
* @covers \BusinessModel\Cases::getList
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The user with userId: 'UidInexistente' does not exist.
|
||||
* @expectedExceptionMessage The user with userId: 'IdDoesNotExists' does not exist.
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function testGetListCasesErrorNotExistsUserIdArray()
|
||||
{
|
||||
$this->oCases->getList(array('userId' => 'UidInexistente'));
|
||||
$this->oCases->getList(array('userId' => 'IdDoesNotExists'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,11 +87,124 @@ class CasesTest extends \PHPUnit_Framework_TestCase
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function testGetListCasesErrorIncorrectValueArray()
|
||||
public function testGetListCasesErrorIncorrectValueActionArray()
|
||||
{
|
||||
$this->oCases->getList(array('userId' => '00000000000000000000000000000001', 'action' => 'incorrect'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test error for incorrect value $process in array
|
||||
*
|
||||
* @covers \BusinessModel\Cases::getList
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The process with $pro_uid: 'IdDoesNotExists' does not exist.
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function testGetListCasesErrorIncorrectValueProUidArray()
|
||||
{
|
||||
$this->oCases->getList(array(
|
||||
'userId' => '00000000000000000000000000000001',
|
||||
'process' => 'IdDoesNotExists'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test error for incorrect value $process in array
|
||||
*
|
||||
* @covers \BusinessModel\Cases::getList
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The category with $cat_uid: 'IdDoesNotExists' does not exist.
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function testGetListCasesErrorIncorrectValueCatUidArray()
|
||||
{
|
||||
$this->oCases->getList(array(
|
||||
'userId' => '00000000000000000000000000000001',
|
||||
'category' => 'IdDoesNotExists'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test error for incorrect value $process in array
|
||||
*
|
||||
* @covers \BusinessModel\Cases::getList
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The user with $usr_uid: 'IdDoesNotExists' does not exist.
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function testGetListCasesErrorIncorrectValueUserArray()
|
||||
{
|
||||
$this->oCases->getList(array(
|
||||
'userId' => '00000000000000000000000000000001',
|
||||
'user' => 'IdDoesNotExists'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test error for incorrect value $process in array
|
||||
*
|
||||
* @covers \BusinessModel\Cases::getList
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The value '2014-44-44' is not a valid date for the format 'Y-m-d'.
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function testGetListCasesErrorIncorrectValueDateToArray()
|
||||
{
|
||||
$this->oCases->getList(array(
|
||||
'userId' => '00000000000000000000000000000001',
|
||||
'dateTo' => '2014-44-44'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test error for incorrect value $process in array
|
||||
*
|
||||
* @covers \BusinessModel\Cases::getList
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The value '2014-44-44' is not a valid date for the format 'Y-m-d'.
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function testGetListCasesErrorIncorrectValueDateFromArray()
|
||||
{
|
||||
$this->oCases->getList(array(
|
||||
'userId' => '00000000000000000000000000000001',
|
||||
'dateFrom' => '2014-44-44'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get list to do not paged
|
||||
*
|
||||
* @covers \BusinessModel\Cases::getList
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function testGetListCasesToDoNotPaged()
|
||||
{
|
||||
$response = $this->oCases->getList(array('userId' => '00000000000000000000000000000001', 'paged' => false));
|
||||
$this->assertTrue(is_array($response));
|
||||
$this->assertFalse(isset($response['data']));
|
||||
$this->assertFalse(isset($response['total']));
|
||||
$this->assertFalse(isset($response['start']));
|
||||
$this->assertFalse(isset($response['limit']));
|
||||
$this->assertFalse(isset($response['sort']));
|
||||
$this->assertFalse(isset($response['dir']));
|
||||
$this->assertFalse(isset($response['cat_uid']));
|
||||
$this->assertFalse(isset($response['pro_uid']));
|
||||
$this->assertFalse(isset($response['search']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get list to do
|
||||
*
|
||||
@@ -104,8 +217,38 @@ class CasesTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$response = $this->oCases->getList(array('userId' => '00000000000000000000000000000001'));
|
||||
$this->assertTrue(is_array($response));
|
||||
$this->assertTrue(is_numeric($response['totalCount']));
|
||||
$this->assertTrue(is_array($response['data']));
|
||||
$this->assertTrue(isset($response['total']));
|
||||
$this->assertTrue(isset($response['start']));
|
||||
$this->assertTrue(isset($response['limit']));
|
||||
$this->assertTrue(isset($response['sort']));
|
||||
$this->assertTrue(isset($response['dir']));
|
||||
$this->assertTrue(isset($response['cat_uid']));
|
||||
$this->assertTrue(isset($response['pro_uid']));
|
||||
$this->assertTrue(isset($response['search']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get list draft not paged
|
||||
*
|
||||
* @covers \BusinessModel\Cases::getList
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function testGetListCasesDraftNotPaged()
|
||||
{
|
||||
$response = $this->oCases->getList(array('userId' => '00000000000000000000000000000001', 'action' => 'draft', 'paged' => false));
|
||||
$this->assertTrue(is_array($response));
|
||||
$this->assertFalse(isset($response['data']));
|
||||
$this->assertFalse(isset($response['total']));
|
||||
$this->assertFalse(isset($response['start']));
|
||||
$this->assertFalse(isset($response['limit']));
|
||||
$this->assertFalse(isset($response['sort']));
|
||||
$this->assertFalse(isset($response['dir']));
|
||||
$this->assertFalse(isset($response['cat_uid']));
|
||||
$this->assertFalse(isset($response['pro_uid']));
|
||||
$this->assertFalse(isset($response['search']));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,8 +263,38 @@ class CasesTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$response = $this->oCases->getList(array('userId' => '00000000000000000000000000000001', 'action' => 'draft'));
|
||||
$this->assertTrue(is_array($response));
|
||||
$this->assertTrue(is_numeric($response['totalCount']));
|
||||
$this->assertTrue(is_array($response['data']));
|
||||
$this->assertTrue(isset($response['total']));
|
||||
$this->assertTrue(isset($response['start']));
|
||||
$this->assertTrue(isset($response['limit']));
|
||||
$this->assertTrue(isset($response['sort']));
|
||||
$this->assertTrue(isset($response['dir']));
|
||||
$this->assertTrue(isset($response['cat_uid']));
|
||||
$this->assertTrue(isset($response['pro_uid']));
|
||||
$this->assertTrue(isset($response['search']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get list participated not paged
|
||||
*
|
||||
* @covers \BusinessModel\Cases::getList
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function testGetListCasesParticipatedNotPaged()
|
||||
{
|
||||
$response = $this->oCases->getList(array('userId' => '00000000000000000000000000000001', 'action' => 'sent', 'paged' => false));
|
||||
$this->assertTrue(is_array($response));
|
||||
$this->assertFalse(isset($response['data']));
|
||||
$this->assertFalse(isset($response['total']));
|
||||
$this->assertFalse(isset($response['start']));
|
||||
$this->assertFalse(isset($response['limit']));
|
||||
$this->assertFalse(isset($response['sort']));
|
||||
$this->assertFalse(isset($response['dir']));
|
||||
$this->assertFalse(isset($response['cat_uid']));
|
||||
$this->assertFalse(isset($response['pro_uid']));
|
||||
$this->assertFalse(isset($response['search']));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,8 +309,38 @@ class CasesTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$response = $this->oCases->getList(array('userId' => '00000000000000000000000000000001', 'action' => 'sent'));
|
||||
$this->assertTrue(is_array($response));
|
||||
$this->assertTrue(is_numeric($response['totalCount']));
|
||||
$this->assertTrue(is_array($response['data']));
|
||||
$this->assertTrue(isset($response['total']));
|
||||
$this->assertTrue(isset($response['start']));
|
||||
$this->assertTrue(isset($response['limit']));
|
||||
$this->assertTrue(isset($response['sort']));
|
||||
$this->assertTrue(isset($response['dir']));
|
||||
$this->assertTrue(isset($response['cat_uid']));
|
||||
$this->assertTrue(isset($response['pro_uid']));
|
||||
$this->assertTrue(isset($response['search']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get list unassigned not paged
|
||||
*
|
||||
* @covers \BusinessModel\Cases::getList
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function testGetListCasesUnassignedNotPaged()
|
||||
{
|
||||
$response = $this->oCases->getList(array('userId' => '00000000000000000000000000000001', 'action' => 'unassigned', 'paged' => false));
|
||||
$this->assertTrue(is_array($response));
|
||||
$this->assertFalse(isset($response['data']));
|
||||
$this->assertFalse(isset($response['total']));
|
||||
$this->assertFalse(isset($response['start']));
|
||||
$this->assertFalse(isset($response['limit']));
|
||||
$this->assertFalse(isset($response['sort']));
|
||||
$this->assertFalse(isset($response['dir']));
|
||||
$this->assertFalse(isset($response['cat_uid']));
|
||||
$this->assertFalse(isset($response['pro_uid']));
|
||||
$this->assertFalse(isset($response['search']));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,8 +355,42 @@ class CasesTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$response = $this->oCases->getList(array('userId' => '00000000000000000000000000000001', 'action' => 'unassigned'));
|
||||
$this->assertTrue(is_array($response));
|
||||
$this->assertTrue(is_numeric($response['totalCount']));
|
||||
$this->assertTrue(is_array($response['data']));
|
||||
$this->assertTrue(isset($response['total']));
|
||||
$this->assertTrue(isset($response['start']));
|
||||
$this->assertTrue(isset($response['limit']));
|
||||
$this->assertTrue(isset($response['sort']));
|
||||
$this->assertTrue(isset($response['dir']));
|
||||
$this->assertTrue(isset($response['cat_uid']));
|
||||
$this->assertTrue(isset($response['pro_uid']));
|
||||
$this->assertTrue(isset($response['search']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get list search not paged
|
||||
*
|
||||
* @covers \BusinessModel\Cases::getList
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*/
|
||||
public function testGetListCasesSearchNotPaged()
|
||||
{
|
||||
$response = $this->oCases->getList(array('userId' => '00000000000000000000000000000001', 'action' => 'search', 'paged' => false));
|
||||
$this->assertTrue(is_array($response));
|
||||
$this->assertFalse(isset($response['data']));
|
||||
$this->assertFalse(isset($response['total']));
|
||||
$this->assertFalse(isset($response['start']));
|
||||
$this->assertFalse(isset($response['limit']));
|
||||
$this->assertFalse(isset($response['sort']));
|
||||
$this->assertFalse(isset($response['dir']));
|
||||
$this->assertFalse(isset($response['cat_uid']));
|
||||
$this->assertFalse(isset($response['pro_uid']));
|
||||
$this->assertFalse(isset($response['search']));
|
||||
$this->assertFalse(isset($response['app_status']));
|
||||
$this->assertFalse(isset($response['usr_uid']));
|
||||
$this->assertFalse(isset($response['date_from']));
|
||||
$this->assertFalse(isset($response['date_to']));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,8 +405,19 @@ class CasesTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$response = $this->oCases->getList(array('userId' => '00000000000000000000000000000001', 'action' => 'search'));
|
||||
$this->assertTrue(is_array($response));
|
||||
$this->assertTrue(is_numeric($response['totalCount']));
|
||||
$this->assertTrue(is_array($response['data']));
|
||||
$this->assertTrue(isset($response['total']));
|
||||
$this->assertTrue(isset($response['start']));
|
||||
$this->assertTrue(isset($response['limit']));
|
||||
$this->assertTrue(isset($response['sort']));
|
||||
$this->assertTrue(isset($response['dir']));
|
||||
$this->assertTrue(isset($response['cat_uid']));
|
||||
$this->assertTrue(isset($response['pro_uid']));
|
||||
$this->assertTrue(isset($response['search']));
|
||||
$this->assertTrue(isset($response['app_status']));
|
||||
$this->assertTrue(isset($response['usr_uid']));
|
||||
$this->assertTrue(isset($response['date_from']));
|
||||
$this->assertTrue(isset($response['date_to']));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user