2014-02-05 11:39:15 -04:00
|
|
|
<?php
|
|
|
|
|
namespace ProcessMaker\Project;
|
|
|
|
|
|
|
|
|
|
use \Criteria;
|
|
|
|
|
use \ResultSet;
|
|
|
|
|
|
|
|
|
|
use \Process;
|
|
|
|
|
use \Tasks;
|
|
|
|
|
use \Task;
|
|
|
|
|
use \Route;
|
|
|
|
|
use \RoutePeer;
|
|
|
|
|
|
2014-03-26 12:20:58 -04:00
|
|
|
use ProcessMaker\Util\Common;
|
2014-02-05 11:39:15 -04:00
|
|
|
use ProcessMaker\Exception;
|
2014-03-26 12:20:58 -04:00
|
|
|
use ProcessMaker\Util;
|
2014-02-05 11:39:15 -04:00
|
|
|
|
2014-02-10 13:09:50 -04:00
|
|
|
/**
|
|
|
|
|
* Class Workflow
|
|
|
|
|
*
|
|
|
|
|
* @package ProcessMaker\Project
|
|
|
|
|
* @author Erik Amaru Ortiz <aortiz.erik@gmail.com, erik@colosa.com>
|
|
|
|
|
*/
|
2014-02-05 11:39:15 -04:00
|
|
|
class Workflow extends Handler
|
|
|
|
|
{
|
|
|
|
|
protected $process;
|
|
|
|
|
protected $proUid;
|
|
|
|
|
|
|
|
|
|
protected $tasks = array();
|
|
|
|
|
protected $routes = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function __construct($data = null)
|
|
|
|
|
{
|
|
|
|
|
if (! is_null($data)) {
|
|
|
|
|
$this->create($data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-05 12:33:36 -04:00
|
|
|
public static function load($proUid)
|
2014-02-05 11:39:15 -04:00
|
|
|
{
|
2014-02-05 12:33:36 -04:00
|
|
|
$me = new self();
|
2014-02-05 11:39:15 -04:00
|
|
|
|
2014-02-05 12:33:36 -04:00
|
|
|
try {
|
|
|
|
|
$process = new Process();
|
|
|
|
|
$processData = $process->load($proUid);
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw new Exception\ProjectNotFound($me, $proUid);
|
2014-02-05 11:39:15 -04:00
|
|
|
}
|
|
|
|
|
|
2014-02-05 12:33:36 -04:00
|
|
|
$me->process = $processData;
|
|
|
|
|
$me->proUid = $processData["PRO_UID"];
|
2014-02-05 11:39:15 -04:00
|
|
|
|
2014-02-05 12:33:36 -04:00
|
|
|
return $me;
|
2014-02-05 11:39:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function create($data)
|
|
|
|
|
{
|
2014-02-12 17:01:19 -04:00
|
|
|
// setting defaults
|
2014-03-26 12:20:58 -04:00
|
|
|
$data['PRO_UID'] = array_key_exists('PRO_UID', $data) ? $data['PRO_UID'] : Common::generateUID();
|
2014-02-12 17:01:19 -04:00
|
|
|
$data['USR_UID'] = array_key_exists('PRO_CREATE_USER', $data) ? $data['PRO_CREATE_USER'] : null;
|
|
|
|
|
$data['PRO_TITLE'] = array_key_exists('PRO_TITLE', $data) ? trim($data['PRO_TITLE']) : "";
|
|
|
|
|
$data['PRO_CATEGORY'] = array_key_exists('PRO_CATEGORY', $data) ? $data['PRO_CATEGORY'] : "";
|
|
|
|
|
|
2014-02-05 11:39:15 -04:00
|
|
|
try {
|
2014-02-18 17:41:45 -04:00
|
|
|
self::log("Create Process with data:", $data);
|
2014-02-05 17:29:28 -04:00
|
|
|
|
|
|
|
|
//validate if process with specified name already exists
|
|
|
|
|
if (Process::existsByProTitle($data["PRO_TITLE"])) {
|
|
|
|
|
throw new Exception\ProjectAlreadyExists($this, $data["PRO_TITLE"]);
|
|
|
|
|
}
|
2014-02-05 11:39:15 -04:00
|
|
|
|
|
|
|
|
// Create project
|
|
|
|
|
$process = new Process();
|
|
|
|
|
$this->proUid = $process->create($data, false);
|
|
|
|
|
|
2014-02-05 17:29:28 -04:00
|
|
|
// Call Plugins
|
|
|
|
|
$pluginData['PRO_UID'] = $this->proUid;
|
|
|
|
|
$pluginData['PRO_TEMPLATE'] = empty($data["PRO_TEMPLATE"]) ? "" : $data["PRO_TEMPLATE"];
|
|
|
|
|
$pluginData['PROCESSMAP'] = null;
|
|
|
|
|
|
|
|
|
|
$pluginRegistry = \PMPluginRegistry::getSingleton();
|
|
|
|
|
$pluginRegistry->executeTriggers(PM_NEW_PROCESS_SAVE, $pluginData);
|
|
|
|
|
|
|
|
|
|
// Save Calendar ID for this process
|
|
|
|
|
if (! empty($data["PRO_CALENDAR"])) {
|
|
|
|
|
//G::LoadClass( "calendar" );
|
|
|
|
|
$calendar = new \Calendar();
|
|
|
|
|
$calendar->assignCalendarTo($this->proUid, $data["PRO_CALENDAR"], 'PROCESS');
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-11 16:55:50 -04:00
|
|
|
self::log("Create Process Success!");
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
|
|
|
|
throw $e;
|
2014-02-05 11:39:15 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function update()
|
|
|
|
|
{
|
|
|
|
|
// TODO: Implement update() method.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function remove()
|
|
|
|
|
{
|
2014-02-11 16:55:50 -04:00
|
|
|
try {
|
2014-02-18 17:41:45 -04:00
|
|
|
self::log("Remove Process with uid: {$this->proUid}");
|
2014-02-11 16:55:50 -04:00
|
|
|
$this->deleteProcess($this->proUid);
|
|
|
|
|
self::log("Remove Process Success!");
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
2014-02-05 11:39:15 -04:00
|
|
|
}
|
|
|
|
|
|
2014-02-12 17:01:19 -04:00
|
|
|
public static function removeIfExists($proUid)
|
|
|
|
|
{
|
|
|
|
|
$process = \ProcessPeer::retrieveByPK($proUid);
|
|
|
|
|
|
|
|
|
|
if ($process) {
|
|
|
|
|
$me = new self();
|
|
|
|
|
$me->proUid = $process->getProUid();
|
|
|
|
|
$me->remove();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-05 14:09:48 -04:00
|
|
|
public static function getList($start = null, $limit = null, $filter = "", $changeCaseTo = CASE_UPPER)
|
|
|
|
|
{
|
|
|
|
|
//return Project::getAll($start, $limit, $filter, $changeCaseTo);
|
|
|
|
|
$process = new Process();
|
|
|
|
|
$processes = $process->getAllProcesses( $start, $limit, "", "");
|
|
|
|
|
//$processes = $process->getAll();
|
|
|
|
|
|
2014-02-26 12:53:17 -04:00
|
|
|
if ($changeCaseTo != CASE_UPPER) {
|
|
|
|
|
foreach ($processes as $i => $processRow) {
|
|
|
|
|
$processes[$i] = array_change_key_case($processRow, $changeCaseTo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-05 14:09:48 -04:00
|
|
|
return $processes;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-05 12:33:36 -04:00
|
|
|
public function getUid()
|
2014-02-05 11:39:15 -04:00
|
|
|
{
|
2014-02-05 14:09:48 -04:00
|
|
|
if (empty($this->proUid)) {
|
2014-02-05 12:33:36 -04:00
|
|
|
throw new \RuntimeException("Error: There is not an initialized project.");
|
|
|
|
|
}
|
2014-02-05 11:39:15 -04:00
|
|
|
|
2014-02-05 12:33:36 -04:00
|
|
|
return $this->proUid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getProcess()
|
|
|
|
|
{
|
|
|
|
|
if (empty($this->proUid)) {
|
|
|
|
|
throw new \Exception("Error: There is not an initialized project.");
|
2014-02-05 11:39:15 -04:00
|
|
|
}
|
|
|
|
|
|
2014-02-05 12:33:36 -04:00
|
|
|
$process = new Process();
|
2014-02-05 11:39:15 -04:00
|
|
|
|
2014-02-05 12:33:36 -04:00
|
|
|
return $process->load($this->proUid);
|
2014-02-05 11:39:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Projects elements handlers
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public function addTask($taskData)
|
|
|
|
|
{
|
|
|
|
|
// Setting defaults
|
2014-03-26 12:20:58 -04:00
|
|
|
$taskData['TAS_UID'] = array_key_exists('TAS_UID', $taskData) ? $taskData['TAS_UID'] : Common::generateUID();
|
2014-02-05 11:39:15 -04:00
|
|
|
$taskData['PRO_UID'] = $this->proUid;
|
|
|
|
|
|
2014-02-06 16:21:46 -04:00
|
|
|
try {
|
2014-02-18 17:41:45 -04:00
|
|
|
self::log("Add Task with data: ", $taskData);
|
2014-02-06 16:21:46 -04:00
|
|
|
$task = new Task();
|
|
|
|
|
$tasUid = $task->create($taskData, false);
|
|
|
|
|
self::log("Add Task Success!");
|
2014-03-26 12:20:58 -04:00
|
|
|
|
|
|
|
|
// SubProcess Handling
|
|
|
|
|
if ($task->getTasType() == "SUBPROCESS") {
|
|
|
|
|
$this->addSubProcess($this->proUid, $tasUid);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-06 16:21:46 -04:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
2014-02-05 11:39:15 -04:00
|
|
|
|
2014-02-06 16:21:46 -04:00
|
|
|
return $tasUid;
|
2014-02-05 11:39:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function updateTask($tasUid, $taskData)
|
|
|
|
|
{
|
2014-02-06 16:21:46 -04:00
|
|
|
try {
|
2014-02-18 17:41:45 -04:00
|
|
|
self::log("Update Task: $tasUid", "With data: ", $taskData);
|
2014-02-06 16:21:46 -04:00
|
|
|
$task = new Task();
|
|
|
|
|
$taskData['TAS_UID'] = $tasUid;
|
|
|
|
|
$result = $task->update($taskData);
|
|
|
|
|
self::log("Update Task Success!");
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
2014-02-05 11:39:15 -04:00
|
|
|
|
2014-02-06 16:21:46 -04:00
|
|
|
return $result;
|
2014-02-05 11:39:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function removeTask($tasUid)
|
|
|
|
|
{
|
2014-02-06 16:21:46 -04:00
|
|
|
try {
|
2014-02-18 17:41:45 -04:00
|
|
|
self::log("Remove Task: $tasUid");
|
2014-03-26 12:20:58 -04:00
|
|
|
$task = \TaskPeer::retrieveByPK($tasUid);
|
|
|
|
|
$tasType = $task->getTasType();
|
|
|
|
|
|
2014-02-25 13:47:59 -04:00
|
|
|
$task = new Tasks();
|
|
|
|
|
$task->deleteTask($tasUid);
|
2014-02-06 16:21:46 -04:00
|
|
|
self::log("Remove Task Success!");
|
2014-03-26 12:20:58 -04:00
|
|
|
|
|
|
|
|
if ($tasType == "SUBPROCESS") {
|
|
|
|
|
$this->removeSupProcess($this->proUid, $tasUid);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-06 16:21:46 -04:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
2014-02-05 11:39:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getTask($tasUid)
|
|
|
|
|
{
|
2014-02-27 15:51:42 -04:00
|
|
|
try {
|
|
|
|
|
$task = new Task();
|
|
|
|
|
$taskData = $task->load($tasUid);
|
|
|
|
|
} catch (\Exception $e){
|
|
|
|
|
$taskData = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $taskData;
|
2014-02-05 11:39:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-02-27 15:51:42 -04:00
|
|
|
/**
|
|
|
|
|
* @return array()
|
|
|
|
|
*/
|
2014-02-05 11:39:15 -04:00
|
|
|
public function getTasks()
|
|
|
|
|
{
|
|
|
|
|
if (empty($this->proUid)) {
|
2014-02-27 15:51:42 -04:00
|
|
|
return array();
|
2014-02-05 11:39:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$tasks = new Tasks();
|
|
|
|
|
|
|
|
|
|
return $tasks->getAllTasks($this->proUid);
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-26 12:20:58 -04:00
|
|
|
public function addSubProcess($proUid = '', $tasUid)//$iX = 0, $iY = 0)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$subProcess = new \SubProcess();
|
|
|
|
|
$data = array(
|
|
|
|
|
'SP_UID' => Util\Common::generateUID(),
|
|
|
|
|
'PRO_UID' => 0,
|
|
|
|
|
'TAS_UID' => 0,
|
|
|
|
|
'PRO_PARENT' => $proUid,
|
|
|
|
|
'TAS_PARENT' => $tasUid,
|
|
|
|
|
'SP_TYPE' => 'SIMPLE',
|
|
|
|
|
'SP_SYNCHRONOUS' => 0,
|
|
|
|
|
'SP_SYNCHRONOUS_TYPE' => 'ALL',
|
|
|
|
|
'SP_SYNCHRONOUS_WAIT' => 0,
|
|
|
|
|
'SP_VARIABLES_OUT' => '',
|
|
|
|
|
'SP_VARIABLES_IN' => '',
|
|
|
|
|
'SP_GRID_IN' => ''
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
self::log("Adding SubProcess with data: ", $data);
|
|
|
|
|
$spUid = $subProcess->create($data);
|
|
|
|
|
self::log("Adding SubProcess success!, created sp_uid: ", $spUid);
|
|
|
|
|
|
|
|
|
|
return $spUid;
|
|
|
|
|
} catch (\Exception $oError) {
|
|
|
|
|
throw ($oError);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function removeSupProcess($proUid, $tasUid)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$subProcess = \SubProcess::findByParents($proUid, $tasUid);
|
|
|
|
|
self::log("Remove SupProcess: ".$subProcess->getSpUid());
|
|
|
|
|
$subProcess->delete();
|
|
|
|
|
self::log("Remove SupProcess Success!");
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function updateSubProcess()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 19:11:34 -04:00
|
|
|
/**
|
|
|
|
|
* @param string $tasUid
|
|
|
|
|
* @param bool $value
|
|
|
|
|
*/
|
2014-02-12 17:01:19 -04:00
|
|
|
public function setStartTask($tasUid, $value = true)
|
2014-02-05 11:39:15 -04:00
|
|
|
{
|
2014-02-12 17:01:19 -04:00
|
|
|
$value = $value ? "TRUE" : "FALSE";
|
|
|
|
|
|
|
|
|
|
self::log("Setting Start Task with Uid: $tasUid: $value");
|
2014-02-05 11:39:15 -04:00
|
|
|
$task = \TaskPeer::retrieveByPK($tasUid);
|
2014-02-12 17:01:19 -04:00
|
|
|
$task->setTasStart($value);
|
2014-02-05 11:39:15 -04:00
|
|
|
$task->save();
|
2014-02-12 17:01:19 -04:00
|
|
|
self::log("Setting Start Task -> $value, Success!");
|
2014-02-05 11:39:15 -04:00
|
|
|
}
|
|
|
|
|
|
2014-02-28 19:11:34 -04:00
|
|
|
/**
|
|
|
|
|
* @param string $tasUid
|
|
|
|
|
* @param bool $value
|
|
|
|
|
*/
|
2014-02-12 17:01:19 -04:00
|
|
|
public function setEndTask($tasUid, $value = true)
|
2014-02-05 11:39:15 -04:00
|
|
|
{
|
2014-02-12 17:01:19 -04:00
|
|
|
self::log("Setting End Task with Uid: $tasUid: " . ($value ? "TRUE" : "FALSE"));
|
|
|
|
|
if ($value) {
|
|
|
|
|
$this->addSequentialRoute($tasUid, "-1");
|
|
|
|
|
} else {
|
|
|
|
|
$route = \Route::findOneBy(array(
|
|
|
|
|
\RoutePeer::TAS_UID => $tasUid,
|
|
|
|
|
\RoutePeer::ROU_NEXT_TASK => "-1"
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
if (! is_null($route)) {
|
|
|
|
|
$this->removeRoute($route->getRouUid());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
self::log("Setting End Task -> ".($value ? "TRUE" : "FALSE").", Success!");
|
2014-02-05 11:39:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addSequentialRoute($fromTasUid, $toTasUid, $delete = null)
|
|
|
|
|
{
|
|
|
|
|
$this->addRoute($fromTasUid, $toTasUid, "SEQUENTIAL", $delete);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addSelectRoute($fromTasUid, array $toTasks, $delete = null)
|
|
|
|
|
{
|
|
|
|
|
foreach ($toTasks as $toTasUid) {
|
|
|
|
|
$this->addRoute($fromTasUid, $toTasUid, "SELECT", $delete);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-25 11:30:56 -04:00
|
|
|
/**
|
|
|
|
|
* This method add a new or update a Route record
|
|
|
|
|
*
|
|
|
|
|
* @param $fromTasUid
|
|
|
|
|
* @param $toTasUid
|
|
|
|
|
* @param $type
|
|
|
|
|
* @param string $condition
|
|
|
|
|
* @return string
|
|
|
|
|
* @throws \Exception
|
|
|
|
|
*/
|
2014-02-26 17:38:07 -04:00
|
|
|
public function addRoute($fromTasUid, $toTasUid, $type, $condition = "")
|
2014-02-05 11:39:15 -04:00
|
|
|
{
|
2014-02-06 21:26:06 -04:00
|
|
|
try {
|
|
|
|
|
$validTypes = array("SEQUENTIAL", "SELECT", "EVALUATE", "PARALLEL", "PARALLEL-BY-EVALUATION", "SEC-JOIN", "DISCRIMINATOR");
|
|
|
|
|
|
|
|
|
|
if (! in_array($type, $validTypes)) {
|
|
|
|
|
throw new \Exception("Invalid Route type, given: $type, expected: [".implode(",", $validTypes)."]");
|
2014-02-05 11:39:15 -04:00
|
|
|
}
|
|
|
|
|
|
2014-02-06 21:26:06 -04:00
|
|
|
if ($type != 'SEQUENTIAL' && $type != 'SEC-JOIN' && $type != 'DISCRIMINATOR') {
|
2014-02-25 13:47:59 -04:00
|
|
|
//if ($this->getNumberOfRoutes($this->proUid, $fromTasUid, $toTasUid, $type) > 0) {
|
|
|
|
|
//throw new \LogicException("Unexpected behaviour");
|
|
|
|
|
//}
|
2014-02-06 21:26:06 -04:00
|
|
|
}
|
2014-02-05 11:39:15 -04:00
|
|
|
|
2014-03-25 11:30:56 -04:00
|
|
|
//if ($type == 'SEQUENTIAL' || $type == 'SEC-JOIN' || $type == 'DISCRIMINATOR') {
|
2014-02-25 13:47:59 -04:00
|
|
|
//$oTasks = new Tasks();
|
|
|
|
|
//$oTasks->deleteAllRoutesOfTask($this->proUid, $fromTasUid);
|
2014-02-12 17:01:19 -04:00
|
|
|
//}
|
2014-02-05 11:39:15 -04:00
|
|
|
|
2014-03-25 11:30:56 -04:00
|
|
|
$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
|
|
|
|
|
));
|
|
|
|
|
}
|
2014-02-06 21:26:06 -04:00
|
|
|
|
2014-02-11 16:55:50 -04:00
|
|
|
return $result;
|
2014-02-06 21:26:06 -04:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
|
|
|
|
throw $e;
|
2014-02-05 11:39:15 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-25 13:47:59 -04:00
|
|
|
public function resetTaskRoutes($actUid)
|
|
|
|
|
{
|
|
|
|
|
$oTasks = new Tasks();
|
|
|
|
|
$oTasks->deleteAllRoutesOfTask($this->proUid, $actUid);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-05 11:39:15 -04:00
|
|
|
public function updateRoute($rouUid, $routeData)
|
|
|
|
|
{
|
|
|
|
|
$routeData['ROU_UID'] = $rouUid;
|
2014-02-11 16:55:50 -04:00
|
|
|
|
|
|
|
|
try {
|
2014-02-18 17:41:45 -04:00
|
|
|
self::log("Update Route: $rouUid with data:", $routeData);
|
2014-02-11 16:55:50 -04:00
|
|
|
$route = new Route();
|
2014-03-25 11:30:56 -04:00
|
|
|
$result = $route->update($routeData);
|
2014-02-11 16:55:50 -04:00
|
|
|
self::log("Update Route Success!");
|
2014-03-25 11:30:56 -04:00
|
|
|
|
|
|
|
|
return $result;
|
2014-02-11 16:55:50 -04:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
2014-02-05 11:39:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function removeRoute($rouUid)
|
|
|
|
|
{
|
2014-02-11 16:55:50 -04:00
|
|
|
try {
|
2014-02-18 17:41:45 -04:00
|
|
|
self::log("Remove Route: $rouUid");
|
2014-02-11 16:55:50 -04:00
|
|
|
$route = new Route();
|
|
|
|
|
$result = $route->remove($rouUid);
|
|
|
|
|
self::log("Remove Route Success!");
|
2014-02-05 11:39:15 -04:00
|
|
|
|
2014-02-11 16:55:50 -04:00
|
|
|
return $result;
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
2014-02-05 11:39:15 -04:00
|
|
|
}
|
|
|
|
|
|
2014-02-24 19:10:45 -04:00
|
|
|
public function removeRouteFromTo($fromTasUid, $toTasUid)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
self::log("Remove Route from $fromTasUid -> to $toTasUid");
|
|
|
|
|
|
|
|
|
|
$route = Route::findOneBy(array(
|
|
|
|
|
RoutePeer::TAS_UID => $fromTasUid,
|
|
|
|
|
RoutePeer::ROU_NEXT_TASK => $toTasUid
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
$route->delete();
|
|
|
|
|
self::log("Remove Route Success!");
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-05 11:39:15 -04:00
|
|
|
public function getRoute($rouUid)
|
|
|
|
|
{
|
|
|
|
|
$route = new Route();
|
|
|
|
|
|
|
|
|
|
return $route->load($rouUid);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-26 17:38:07 -04:00
|
|
|
public function getRoutes($start = null, $limit = null, $filter = '', $changeCaseTo = CASE_UPPER)
|
2014-02-24 19:10:45 -04:00
|
|
|
{
|
2014-02-26 17:38:07 -04:00
|
|
|
return Route::getAll($this->getUid(), $start, $limit, $filter, $changeCaseTo);
|
2014-02-24 19:10:45 -04:00
|
|
|
}
|
|
|
|
|
|
2014-02-05 11:39:15 -04:00
|
|
|
|
|
|
|
|
/****************************************************************************************************
|
|
|
|
|
* Migrated Methods from class.processMap.php class *
|
|
|
|
|
****************************************************************************************************/
|
|
|
|
|
|
|
|
|
|
private function getNumberOfRoutes($sProcessUID = '', $sTaskUID = '', $sNextTask = '', $sType = '')
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$oCriteria = new Criteria('workflow');
|
|
|
|
|
$oCriteria->addSelectColumn('COUNT(*) AS ROUTE_NUMBER');
|
|
|
|
|
$oCriteria->add(RoutePeer::PRO_UID, $sProcessUID);
|
|
|
|
|
$oCriteria->add(RoutePeer::TAS_UID, $sTaskUID);
|
|
|
|
|
$oCriteria->add(RoutePeer::ROU_NEXT_TASK, $sNextTask);
|
|
|
|
|
$oCriteria->add(RoutePeer::ROU_TYPE, $sType);
|
|
|
|
|
$oDataset = RoutePeer::doSelectRS($oCriteria);
|
|
|
|
|
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
$aRow = $oDataset->getRow();
|
|
|
|
|
|
|
|
|
|
return (int) $aRow['ROUTE_NUMBER'];
|
|
|
|
|
} catch (Exception $oError) {
|
|
|
|
|
throw ($oError);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-26 17:38:07 -04:00
|
|
|
private function saveNewPattern($sProcessUID = '', $sTaskUID = '', $sNextTask = '', $sType = '', $condition = '')
|
2014-02-05 11:39:15 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2014-03-25 11:30:56 -04:00
|
|
|
self::log("Add Route from task: $sTaskUID -> to task: $sNextTask ($sType)");
|
|
|
|
|
|
2014-02-05 11:39:15 -04:00
|
|
|
$oCriteria = new Criteria('workflow');
|
|
|
|
|
$oCriteria->addSelectColumn('COUNT(*) AS ROUTE_NUMBER');
|
|
|
|
|
//$oCriteria->addSelectColumn('GAT_UID AS GATEWAY_UID');
|
|
|
|
|
$oCriteria->add(RoutePeer::PRO_UID, $sProcessUID);
|
|
|
|
|
$oCriteria->add(RoutePeer::TAS_UID, $sTaskUID);
|
|
|
|
|
$oCriteria->add(RoutePeer::ROU_TYPE, $sType);
|
|
|
|
|
|
|
|
|
|
$oDataset = RoutePeer::doSelectRS($oCriteria);
|
|
|
|
|
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
$aRow = $oDataset->getRow();
|
|
|
|
|
|
|
|
|
|
$aFields['PRO_UID'] = $sProcessUID;
|
|
|
|
|
$aFields['TAS_UID'] = $sTaskUID;
|
|
|
|
|
$aFields['ROU_NEXT_TASK'] = $sNextTask;
|
|
|
|
|
$aFields['ROU_TYPE'] = $sType;
|
|
|
|
|
$aFields['ROU_CASE'] = (int) $aRow['ROUTE_NUMBER'] + 1;
|
|
|
|
|
|
2014-02-26 17:38:07 -04:00
|
|
|
if(! empty($condition)) {
|
|
|
|
|
$aFields['ROU_CONDITION'] = $condition;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-05 11:39:15 -04:00
|
|
|
//$sGatewayUID = $aRow['GATEWAY_UID'];
|
|
|
|
|
|
|
|
|
|
//if ($sDelete && $sGatewayUID != '') {
|
|
|
|
|
// $oGateway = new Gateway();
|
|
|
|
|
// $oGateway->remove($sGatewayUID);
|
|
|
|
|
//}
|
|
|
|
|
//Getting Gateway UID after saving gateway
|
|
|
|
|
//if($sType != 'SEQUENTIAL' && $sGatewayUID == '' && $sDelete == '1')
|
|
|
|
|
|
|
|
|
|
/*??? Maybe this is deprecated
|
|
|
|
|
if ($sType != 'SEQUENTIAL') {
|
|
|
|
|
$oProcessMap = new processMap();
|
|
|
|
|
$sGatewayUID = $this->saveNewGateway($sProcessUID, $sTaskUID, $sNextTask);
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
//$aFields['GAT_UID'] = (isset($sGatewayUID)) ? $sGatewayUID : '';
|
|
|
|
|
|
|
|
|
|
$oRoute = new Route();
|
2014-03-25 11:30:56 -04:00
|
|
|
$result = $oRoute->create($aFields);
|
|
|
|
|
self::log("Add Route Success! - ROU_UID: ", $result);
|
2014-02-05 11:39:15 -04:00
|
|
|
|
2014-03-25 11:30:56 -04:00
|
|
|
return $result;
|
2014-02-05 11:39:15 -04:00
|
|
|
} catch (Exception $oError) {
|
|
|
|
|
throw ($oError);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function deleteProcess($sProcessUID)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
//G::LoadClass('case');
|
|
|
|
|
//G::LoadClass('reportTables');
|
|
|
|
|
|
|
|
|
|
//Instance all classes necesaries
|
|
|
|
|
$oProcess = new \Process();
|
|
|
|
|
$oDynaform = new \Dynaform();
|
|
|
|
|
$oInputDocument = new \InputDocument();
|
|
|
|
|
$oOutputDocument = new \OutputDocument();
|
|
|
|
|
$oTrigger = new \Triggers();
|
|
|
|
|
$oRoute = new \Route();
|
|
|
|
|
$oGateway = new \Gateway();
|
|
|
|
|
$oEvent = new \Event();
|
|
|
|
|
$oSwimlaneElement = new \SwimlanesElements();
|
|
|
|
|
$oConfiguration = new \Configuration();
|
|
|
|
|
$oDbSource = new \DbSource();
|
|
|
|
|
$oReportTable = new \ReportTables();
|
|
|
|
|
$oCaseTracker = new \CaseTracker();
|
|
|
|
|
$oCaseTrackerObject = new \CaseTrackerObject();
|
|
|
|
|
//Delete the applications of process
|
|
|
|
|
$oCriteria = new \Criteria('workflow');
|
|
|
|
|
$oCriteria->add(\ApplicationPeer::PRO_UID, $sProcessUID);
|
|
|
|
|
$oDataset = \ApplicationPeer::doSelectRS($oCriteria);
|
|
|
|
|
$oDataset->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
$oCase = new \Cases();
|
|
|
|
|
|
|
|
|
|
while ($aRow = $oDataset->getRow()) {
|
|
|
|
|
$oCase->removeCase($aRow['APP_UID']);
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Delete the tasks of process
|
|
|
|
|
$oCriteria = new Criteria('workflow');
|
|
|
|
|
$oCriteria->add(\TaskPeer::PRO_UID, $sProcessUID);
|
|
|
|
|
$oDataset = \TaskPeer::doSelectRS($oCriteria);
|
|
|
|
|
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
while ($aRow = $oDataset->getRow()) {
|
|
|
|
|
//$this->deleteTask($aRow['TAS_UID']);
|
|
|
|
|
$oTasks = new \Tasks();
|
|
|
|
|
$oTasks->deleteTask($aRow['TAS_UID']);
|
|
|
|
|
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
}
|
|
|
|
|
//Delete the dynaforms of process
|
|
|
|
|
$oCriteria = new Criteria('workflow');
|
|
|
|
|
$oCriteria->add(\DynaformPeer::PRO_UID, $sProcessUID);
|
|
|
|
|
$oDataset = \DynaformPeer::doSelectRS($oCriteria);
|
|
|
|
|
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
while ($aRow = $oDataset->getRow()) {
|
|
|
|
|
$oDynaform->remove($aRow['DYN_UID']);
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
}
|
|
|
|
|
//Delete the input documents of process
|
|
|
|
|
$oCriteria = new Criteria('workflow');
|
|
|
|
|
$oCriteria->add(\InputDocumentPeer::PRO_UID, $sProcessUID);
|
|
|
|
|
$oDataset = \InputDocumentPeer::doSelectRS($oCriteria);
|
|
|
|
|
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
while ($aRow = $oDataset->getRow()) {
|
|
|
|
|
$oInputDocument->remove($aRow['INP_DOC_UID']);
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
}
|
|
|
|
|
//Delete the output documents of process
|
|
|
|
|
$oCriteria = new Criteria('workflow');
|
|
|
|
|
$oCriteria->add(\OutputDocumentPeer::PRO_UID, $sProcessUID);
|
|
|
|
|
$oDataset = \OutputDocumentPeer::doSelectRS($oCriteria);
|
|
|
|
|
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
while ($aRow = $oDataset->getRow()) {
|
|
|
|
|
$oOutputDocument->remove($aRow['OUT_DOC_UID']);
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Delete the triggers of process
|
|
|
|
|
$oCriteria = new Criteria('workflow');
|
|
|
|
|
$oCriteria->add(\TriggersPeer::PRO_UID, $sProcessUID);
|
|
|
|
|
$oDataset = \TriggersPeer::doSelectRS($oCriteria);
|
|
|
|
|
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
while ($aRow = $oDataset->getRow()) {
|
|
|
|
|
$oTrigger->remove($aRow['TRI_UID']);
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Delete the routes of process
|
|
|
|
|
$oCriteria = new Criteria('workflow');
|
|
|
|
|
$oCriteria->add(\RoutePeer::PRO_UID, $sProcessUID);
|
|
|
|
|
$oDataset = \RoutePeer::doSelectRS($oCriteria);
|
|
|
|
|
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
while ($aRow = $oDataset->getRow()) {
|
|
|
|
|
$oRoute->remove($aRow['ROU_UID']);
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Delete the gateways of process
|
|
|
|
|
$oCriteria = new Criteria('workflow');
|
|
|
|
|
$oCriteria->add(\GatewayPeer::PRO_UID, $sProcessUID);
|
|
|
|
|
$oDataset = \GatewayPeer::doSelectRS($oCriteria);
|
|
|
|
|
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
while ($aRow = $oDataset->getRow()) {
|
|
|
|
|
$oGateway->remove($aRow['GAT_UID']);
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Delete the Event of process
|
|
|
|
|
$oCriteria = new Criteria('workflow');
|
|
|
|
|
$oCriteria->add(\EventPeer::PRO_UID, $sProcessUID);
|
|
|
|
|
$oDataset = \EventPeer::doSelectRS($oCriteria);
|
|
|
|
|
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
while ($aRow = $oDataset->getRow()) {
|
|
|
|
|
$oEvent->remove($aRow['EVN_UID']);
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Delete the swimlanes elements of process
|
|
|
|
|
$oCriteria = new Criteria('workflow');
|
|
|
|
|
$oCriteria->add(\SwimlanesElementsPeer::PRO_UID, $sProcessUID);
|
|
|
|
|
$oDataset = \SwimlanesElementsPeer::doSelectRS($oCriteria);
|
|
|
|
|
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
while ($aRow = $oDataset->getRow()) {
|
|
|
|
|
$oSwimlaneElement->remove($aRow['SWI_UID']);
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
}
|
|
|
|
|
//Delete the configurations of process
|
|
|
|
|
$oCriteria = new Criteria('workflow');
|
|
|
|
|
$oCriteria->add(\ConfigurationPeer::PRO_UID, $sProcessUID);
|
|
|
|
|
$oDataset = \ConfigurationPeer::doSelectRS($oCriteria);
|
|
|
|
|
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
while ($aRow = $oDataset->getRow()) {
|
|
|
|
|
$oConfiguration->remove($aRow['CFG_UID'], $aRow['OBJ_UID'], $aRow['PRO_UID'], $aRow['USR_UID'], $aRow['APP_UID']);
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
}
|
|
|
|
|
//Delete the DB sources of process
|
|
|
|
|
$oCriteria = new Criteria('workflow');
|
|
|
|
|
$oCriteria->add(\DbSourcePeer::PRO_UID, $sProcessUID);
|
|
|
|
|
$oDataset = \DbSourcePeer::doSelectRS($oCriteria);
|
|
|
|
|
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
while ($aRow = $oDataset->getRow()) {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* note added by gustavo cruz gustavo-at-colosa-dot-com 27-01-2010
|
|
|
|
|
* in order to solve the bug 0004389, we use the validation function Exists
|
|
|
|
|
* inside the remove function in order to verify if the DbSource record
|
|
|
|
|
* exists in the Database, however there is a strange behavior within the
|
|
|
|
|
* propel engine, when the first record is erased somehow the "_deleted"
|
|
|
|
|
* attribute of the next row is set to true, so when propel tries to erase
|
|
|
|
|
* it, obviously it can't and trows an error. With the "Exist" function
|
|
|
|
|
* we ensure that if there is the record in the database, the _delete attribute must be false.
|
|
|
|
|
*
|
|
|
|
|
* note added by gustavo cruz gustavo-at-colosa-dot-com 28-01-2010
|
|
|
|
|
* I have just identified the source of the issue, when is created a $oDbSource DbSource object
|
|
|
|
|
* it's used whenever a record is erased or removed in the db, however the problem
|
|
|
|
|
* it's that the same object is used every time, and the delete method invoked
|
|
|
|
|
* sets the _deleted attribute to true when its called, of course as we use
|
|
|
|
|
* the same object, the first time works fine but trowns an error with the
|
|
|
|
|
* next record, cos it's the same object and the delete method checks if the _deleted
|
|
|
|
|
* attribute it's true or false, the attrib _deleted is setted to true the
|
|
|
|
|
* first time and later is never changed, the issue seems to be part of
|
|
|
|
|
* every remove function in the model classes, not only DbSource
|
|
|
|
|
* i recommend that a more general solution must be achieved to resolve
|
|
|
|
|
* this issue in every model class, to prevent future problems.
|
|
|
|
|
*/
|
|
|
|
|
$oDbSource->remove($aRow['DBS_UID'], $sProcessUID);
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
}
|
|
|
|
|
//Delete the supervisors
|
|
|
|
|
$oCriteria = new Criteria('workflow');
|
|
|
|
|
$oCriteria->add(\ProcessUserPeer::PRO_UID, $sProcessUID);
|
|
|
|
|
\ProcessUserPeer::doDelete($oCriteria);
|
|
|
|
|
//Delete the object permissions
|
|
|
|
|
$oCriteria = new Criteria('workflow');
|
|
|
|
|
$oCriteria->add(\ObjectPermissionPeer::PRO_UID, $sProcessUID);
|
|
|
|
|
\ObjectPermissionPeer::doDelete($oCriteria);
|
|
|
|
|
//Delete the step supervisors
|
|
|
|
|
$oCriteria = new Criteria('workflow');
|
|
|
|
|
$oCriteria->add(\StepSupervisorPeer::PRO_UID, $sProcessUID);
|
|
|
|
|
\StepSupervisorPeer::doDelete($oCriteria);
|
|
|
|
|
//Delete the report tables
|
|
|
|
|
$oCriteria = new Criteria('workflow');
|
|
|
|
|
$oCriteria->add(\ReportTablePeer::PRO_UID, $sProcessUID);
|
|
|
|
|
$oDataset = \ReportTablePeer::doSelectRS($oCriteria);
|
|
|
|
|
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
while ($aRow = $oDataset->getRow()) {
|
|
|
|
|
$oReportTable->deleteReportTable($aRow['REP_TAB_UID']);
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
}
|
|
|
|
|
//Delete case tracker configuration
|
|
|
|
|
$oCaseTracker->remove($sProcessUID);
|
|
|
|
|
//Delete case tracker objects
|
|
|
|
|
$oCriteria = new Criteria('workflow');
|
|
|
|
|
$oCriteria->add(\CaseTrackerObjectPeer::PRO_UID, $sProcessUID);
|
|
|
|
|
\ProcessUserPeer::doDelete($oCriteria);
|
|
|
|
|
//Delete the process
|
|
|
|
|
try {
|
|
|
|
|
$oProcess->remove($sProcessUID);
|
|
|
|
|
} catch (Exception $oError) {
|
|
|
|
|
throw ($oError);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
} catch (Exception $oError) {
|
|
|
|
|
throw ($oError);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|