BPMN Project Import chages to import alll workflow properties data
This commit is contained in:
@@ -125,4 +125,25 @@ class Common
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function mk_dir($strPath, $rights = 0777)
|
||||
{
|
||||
$folder_path = array($strPath);
|
||||
$oldumask = umask(0);
|
||||
while (!@is_dir(dirname(end($folder_path)))
|
||||
&& dirname(end($folder_path)) != '/'
|
||||
&& dirname(end($folder_path)) != '.'
|
||||
&& dirname(end($folder_path)) != ''
|
||||
) {
|
||||
array_push($folder_path, dirname(end($folder_path)));
|
||||
}
|
||||
|
||||
while ($parent_folder_path = array_pop($folder_path)) {
|
||||
if (! @is_dir($parent_folder_path)) {
|
||||
if (! @mkdir($parent_folder_path, $rights)) {
|
||||
umask($oldumask);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1506,7 +1506,7 @@ class Processes
|
||||
$oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
|
||||
$oDataset->next();
|
||||
while ($aRow = $oDataset->getRow()) {
|
||||
$oInput = new Inputdocument();
|
||||
$oInput = new InputDocument();
|
||||
$aInput[] = $oInput->Load( $aRow['INP_DOC_UID'] );
|
||||
$oDataset->next();
|
||||
}
|
||||
@@ -1526,7 +1526,7 @@ class Processes
|
||||
public function createInputRows ($aInput)
|
||||
{
|
||||
foreach ($aInput as $key => $row) {
|
||||
$oInput = new Inputdocument();
|
||||
$oInput = new InputDocument();
|
||||
//unset ($row['TAS_UID']);
|
||||
if ($oInput->InputExists( $row['INP_DOC_UID'] )) {
|
||||
$oInput->remove( $row['INP_DOC_UID'] );
|
||||
@@ -1602,7 +1602,7 @@ class Processes
|
||||
$oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
|
||||
$oDataset->next();
|
||||
while ($aRow = $oDataset->getRow()) {
|
||||
$oOutput = new Outputdocument();
|
||||
$oOutput = new OutputDocument();
|
||||
$aOutput[] = $oOutput->Load( $aRow['OUT_DOC_UID'] );
|
||||
$oDataset->next();
|
||||
}
|
||||
@@ -1622,7 +1622,7 @@ class Processes
|
||||
public function createOutputRows ($aOutput)
|
||||
{
|
||||
foreach ($aOutput as $key => $row) {
|
||||
$oOutput = new Outputdocument();
|
||||
$oOutput = new OutputDocument();
|
||||
//unset ($row['TAS_UID']);
|
||||
if ($oOutput->OutputExists( $row['OUT_DOC_UID'] )) {
|
||||
$oOutput->remove( $row['OUT_DOC_UID'] );
|
||||
@@ -3559,13 +3559,59 @@ class Processes
|
||||
$this->createProcessCategoryRow( isset( $oData->processCategory ) ? $oData->processCategory : null );
|
||||
|
||||
// create the process
|
||||
$this->createProcessRow( $oData->process );
|
||||
// $this->createProcessRow( $oData->process );
|
||||
$this->createTaskRows( $oData->tasks );
|
||||
//it was commented becuase it seems to be working fine
|
||||
//$this->createEventRows(isset($oData->event) ? $oData->event : array());
|
||||
|
||||
|
||||
$aRoutesUID = $this->createRouteRows( $oData->routes );
|
||||
|
||||
$this->createProcessPropertiesFromData($oData);
|
||||
|
||||
// $this->createLaneRows( $oData->lanes );
|
||||
//
|
||||
//
|
||||
// if (isset( $oData->gateways )) {
|
||||
// $this->createGatewayRows( $oData->gateways );
|
||||
// }
|
||||
// $this->createDynaformRows( $oData->dynaforms );
|
||||
// $this->createInputRows( $oData->inputs );
|
||||
// $this->createOutputRows( $oData->outputs );
|
||||
// $this->createStepRows( $oData->steps );
|
||||
// $this->createStepSupervisorRows( isset( $oData->stepSupervisor ) ? $oData->stepSupervisor : array () );
|
||||
// $this->createTriggerRows( $oData->triggers );
|
||||
// $this->createStepTriggerRows( $oData->steptriggers );
|
||||
// $this->createTaskUserRows( $oData->taskusers );
|
||||
// $this->createGroupRow( $oData->groupwfs );
|
||||
// $this->createDBConnectionsRows( isset( $oData->dbconnections ) ? $oData->dbconnections : array () );
|
||||
// $this->createReportTables( isset( $oData->reportTables ) ? $oData->reportTables : array (), isset( $oData->reportTablesVars ) ? $oData->reportTablesVars : array () );
|
||||
// $this->createSubProcessRows( isset( $oData->subProcess ) ? $oData->subProcess : array () );
|
||||
// $this->createCaseTrackerRows( isset( $oData->caseTracker ) ? $oData->caseTracker : array () );
|
||||
// $this->createCaseTrackerObjectRows( isset( $oData->caseTrackerObject ) ? $oData->caseTrackerObject : array () );
|
||||
// $this->createObjectPermissionsRows( isset( $oData->objectPermissions ) ? $oData->objectPermissions : array () );
|
||||
// $this->createStageRows( isset( $oData->stage ) ? $oData->stage : array () );
|
||||
//
|
||||
// $this->createFieldCondition( isset( $oData->fieldCondition ) ? $oData->fieldCondition : array (), $oData->dynaforms );
|
||||
//
|
||||
// // Create before to createRouteRows for avoid duplicates
|
||||
// $this->createEventRows( isset( $oData->event ) ? $oData->event : array () );
|
||||
//
|
||||
// $this->createCaseSchedulerRows( isset( $oData->caseScheduler ) ? $oData->caseScheduler : array () );
|
||||
//
|
||||
// //Create data related to Configuration table
|
||||
// $this->createTaskExtraPropertiesRows( isset( $oData->taskExtraProperties ) ? $oData->taskExtraProperties : array () );
|
||||
|
||||
// and finally create the files, dynaforms (xml and html), emailTemplates and Public files
|
||||
$this->createFiles( $oData, $pmFilename );
|
||||
}
|
||||
|
||||
public function createProcessPropertiesFromData ($oData)
|
||||
{
|
||||
// (*) Creating process dependencies
|
||||
// creating the process category
|
||||
$this->createProcessCategoryRow( isset( $oData->processCategory ) ? $oData->processCategory : null );
|
||||
|
||||
$this->createLaneRows( $oData->lanes );
|
||||
|
||||
|
||||
@@ -3598,10 +3644,9 @@ class Processes
|
||||
|
||||
//Create data related to Configuration table
|
||||
$this->createTaskExtraPropertiesRows( isset( $oData->taskExtraProperties ) ? $oData->taskExtraProperties : array () );
|
||||
// and finally create the files, dynaforms (xml and html), emailTemplates and Public files
|
||||
$this->createFiles( $oData, $pmFilename );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* this function creates a new Process, defined in the object $oData
|
||||
*
|
||||
|
||||
@@ -87,7 +87,6 @@ abstract class Exporter
|
||||
|
||||
$oProcess = new \Processes();
|
||||
$workflowData = (array) $oProcess->getWorkflowData($this->prjUid);
|
||||
|
||||
$workflowData["process"]['PRO_DYNAFORMS'] = empty($workflowData["process"]['PRO_DYNAFORMS'])
|
||||
? "" : serialize($workflowData["process"]['PRO_DYNAFORMS']);
|
||||
|
||||
@@ -100,11 +99,9 @@ abstract class Exporter
|
||||
$data["workflow-files"] = array();
|
||||
|
||||
// getting dynaforms
|
||||
$dynaforms = array();
|
||||
|
||||
foreach ($workflowData["dynaforms"] as $dynaform) {
|
||||
$dynFile = PATH_DYNAFORM . $dynaform['DYN_FILENAME'] . '.xml';
|
||||
$dynaforms[] = array(
|
||||
$data["workflow-files"]["DYNAFORMS"][] = array(
|
||||
"filename" => $dynaform['DYN_TITLE'],
|
||||
"filepath" => $dynaform['DYN_FILENAME'] . '.xml',
|
||||
"file_content" => file_get_contents($dynFile)
|
||||
@@ -131,10 +128,10 @@ abstract class Exporter
|
||||
|
||||
foreach ($templatesFiles as $templatesFile) {
|
||||
if (is_dir($templatesFile)) continue;
|
||||
|
||||
$filename = basename($templatesFile);
|
||||
$data["workflow-files"][$target][] = array(
|
||||
"filename" => basename($templatesFile),
|
||||
"filepath" => str_replace($templatesDir, "", $templatesFile),
|
||||
"filename" => $filename,
|
||||
"filepath" => $this->prjUid . PATH_SEP . $filename,
|
||||
"file_content" => file_get_contents($templatesFile)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ class XmlExporter extends Exporter
|
||||
|
||||
private function getTextNode($value)
|
||||
{
|
||||
if (preg_match('/^[\w\s\.\-]+$/', $value, $match)) {
|
||||
if (empty($value) || preg_match('/^[\w\s\.\-]+$/', $value, $match)) {
|
||||
return $this->dom->createTextNode($value);
|
||||
} else {
|
||||
return $this->dom->createCDATASection($value);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
namespace ProcessMaker\Importer;
|
||||
|
||||
use ProcessMaker\Project\Adapter;
|
||||
use ProcessMaker\Util;
|
||||
|
||||
class XmlImporter extends Importer
|
||||
{
|
||||
@@ -79,8 +80,9 @@ class XmlImporter extends Importer
|
||||
|
||||
foreach ($recordsNode->childNodes as $columnNode) {
|
||||
if ($columnNode->nodeName == "#text") continue;
|
||||
//$columns[strtoupper($columnNode->nodeName)] = self::getNodeText($columnNode);;
|
||||
$columns[$columnNode->nodeName] = self::getNodeText($columnNode);;
|
||||
//$columns[strtoupper($columnNode->nodeName)] = self::createTextNode($columnNode);;
|
||||
$columnName = $defClass == "WORKFLOW" ? strtoupper($columnNode->nodeName) : $columnNode->nodeName;
|
||||
$columns[$columnName] = self::createTextNode($columnNode);
|
||||
}
|
||||
|
||||
$tables[$defClass][$tableName][] = $columns;
|
||||
@@ -101,12 +103,12 @@ class XmlImporter extends Importer
|
||||
$wfFiles[$target] = array();
|
||||
}
|
||||
|
||||
$fileContent = self::getNodeText($fileNode->getElementsByTagName("file_content")->item(0));
|
||||
$fileContent = self::createTextNode($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_name" => self::createTextNode($fileNode->getElementsByTagName("file_name")->item(0)),
|
||||
"file_path" => self::createTextNode($fileNode->getElementsByTagName("file_path")->item(0)),
|
||||
"file_content" => $fileContent
|
||||
);
|
||||
}
|
||||
@@ -114,12 +116,12 @@ class XmlImporter extends Importer
|
||||
|
||||
//print_r($tables);
|
||||
//print_r($wfFiles);
|
||||
return $tables;
|
||||
return array($tables, $wfFiles);
|
||||
}
|
||||
|
||||
public function import($data = array())
|
||||
{
|
||||
$tables = $this->load();
|
||||
list($tables, $files) = $this->load();
|
||||
|
||||
// Build BPMN project struct
|
||||
$project = $tables["BPMN"]["PROJECT"][0];
|
||||
@@ -136,10 +138,13 @@ class XmlImporter extends Importer
|
||||
$project["process"] = $tables["BPMN"]["PROCESS"][0];
|
||||
$result = Adapter\BpmnWorkflow::createFromStruct($project);
|
||||
|
||||
$this->importWfTables($tables["WORKFLOW"]);
|
||||
$this->importWfFiles($files);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private static function getNodeText($node)
|
||||
private static function createTextNode($node)
|
||||
{
|
||||
if ($node->nodeType == XML_ELEMENT_NODE) {
|
||||
return $node->textContent;
|
||||
@@ -147,4 +152,42 @@ class XmlImporter extends Importer
|
||||
return (string) simplexml_import_dom($node->parentNode);
|
||||
}
|
||||
}
|
||||
|
||||
private static function importWfFiles(array $workflowFiles)
|
||||
{
|
||||
foreach ($workflowFiles as $target => $files) {
|
||||
switch ($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 . $file["file_path"];
|
||||
$path = dirname($filename);
|
||||
|
||||
if (! is_dir($path)) {
|
||||
Util\Common::mk_dir($path, 0775);
|
||||
}
|
||||
|
||||
file_put_contents($filename, $file["file_content"]);
|
||||
chmod($filename, 0775);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function importWfTables($tables)
|
||||
{
|
||||
$tables = (object) $tables;
|
||||
|
||||
$processes = new \Processes();
|
||||
$processes->createProcessPropertiesFromData($tables);
|
||||
}
|
||||
}
|
||||
@@ -80,6 +80,16 @@ class BpmnWorkflow extends Project\Bpmn
|
||||
}
|
||||
}
|
||||
|
||||
public function update($data)
|
||||
{
|
||||
parent::update($data);
|
||||
$this->wp->update(array(
|
||||
"PRO_UID" => $data["PRJ_UID"],
|
||||
"PRO_TITLE" => $data["PRJ_NAME"],
|
||||
"PRO_DESCRIPTION" => $data["PRJ_DESCRIPTION"],
|
||||
));
|
||||
}
|
||||
|
||||
public static function getList($start = null, $limit = null, $filter = "", $changeCaseTo = CASE_UPPER)
|
||||
{
|
||||
$bpmnProjects = parent::getList($start, $limit, $filter);
|
||||
@@ -403,7 +413,7 @@ class BpmnWorkflow extends Project\Bpmn
|
||||
$this->wp->remove();
|
||||
}
|
||||
|
||||
public static function createFromStruct($projectData)
|
||||
public static function createFromStruct(array $projectData)
|
||||
{
|
||||
$bwp = new self;
|
||||
$result = array();
|
||||
@@ -423,8 +433,18 @@ class BpmnWorkflow extends Project\Bpmn
|
||||
"PRJ_UID" => $projectData["prj_uid"],
|
||||
"PRJ_AUTHOR" => $projectData["prj_author"]
|
||||
));
|
||||
$bwp->addDiagram(array_change_key_case($projectData["diagrams"][0], CASE_UPPER));
|
||||
$bwp->addProcess(array_change_key_case($projectData["process"], CASE_UPPER));
|
||||
|
||||
$diagramData = $processData = array();
|
||||
|
||||
if (array_key_exists("diagrams", $projectData) && is_array($projectData["diagrams"]) && count($projectData["diagrams"]) > 0) {
|
||||
$diagramData = array_change_key_case($projectData["diagrams"][0], CASE_UPPER);
|
||||
}
|
||||
if (array_key_exists("process", $projectData) && is_array($projectData["process"])) {
|
||||
$processData = array_change_key_case($projectData["process"], CASE_UPPER);
|
||||
}
|
||||
|
||||
$bwp->addDiagram($diagramData);
|
||||
$bwp->addProcess($processData);
|
||||
|
||||
$result = array_merge($result, self::updateFromStruct($bwp->prjUid, $projectData));
|
||||
|
||||
@@ -530,7 +550,8 @@ class BpmnWorkflow extends Project\Bpmn
|
||||
$diagram = isset($projectData["diagrams"]) && isset($projectData["diagrams"][0]) ? $projectData["diagrams"][0] : array();
|
||||
$result = array();
|
||||
$bwp = BpmnWorkflow::load($prjUid);
|
||||
//var_dump($bwp->getUid()); die;
|
||||
$projectRecord = array_change_key_case($projectData, CASE_UPPER);
|
||||
$bwp->update($projectRecord);
|
||||
|
||||
/*
|
||||
* Diagram's Activities Handling
|
||||
@@ -636,7 +657,7 @@ class BpmnWorkflow extends Project\Bpmn
|
||||
// looking for removed elements
|
||||
foreach ($events as $eventData) {
|
||||
if (! in_array($eventData["EVN_UID"], $whiteList)) {
|
||||
// If it is not in the white list so, then remove them
|
||||
// If it is not in the white list, then remove them
|
||||
$bwp->removeEvent($eventData["EVN_UID"]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,9 +111,21 @@ class Bpmn extends Handler
|
||||
self::log("Create Project Success!");
|
||||
}
|
||||
|
||||
public function update()
|
||||
public function update($data)
|
||||
{
|
||||
if (array_key_exists("PRJ_CREATE_DATE", $data) && empty($data["PRJ_CREATE_DATE"])) {
|
||||
unset($data["PRJ_UPDATE_DATE"]);
|
||||
}
|
||||
|
||||
if (array_key_exists("PRJ_UPDATE_DATE", $data)) {
|
||||
unset($data["PRJ_UPDATE_DATE"]);
|
||||
}
|
||||
|
||||
$this->project->fromArray($data, BasePeer::TYPE_FIELDNAME);
|
||||
$this->project->setPrjUpdateDate(date("Y-m-d H:i:s"));
|
||||
$this->project->save();
|
||||
|
||||
$this->updateDiagram(array("DIA_NAME" => $data["PRJ_NAME"]));
|
||||
}
|
||||
|
||||
public function remove()
|
||||
@@ -209,6 +221,19 @@ class Bpmn extends Handler
|
||||
$this->diagram->save();
|
||||
}
|
||||
|
||||
public function updateDiagram($data)
|
||||
{
|
||||
if (empty($this->project)) {
|
||||
throw new \Exception("Error: There is not an initialized project.");
|
||||
}
|
||||
if (! is_object($this->diagram)) {
|
||||
$this->getDiagram();
|
||||
}
|
||||
|
||||
$this->diagram->fromArray($data, BasePeer::TYPE_FIELDNAME);
|
||||
$this->diagram->save();
|
||||
}
|
||||
|
||||
public function getDiagram($retType = "array")
|
||||
{
|
||||
if (empty($this->diagram)) {
|
||||
|
||||
@@ -95,9 +95,10 @@ class Workflow extends Handler
|
||||
}
|
||||
}
|
||||
|
||||
public function update()
|
||||
public function update($data)
|
||||
{
|
||||
// TODO: Implement update() method.
|
||||
$process = new Process();
|
||||
$process->update($data);
|
||||
}
|
||||
|
||||
public function remove()
|
||||
@@ -755,11 +756,11 @@ class Workflow extends Handler
|
||||
//Delete the process
|
||||
try {
|
||||
$oProcess->remove($sProcessUID);
|
||||
} catch (Exception $oError) {
|
||||
} catch (\Exception $oError) {
|
||||
throw ($oError);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception $oError) {
|
||||
} catch (\Exception $oError) {
|
||||
throw ($oError);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user