HOR-3701
This commit is contained in:
@@ -1,36 +1,39 @@
|
||||
<?php
|
||||
namespace ProcessMaker\Project;
|
||||
|
||||
use \BasePeer;
|
||||
use \BpmnActivity as Activity;
|
||||
use \BpmnArtifact as Artifact;
|
||||
use \BpmnActivityPeer as ActivityPeer;
|
||||
use \BpmnArtifactPeer as ArtifactPeer;
|
||||
use \BpmnBound as Bound;
|
||||
use \BpmnBoundPeer as BoundPeer;
|
||||
use \BpmnDiagram as Diagram;
|
||||
use \BpmnDiagramPeer as DiagramPeer;
|
||||
use \BpmnEvent as Event;
|
||||
use \BpmnEventPeer as EventPeer;
|
||||
use \BpmnFlow as Flow;
|
||||
use \BpmnFlowPeer as FlowPeer;
|
||||
use \BpmnGateway as Gateway;
|
||||
use \BpmnGatewayPeer as GatewayPeer;
|
||||
use \BpmnLaneset as Laneset;
|
||||
use \BpmnLanesetPeer as LanesetPeer;
|
||||
use \BpmnLane as Lane;
|
||||
use \BpmnLanePeer as LanePeer;
|
||||
use \BpmnParticipant as Participant;
|
||||
use \BpmnParticipantPeer as ParticipantPeer;
|
||||
use \BpmnProject as Project;
|
||||
use \BpmnProcess as Process;
|
||||
use \BpmnProjectPeer as ProjectPeer;
|
||||
use \BpmnProcessPeer as ProcessPeer;
|
||||
use \Criteria as Criteria;
|
||||
use \Exception;
|
||||
use \G;
|
||||
use \ResultSet as ResultSet;
|
||||
use \ProcessMaker\Util\Common;
|
||||
use BasePeer;
|
||||
use BpmnActivity as Activity;
|
||||
use BpmnArtifact as Artifact;
|
||||
use BpmnActivityPeer as ActivityPeer;
|
||||
use BpmnArtifactPeer as ArtifactPeer;
|
||||
use BpmnBound as Bound;
|
||||
use BpmnBoundPeer as BoundPeer;
|
||||
use BpmnDiagram as Diagram;
|
||||
use BpmnDiagramPeer as DiagramPeer;
|
||||
use BpmnEvent as Event;
|
||||
use BpmnEventPeer as EventPeer;
|
||||
use BpmnFlow as Flow;
|
||||
use BpmnFlowPeer as FlowPeer;
|
||||
use BpmnGateway as Gateway;
|
||||
use BpmnGatewayPeer as GatewayPeer;
|
||||
use BpmnLaneset as Laneset;
|
||||
use BpmnLanesetPeer as LanesetPeer;
|
||||
use BpmnLane as Lane;
|
||||
use BpmnLanePeer as LanePeer;
|
||||
use BpmnParticipant as Participant;
|
||||
use BpmnParticipantPeer as ParticipantPeer;
|
||||
use BpmnProject as Project;
|
||||
use BpmnProcess as Process;
|
||||
use BpmnProjectPeer as ProjectPeer;
|
||||
use BpmnProcessPeer as ProcessPeer;
|
||||
use Criteria as Criteria;
|
||||
use Exception;
|
||||
use G;
|
||||
use ResultSet as ResultSet;
|
||||
use ProcessMaker\Util\Common;
|
||||
use ProcessMaker\Exception\ProjectNotFound;
|
||||
use ProcessMaker\Project\Adapter\BpmnWorkflow;
|
||||
use Bootstrap;
|
||||
|
||||
/**
|
||||
* Class Bpmn
|
||||
@@ -59,34 +62,230 @@ class Bpmn extends Handler
|
||||
|
||||
protected static $excludeFields = array(
|
||||
"activity" => array(
|
||||
"PRJ_UID", "PRO_UID", "BOU_ELEMENT_TYPE", "BOU_REL_POSITION",
|
||||
"BOU_SIZE_IDENTICAL", "DIA_UID", "BOU_UID", "ELEMENT_UID"
|
||||
"PRJ_UID",
|
||||
"PRO_UID",
|
||||
"BOU_ELEMENT_TYPE",
|
||||
"BOU_REL_POSITION",
|
||||
"BOU_SIZE_IDENTICAL",
|
||||
"DIA_UID",
|
||||
"BOU_UID",
|
||||
"ELEMENT_UID"
|
||||
),
|
||||
"event" => array(
|
||||
"PRJ_UID", "PRO_UID", "BOU_ELEMENT_TYPE", "BOU_REL_POSITION",
|
||||
"BOU_SIZE_IDENTICAL", "DIA_UID", "BOU_UID", "ELEMENT_UID", "EVN_ATTACHED_TO", "EVN_CONDITION"
|
||||
"PRJ_UID",
|
||||
"PRO_UID",
|
||||
"BOU_ELEMENT_TYPE",
|
||||
"BOU_REL_POSITION",
|
||||
"BOU_SIZE_IDENTICAL",
|
||||
"DIA_UID",
|
||||
"BOU_UID",
|
||||
"ELEMENT_UID",
|
||||
"EVN_ATTACHED_TO",
|
||||
"EVN_CONDITION"
|
||||
),
|
||||
"gateway" => array("BOU_ELEMENT_TYPE", "BOU_REL_POSITION", "BOU_SIZE_IDENTICAL", "BOU_UID",
|
||||
"DIA_UID", "ELEMENT_UID", "PRJ_UID", "PRO_UID"
|
||||
"gateway" => array(
|
||||
"BOU_ELEMENT_TYPE",
|
||||
"BOU_REL_POSITION",
|
||||
"BOU_SIZE_IDENTICAL",
|
||||
"BOU_UID",
|
||||
"DIA_UID",
|
||||
"ELEMENT_UID",
|
||||
"PRJ_UID",
|
||||
"PRO_UID"
|
||||
),
|
||||
"artifact" => array(
|
||||
"PRJ_UID", "PRO_UID", "BOU_ELEMENT_TYPE", "BOU_REL_POSITION",
|
||||
"BOU_SIZE_IDENTICAL", "DIA_UID", "BOU_UID", "ELEMENT_UID"
|
||||
"PRJ_UID",
|
||||
"PRO_UID",
|
||||
"BOU_ELEMENT_TYPE",
|
||||
"BOU_REL_POSITION",
|
||||
"BOU_SIZE_IDENTICAL",
|
||||
"DIA_UID",
|
||||
"BOU_UID",
|
||||
"ELEMENT_UID"
|
||||
),
|
||||
"flow" => array("PRJ_UID", "DIA_UID", "FLO_ELEMENT_DEST_PORT", "FLO_ELEMENT_ORIGIN_PORT"),
|
||||
"data" => array("PRJ_UID"),
|
||||
"participant" => array("PRJ_UID"),
|
||||
"laneset" => array("BOU_ELEMENT_TYPE", "BOU_SIZE_IDENTICAL", "BOU_UID"),
|
||||
"lane" => array("BOU_ELEMENT_TYPE", "BOU_SIZE_IDENTICAL", "BOU_UID")
|
||||
"flow" => array(
|
||||
"PRJ_UID",
|
||||
"DIA_UID",
|
||||
"FLO_ELEMENT_DEST_PORT",
|
||||
"FLO_ELEMENT_ORIGIN_PORT"
|
||||
),
|
||||
"data" => array(
|
||||
"PRJ_UID"
|
||||
),
|
||||
"participant" => array(
|
||||
"PRJ_UID"
|
||||
),
|
||||
"laneset" => array(
|
||||
"BOU_ELEMENT_TYPE",
|
||||
"BOU_SIZE_IDENTICAL",
|
||||
"BOU_UID"
|
||||
),
|
||||
"lane" => array(
|
||||
"BOU_ELEMENT_TYPE",
|
||||
"BOU_SIZE_IDENTICAL",
|
||||
"BOU_UID"
|
||||
)
|
||||
);
|
||||
|
||||
private $arrayElementOriginChecked = array();
|
||||
protected $contextLog = array();
|
||||
|
||||
public function __construct($data = null)
|
||||
{
|
||||
if (! is_null($data)) {
|
||||
$this->create($data);
|
||||
}
|
||||
//Define the variables for the logging
|
||||
$info = array(
|
||||
'ip' => G::getIpAddress(),
|
||||
'workspace' => (defined("SYS_SYS"))? SYS_SYS : "Workspace undefined"
|
||||
);
|
||||
$this->setContextLog($info);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the $contextLog value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContextLog()
|
||||
{
|
||||
return $this->contextLog;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of $contextLog.
|
||||
*
|
||||
* @param array $k
|
||||
* @return void
|
||||
*/
|
||||
public function setContextLog($k)
|
||||
{
|
||||
$this->contextLog = array_merge($this->contextLog, $k);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bulk actions
|
||||
* We will have actions in many projects
|
||||
*
|
||||
* @param array $data
|
||||
* @return array $result, related to actions send
|
||||
*/
|
||||
public static function doBulk($data)
|
||||
{
|
||||
//We will review the data format
|
||||
if (!is_array($data)) {
|
||||
$isJson = is_string($data) && is_array(G::json_decode($data, true));
|
||||
if ($isJson) {
|
||||
$data = G::json_decode($data, true);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
//We get the action and execute
|
||||
$response = array();
|
||||
if (isset($data['data'])) {
|
||||
foreach ($data['data'] as $key => $val) {
|
||||
if (isset($val['action'])) {
|
||||
switch ($val['action']) {
|
||||
case 'delete':
|
||||
$response[] = array(
|
||||
'action' => $val['action'],
|
||||
'data'=> self::doBulkDelete($val['data'])
|
||||
);
|
||||
break;
|
||||
default:
|
||||
$response[] = array(
|
||||
'action' => $val['action'],
|
||||
'title' => 'Unknown action',
|
||||
'status' => '400',
|
||||
'detail' => "Unknown action.",
|
||||
'result' => false
|
||||
);
|
||||
//todo, we can add more bulk actions
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$result['data'] = $response;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bulk delete
|
||||
* We will delete many projects in bulk
|
||||
*
|
||||
* @param array $data, array of projectUid
|
||||
* @return array $response, information about the action with the projectUid
|
||||
*/
|
||||
public static function doBulkDelete($data)
|
||||
{
|
||||
//We reviewed the action in all projectUid
|
||||
$response = array();
|
||||
foreach ($data as $key => $val) {
|
||||
//Review if the type is "prj_uid"
|
||||
if (isset($val['prj_uid']) && !empty($val['prj_uid']) ) {
|
||||
//The project exist?
|
||||
if (!Bpmn::exists($val['prj_uid'])) {
|
||||
$response[] = array(
|
||||
'type' => $val['type'],
|
||||
'prj_uid' => $val['prj_uid'],
|
||||
'title' => 'Not found',
|
||||
'token' => strtotime("now"),
|
||||
'status' => '404',
|
||||
'detail' => "The row {$val['prj_uid']} in table Process doesn't exist!.",
|
||||
'result' => false
|
||||
);
|
||||
continue;
|
||||
}
|
||||
//The project has cases?
|
||||
$oBpmnWf = BpmnWorkflow::load($val['prj_uid']);
|
||||
if (!$oBpmnWf->canRemove()) {
|
||||
$response[] = array(
|
||||
'type' => $val['type'],
|
||||
'prj_uid' => $val['prj_uid'],
|
||||
'title' => 'Unable to delete project',
|
||||
'token' => strtotime("now"),
|
||||
'status' => '403',
|
||||
'detail' => "Project with prj_uid: {$val['prj_uid']} can not be deleted, it has started cases.",
|
||||
'result' => false
|
||||
|
||||
);
|
||||
continue;
|
||||
}
|
||||
//We will to remove
|
||||
$oBpmnWf = BpmnWorkflow::load($val['prj_uid']);
|
||||
$oBpmnWf->remove();
|
||||
$response[] = array(
|
||||
'type' => $val['type'],
|
||||
'prj_uid' => $val['prj_uid'],
|
||||
'status' => '200',
|
||||
'result' => true
|
||||
);
|
||||
} else {
|
||||
//Is not defined the "prj_uid"
|
||||
$response[] = array(
|
||||
'type' => $val['type'],
|
||||
'title' => 'Unknown field',
|
||||
'token' => strtotime("now"),
|
||||
'status' => '400',
|
||||
'detail' => "Unknown field.",
|
||||
'result' => false
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
$me = new self();
|
||||
$me->setContextLog($response);
|
||||
$me->syslog(
|
||||
'DoBulkDelete',
|
||||
200,
|
||||
'Do bulk delete',
|
||||
$me->getContextLog()
|
||||
);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function exists($projectUid)
|
||||
@@ -107,8 +306,8 @@ class Bpmn extends Handler
|
||||
$me = new self();
|
||||
$project = ProjectPeer::retrieveByPK($prjUid);
|
||||
|
||||
if (! is_object($project)) {
|
||||
throw new Exception\ProjectNotFound($me, $prjUid);
|
||||
if (!is_object($project)) {
|
||||
throw new ProjectNotFound($me, $prjUid);
|
||||
}
|
||||
|
||||
$me->project = $project;
|
||||
@@ -1463,5 +1662,31 @@ class Bpmn extends Handler
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logging information related to project
|
||||
* When the user doDeleteBulk
|
||||
*
|
||||
* @param string $channel
|
||||
* @param string $level
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
private function syslog(
|
||||
$channel,
|
||||
$level,
|
||||
$message,
|
||||
$context = array()
|
||||
)
|
||||
{
|
||||
try {
|
||||
Bootstrap::registerMonolog($channel, $level, $message, $context, $context['workspace'], 'processmaker.log');
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -139,6 +139,27 @@ class Project extends Api
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bulk actions
|
||||
* @url POST /bulk
|
||||
*
|
||||
* @access protected
|
||||
* @class AccessControl {@permission PM_FACTORY}
|
||||
*
|
||||
* @param array $request_data
|
||||
* @return array $response
|
||||
* @throws Exception
|
||||
*/
|
||||
public function bulk($request_data)
|
||||
{
|
||||
try {
|
||||
$response = Bpmn::doBulk($request_data);
|
||||
return $response;
|
||||
} catch (Exception $e) {
|
||||
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @url GET /:prj_uid/export/listObjects
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user