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
|
2014-05-05 12:19:20 -04:00
|
|
|
*
|
2014-02-10 13:09:50 -04:00
|
|
|
* @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) {
|
2014-06-23 12:56:23 -04:00
|
|
|
if (is_null(\ProcessPeer::retrieveByPK($proUid))) {
|
|
|
|
|
throw new Exception\ProjectNotFound($me, $proUid);
|
|
|
|
|
} else {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-27 19:11:11 -04:00
|
|
|
public function update($data)
|
2014-02-05 11:39:15 -04:00
|
|
|
{
|
2014-03-27 19:11:11 -04:00
|
|
|
$process = new Process();
|
2014-04-07 16:10:42 -04:00
|
|
|
$data["PRO_UID"] = $this->getUid();
|
2014-03-27 19:11:11 -04:00
|
|
|
$process->update($data);
|
2014-02-05 11:39:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
2014-05-20 15:15:56 -04:00
|
|
|
$processes = $process->getAllProcesses($start, $limit);
|
2014-02-05 14:09:48 -04:00
|
|
|
//$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
|
|
|
|
|
));
|
|
|
|
|
|
2014-05-05 12:19:20 -04:00
|
|
|
if ($route != null) {
|
|
|
|
|
$route->delete();
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-24 19:10:45 -04:00
|
|
|
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);
|
2014-05-05 12:19:20 -04:00
|
|
|
|
|
|
|
|
//Delete Web Entries
|
|
|
|
|
$webEntry = new \ProcessMaker\BusinessModel\WebEntry();
|
|
|
|
|
|
|
|
|
|
$criteria = new \Criteria("workflow");
|
|
|
|
|
$criteria->addSelectColumn(\WebEntryPeer::WE_UID);
|
|
|
|
|
$criteria->add(\WebEntryPeer::PRO_UID, $sProcessUID, \Criteria::EQUAL);
|
|
|
|
|
|
|
|
|
|
$rsCriteria = \WebEntryPeer::doSelectRS($criteria);
|
|
|
|
|
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
|
|
|
|
|
while ($rsCriteria->next()) {
|
|
|
|
|
$row = $rsCriteria->getRow();
|
|
|
|
|
|
|
|
|
|
$webEntry->delete($row["WE_UID"]);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-05 11:39:15 -04:00
|
|
|
//Delete the process
|
|
|
|
|
try {
|
|
|
|
|
$oProcess->remove($sProcessUID);
|
2014-03-27 19:11:11 -04:00
|
|
|
} catch (\Exception $oError) {
|
2014-02-05 11:39:15 -04:00
|
|
|
throw ($oError);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2014-03-27 19:11:11 -04:00
|
|
|
} catch (\Exception $oError) {
|
2014-02-05 11:39:15 -04:00
|
|
|
throw ($oError);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-07 16:10:42 -04:00
|
|
|
public function setDisabled($value = true)
|
|
|
|
|
{
|
|
|
|
|
$status = $value ? "DISABLED" : "ACTIVE";
|
|
|
|
|
$this->update(array("PRO_STATUS" => $status));
|
|
|
|
|
}
|
2014-04-28 10:48:34 -04:00
|
|
|
|
2014-04-28 15:22:53 -04:00
|
|
|
public function addCaseScheduler($schUid)
|
2014-04-28 10:48:34 -04:00
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$caseScheduler = new \CaseScheduler();
|
|
|
|
|
$data = array(
|
|
|
|
|
'SCH_NAME'=>'',
|
|
|
|
|
'SCH_DEL_USER_NAME'=>'',
|
|
|
|
|
'SCH_DEL_USER_UID'=>'',
|
2014-04-28 12:05:08 -04:00
|
|
|
'PRO_UID'=>$this->proUid,
|
2014-04-28 10:48:34 -04:00
|
|
|
'TAS_UID'=>'',
|
|
|
|
|
'SCH_TIME_NEXT_RUN'=>date('Y-m-d H:i:s'),
|
|
|
|
|
'SCH_LAST_RUN_TIME'=>NULL,
|
|
|
|
|
'SCH_STATE'=>'',
|
|
|
|
|
'SCH_LAST_STATE'=>'',
|
|
|
|
|
'USR_UID'=>'',
|
|
|
|
|
'SCH_OPTION'=>'',
|
|
|
|
|
'SCH_START_TIME'=>date('Y-m-d H:i:s'),
|
|
|
|
|
'SCH_START_DATE'=>date('Y-m-d H:i:s'),
|
|
|
|
|
'SCH_DAYS_PERFORM_TASK'=>'',
|
|
|
|
|
'SCH_EVERY_DAYS'=>NULL,
|
|
|
|
|
'SCH_WEEK_DAYS'=>'',
|
|
|
|
|
'SCH_START_DAY'=>'',
|
|
|
|
|
'SCH_START_DAY_OPT_1'=>'',
|
|
|
|
|
'SCH_START_DAY_OPT_2'=>'',
|
|
|
|
|
'SCH_MONTHS'=>'',
|
|
|
|
|
'SCH_END_DATE'=>date('Y-m-d H:i:s'),
|
|
|
|
|
'SCH_REPEAT_EVERY'=>'',
|
|
|
|
|
'SCH_REPEAT_STOP_IF_RUNNING'=>'',
|
|
|
|
|
'CASE_SH_PLUGIN_UID'=>NULL,
|
|
|
|
|
'SCH_DEL_USER_PASS'=>'',
|
2014-04-28 15:22:53 -04:00
|
|
|
'SCH_UID'=>$schUid,
|
2014-04-28 10:48:34 -04:00
|
|
|
'SCH_REPEAT_UNTIL'=>''
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
self::log("Adding Case Scheduler with data: ", $data);
|
|
|
|
|
$caseSchedulerUid = $caseScheduler->create($data);
|
|
|
|
|
self::log("Adding Case Scheduler success!, created case Scheduler id: ", $caseSchedulerUid);
|
|
|
|
|
|
|
|
|
|
return $caseSchedulerUid;
|
|
|
|
|
} catch (\Exception $oError) {
|
|
|
|
|
throw ($oError);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-29 09:54:46 -04:00
|
|
|
public function removeCaseScheduler($schUid)
|
2014-04-28 10:48:34 -04:00
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$caseScheduler = new \CaseScheduler();
|
2014-04-28 15:22:53 -04:00
|
|
|
self::log("Remove Case Scheduler: ".$schUid);
|
|
|
|
|
$caseScheduler->remove($schUid);
|
2014-04-28 10:48:34 -04:00
|
|
|
self::log("Remove Case Scheduler Success!");
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-29 11:06:16 -04:00
|
|
|
public function updateCaseScheduler($schUid, $data)
|
2014-04-28 10:48:34 -04:00
|
|
|
{
|
2014-04-28 15:22:53 -04:00
|
|
|
try {
|
2014-04-29 11:06:16 -04:00
|
|
|
$data = array_merge(array("SCH_UID" => $schUid), $data);
|
2014-04-28 15:22:53 -04:00
|
|
|
$caseScheduler = new \CaseScheduler();
|
|
|
|
|
$caseScheduler->update($data);
|
|
|
|
|
self::log("Update Case Scheduler Success!");
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
2014-04-28 10:48:34 -04:00
|
|
|
}
|
|
|
|
|
|
2014-04-28 15:22:53 -04:00
|
|
|
public function addWebEntry($weUid)
|
2014-04-28 10:48:34 -04:00
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$webEntry = new \WebEntry();
|
2014-04-28 15:22:53 -04:00
|
|
|
$webEntryUid = $weUid;
|
2014-04-28 10:48:34 -04:00
|
|
|
$webEntry->setWeUid($webEntryUid);
|
2014-04-28 12:05:08 -04:00
|
|
|
$webEntry->setProUid($this->proUid);
|
2014-04-28 10:48:34 -04:00
|
|
|
$webEntry->setWeMethod('');
|
|
|
|
|
$webEntry->setWeCreateDate(date('Y-m-d H:i:s'));
|
|
|
|
|
$webEntry->save();
|
|
|
|
|
|
|
|
|
|
//Return
|
|
|
|
|
self::log("Adding Web Entry success!, created Web Entry id: ", $webEntryUid);
|
|
|
|
|
return $webEntryUid;
|
|
|
|
|
} catch (\Exception $oError) {
|
|
|
|
|
throw ($oError);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-29 09:54:46 -04:00
|
|
|
public function removeWebEntry($weUid)
|
2014-04-28 10:48:34 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2014-04-28 15:22:53 -04:00
|
|
|
$webEntry = new \ProcessMaker\BusinessModel\WebEntry();
|
|
|
|
|
self::log("Remove Web Entry: ".$weUid);
|
|
|
|
|
$webEntry->delete($weUid);
|
2014-04-28 10:48:34 -04:00
|
|
|
self::log("Remove Web Entry Success!");
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-29 11:06:16 -04:00
|
|
|
public function updateWebEntry($webEntryUid, $data)
|
2014-04-28 10:48:34 -04:00
|
|
|
{
|
2014-04-28 15:22:53 -04:00
|
|
|
try {
|
|
|
|
|
$webEntry = \WebEntryPeer::retrieveByPK($webEntryUid);
|
|
|
|
|
$webEntry->fromArray($data, \BasePeer::TYPE_FIELDNAME);
|
|
|
|
|
$webEntry->save();
|
|
|
|
|
self::log("Update Web Entry Success!");
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
2014-04-28 10:48:34 -04:00
|
|
|
|
|
|
|
|
}
|
2014-07-24 17:18:48 -04:00
|
|
|
|
2014-07-29 16:10:58 -04:00
|
|
|
public function addLine($position, $direction = "HORIZONTAL")
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
self::log("Add Line with data: position $position, direction $direction");
|
|
|
|
|
|
|
|
|
|
$swimlaneElement = new \SwimlanesElements();
|
|
|
|
|
|
|
|
|
|
$swiUid = $swimlaneElement->create(array(
|
|
|
|
|
"PRO_UID" => $this->proUid,
|
|
|
|
|
"SWI_TYPE" => "LINE",
|
|
|
|
|
"SWI_X" => ($direction == "HORIZONTAL")? 0 : $position,
|
|
|
|
|
"SWI_Y" => ($direction == "HORIZONTAL")? $position : 0
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
self::log("Add Line Success!");
|
|
|
|
|
|
|
|
|
|
//Return
|
|
|
|
|
return $swiUid;
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
|
|
|
|
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addText($text, $x, $y)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
self::log("Add Text with data: text \"$text\"");
|
|
|
|
|
|
|
|
|
|
$swimlaneElement = new \SwimlanesElements();
|
|
|
|
|
|
|
|
|
|
$swiUid = $swimlaneElement->create(array(
|
|
|
|
|
"PRO_UID" => $this->proUid,
|
|
|
|
|
"SWI_TYPE" => "TEXT",
|
|
|
|
|
"SWI_TEXT" => $text,
|
|
|
|
|
"SWI_X" => $x,
|
|
|
|
|
"SWI_Y" => $y
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
self::log("Add Text Success!");
|
|
|
|
|
|
|
|
|
|
//Return
|
|
|
|
|
return $swiUid;
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
|
|
|
|
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function createDataByArrayData(array $arrayData)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$processes = new \Processes();
|
|
|
|
|
|
|
|
|
|
$processes->createProcessPropertiesFromData((object)($arrayData));
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
|
|
|
|
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function createDataFileByArrayFile(array $arrayFile)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
foreach ($arrayFile as $target => $files) {
|
|
|
|
|
switch (strtoupper($target)) {
|
|
|
|
|
case "DYNAFORMS":
|
|
|
|
|
$basePath = PATH_DYNAFORM;
|
|
|
|
|
break;
|
|
|
|
|
case "PUBLIC":
|
|
|
|
|
$basePath = PATH_DATA . "sites" . PATH_SEP . SYS_SYS . PATH_SEP . "public" . PATH_SEP;
|
|
|
|
|
break;
|
|
|
|
|
case "TEMPLATES":
|
|
|
|
|
$basePath = PATH_DATA . "sites" . PATH_SEP . SYS_SYS . PATH_SEP . "mailTemplates" . PATH_SEP;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
$basePath = "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (empty($basePath)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($files as $file) {
|
|
|
|
|
$filename = $basePath . ((isset($file["file_path"]))? $file["file_path"] : $file["filepath"]);
|
|
|
|
|
$path = dirname($filename);
|
|
|
|
|
|
|
|
|
|
if (!is_dir($path)) {
|
|
|
|
|
Util\Common::mk_dir($path, 0775);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
file_put_contents($filename, $file["file_content"]);
|
|
|
|
|
chmod($filename, 0775);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
|
|
|
|
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-24 17:18:48 -04:00
|
|
|
public function getData($processUid)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$process = new \Processes();
|
|
|
|
|
|
|
|
|
|
//Get data
|
|
|
|
|
$workflowData = (array)($process->getWorkflowData($processUid));
|
|
|
|
|
$workflowData["process"]["PRO_DYNAFORMS"] = (empty($workflowData["process"]["PRO_DYNAFORMS"]))? "" : serialize($workflowData["process"]["PRO_DYNAFORMS"]);
|
|
|
|
|
|
|
|
|
|
$workflowData["process"] = array($workflowData["process"]);
|
|
|
|
|
$workflowData["processCategory"] = (empty($workflowData["processCategory"]))? array() : array($workflowData["processCategory"]);
|
|
|
|
|
|
|
|
|
|
//Get files
|
|
|
|
|
$workflowFile = array();
|
|
|
|
|
|
|
|
|
|
//Getting DynaForms
|
|
|
|
|
foreach ($workflowData["dynaforms"] as $dynaform) {
|
|
|
|
|
$dynFile = PATH_DYNAFORM . $dynaform["DYN_FILENAME"] . ".xml";
|
|
|
|
|
|
|
|
|
|
$workflowFile["DYNAFORMS"][] = array(
|
|
|
|
|
"filename" => $dynaform["DYN_TITLE"],
|
|
|
|
|
"filepath" => $dynaform["DYN_FILENAME"] . ".xml",
|
|
|
|
|
"file_content" => file_get_contents($dynFile)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$htmlFile = PATH_DYNAFORM . $dynaform["DYN_FILENAME"] . ".html";
|
|
|
|
|
|
|
|
|
|
if (file_exists($htmlFile)) {
|
|
|
|
|
$workflowFile["DYNAFORMS"][] = array(
|
|
|
|
|
"filename" => $dynaform["DYN_FILENAME"] . ".html",
|
|
|
|
|
"filepath" => $dynaform["DYN_FILENAME"] . ".html",
|
|
|
|
|
"file_content" => file_get_contents($htmlFile)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Getting templates files
|
|
|
|
|
$workspaceTargetDirs = array("TEMPLATES" => "mailTemplates", "PUBLIC" => "public");
|
|
|
|
|
$workspaceDir = PATH_DATA . "sites" . PATH_SEP . SYS_SYS . PATH_SEP;
|
|
|
|
|
|
|
|
|
|
foreach ($workspaceTargetDirs as $target => $workspaceTargetDir) {
|
|
|
|
|
$templatesDir = $workspaceDir . $workspaceTargetDir . PATH_SEP . $processUid;
|
|
|
|
|
$templatesFiles = Util\Common::rglob("$templatesDir/*", 0, true);
|
|
|
|
|
|
|
|
|
|
foreach ($templatesFiles as $templatesFile) {
|
|
|
|
|
if (is_dir($templatesFile)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$filename = basename($templatesFile);
|
|
|
|
|
|
|
|
|
|
$workflowFile[$target][] = array(
|
|
|
|
|
"filename" => $filename,
|
|
|
|
|
"filepath" => $processUid . PATH_SEP . $filename,
|
|
|
|
|
"file_content" => file_get_contents($templatesFile)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Return
|
|
|
|
|
self::log("Getting Workflow data Success!");
|
|
|
|
|
|
|
|
|
|
return array($workflowData, $workflowFile);
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
2014-07-29 16:10:58 -04:00
|
|
|
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function updateDataUidByArrayUid(array $arrayWorkflowData, array $arrayWorkflowFile, array $arrayUid)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$processUidOld = $arrayUid[0]["old_uid"];
|
|
|
|
|
$processUid = $arrayUid[0]["new_uid"];
|
|
|
|
|
|
|
|
|
|
//Update TAS_UID
|
|
|
|
|
foreach ($arrayWorkflowData["tasks"] as $key => $value) {
|
|
|
|
|
$taskUid = $arrayWorkflowData["tasks"][$key]["TAS_UID"];
|
|
|
|
|
|
|
|
|
|
foreach ($arrayUid as $value2) {
|
|
|
|
|
$arrayItem = $value2;
|
|
|
|
|
|
|
|
|
|
if ($arrayItem["old_uid"] == $taskUid) {
|
|
|
|
|
$arrayWorkflowData["tasks"][$key]["TAS_UID_OLD"] = $taskUid;
|
|
|
|
|
$arrayWorkflowData["tasks"][$key]["TAS_UID"] = $arrayItem["new_uid"];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Workflow tables
|
|
|
|
|
$workflowData = (object)($arrayWorkflowData);
|
|
|
|
|
|
|
|
|
|
$processes = new \Processes();
|
|
|
|
|
$processes->setProcessGUID($workflowData, $processUid);
|
|
|
|
|
$processes->renewAll($workflowData);
|
|
|
|
|
|
|
|
|
|
$arrayWorkflowData = (array)($workflowData);
|
|
|
|
|
|
|
|
|
|
//Workflow files
|
|
|
|
|
foreach ($arrayWorkflowFile as $key => $value) {
|
|
|
|
|
$arrayFile = $value;
|
|
|
|
|
|
|
|
|
|
foreach ($arrayFile as $key2 => $value2) {
|
|
|
|
|
$file = $value2;
|
|
|
|
|
|
|
|
|
|
$arrayWorkflowFile[$key][$key2]["file_path"] = str_replace($processUidOld, $processUid, (isset($file["file_path"]))? $file["file_path"] : $file["filepath"]);
|
|
|
|
|
$arrayWorkflowFile[$key][$key2]["file_content"] = str_replace($processUidOld, $processUid, $file["file_content"]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($arrayWorkflowData["uid"])) {
|
|
|
|
|
foreach ($arrayWorkflowData["uid"] as $key => $value) {
|
|
|
|
|
$arrayT = $value;
|
|
|
|
|
|
|
|
|
|
foreach ($arrayT as $key2 => $value2) {
|
|
|
|
|
$uidOld = $key2;
|
|
|
|
|
$uid = $value2;
|
|
|
|
|
|
|
|
|
|
foreach ($arrayWorkflowFile as $key3 => $value3) {
|
|
|
|
|
$arrayFile = $value3;
|
|
|
|
|
|
|
|
|
|
foreach ($arrayFile as $key4 => $value4) {
|
|
|
|
|
$file = $value4;
|
|
|
|
|
|
|
|
|
|
$arrayWorkflowFile[$key3][$key4]["file_path"] = str_replace($uidOld, $uid, $file["file_path"]);
|
|
|
|
|
$arrayWorkflowFile[$key3][$key4]["file_content"] = str_replace($uidOld, $uid, $file["file_content"]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Return
|
|
|
|
|
return array($arrayWorkflowData, $arrayWorkflowFile);
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
|
|
|
|
|
2014-07-24 17:18:48 -04:00
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-05-05 12:19:20 -04:00
|
|
|
}
|
|
|
|
|
|