BPMN Project Import chages to import alll workflow properties data

This commit is contained in:
Erik Amaru Ortiz
2014-03-27 19:11:11 -04:00
parent edaf69ec0e
commit 00fd862056
8 changed files with 187 additions and 34 deletions

View File

@@ -125,4 +125,25 @@ class Common
return $result; 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);
}
}
}
}
} }

View File

@@ -1506,7 +1506,7 @@ class Processes
$oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
$oDataset->next(); $oDataset->next();
while ($aRow = $oDataset->getRow()) { while ($aRow = $oDataset->getRow()) {
$oInput = new Inputdocument(); $oInput = new InputDocument();
$aInput[] = $oInput->Load( $aRow['INP_DOC_UID'] ); $aInput[] = $oInput->Load( $aRow['INP_DOC_UID'] );
$oDataset->next(); $oDataset->next();
} }
@@ -1526,7 +1526,7 @@ class Processes
public function createInputRows ($aInput) public function createInputRows ($aInput)
{ {
foreach ($aInput as $key => $row) { foreach ($aInput as $key => $row) {
$oInput = new Inputdocument(); $oInput = new InputDocument();
//unset ($row['TAS_UID']); //unset ($row['TAS_UID']);
if ($oInput->InputExists( $row['INP_DOC_UID'] )) { if ($oInput->InputExists( $row['INP_DOC_UID'] )) {
$oInput->remove( $row['INP_DOC_UID'] ); $oInput->remove( $row['INP_DOC_UID'] );
@@ -1602,7 +1602,7 @@ class Processes
$oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
$oDataset->next(); $oDataset->next();
while ($aRow = $oDataset->getRow()) { while ($aRow = $oDataset->getRow()) {
$oOutput = new Outputdocument(); $oOutput = new OutputDocument();
$aOutput[] = $oOutput->Load( $aRow['OUT_DOC_UID'] ); $aOutput[] = $oOutput->Load( $aRow['OUT_DOC_UID'] );
$oDataset->next(); $oDataset->next();
} }
@@ -1622,7 +1622,7 @@ class Processes
public function createOutputRows ($aOutput) public function createOutputRows ($aOutput)
{ {
foreach ($aOutput as $key => $row) { foreach ($aOutput as $key => $row) {
$oOutput = new Outputdocument(); $oOutput = new OutputDocument();
//unset ($row['TAS_UID']); //unset ($row['TAS_UID']);
if ($oOutput->OutputExists( $row['OUT_DOC_UID'] )) { if ($oOutput->OutputExists( $row['OUT_DOC_UID'] )) {
$oOutput->remove( $row['OUT_DOC_UID'] ); $oOutput->remove( $row['OUT_DOC_UID'] );
@@ -3559,13 +3559,59 @@ class Processes
$this->createProcessCategoryRow( isset( $oData->processCategory ) ? $oData->processCategory : null ); $this->createProcessCategoryRow( isset( $oData->processCategory ) ? $oData->processCategory : null );
// create the process // create the process
$this->createProcessRow( $oData->process ); // $this->createProcessRow( $oData->process );
$this->createTaskRows( $oData->tasks ); $this->createTaskRows( $oData->tasks );
//it was commented becuase it seems to be working fine //it was commented becuase it seems to be working fine
//$this->createEventRows(isset($oData->event) ? $oData->event : array()); //$this->createEventRows(isset($oData->event) ? $oData->event : array());
$aRoutesUID = $this->createRouteRows( $oData->routes ); $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 ); $this->createLaneRows( $oData->lanes );
@@ -3598,10 +3644,9 @@ class Processes
//Create data related to Configuration table //Create data related to Configuration table
$this->createTaskExtraPropertiesRows( isset( $oData->taskExtraProperties ) ? $oData->taskExtraProperties : array () ); $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 * this function creates a new Process, defined in the object $oData
* *

View File

@@ -87,7 +87,6 @@ abstract class Exporter
$oProcess = new \Processes(); $oProcess = new \Processes();
$workflowData = (array) $oProcess->getWorkflowData($this->prjUid); $workflowData = (array) $oProcess->getWorkflowData($this->prjUid);
$workflowData["process"]['PRO_DYNAFORMS'] = empty($workflowData["process"]['PRO_DYNAFORMS']) $workflowData["process"]['PRO_DYNAFORMS'] = empty($workflowData["process"]['PRO_DYNAFORMS'])
? "" : serialize($workflowData["process"]['PRO_DYNAFORMS']); ? "" : serialize($workflowData["process"]['PRO_DYNAFORMS']);
@@ -100,11 +99,9 @@ abstract class Exporter
$data["workflow-files"] = array(); $data["workflow-files"] = array();
// getting dynaforms // getting dynaforms
$dynaforms = array();
foreach ($workflowData["dynaforms"] as $dynaform) { foreach ($workflowData["dynaforms"] as $dynaform) {
$dynFile = PATH_DYNAFORM . $dynaform['DYN_FILENAME'] . '.xml'; $dynFile = PATH_DYNAFORM . $dynaform['DYN_FILENAME'] . '.xml';
$dynaforms[] = array( $data["workflow-files"]["DYNAFORMS"][] = array(
"filename" => $dynaform['DYN_TITLE'], "filename" => $dynaform['DYN_TITLE'],
"filepath" => $dynaform['DYN_FILENAME'] . '.xml', "filepath" => $dynaform['DYN_FILENAME'] . '.xml',
"file_content" => file_get_contents($dynFile) "file_content" => file_get_contents($dynFile)
@@ -131,10 +128,10 @@ abstract class Exporter
foreach ($templatesFiles as $templatesFile) { foreach ($templatesFiles as $templatesFile) {
if (is_dir($templatesFile)) continue; if (is_dir($templatesFile)) continue;
$filename = basename($templatesFile);
$data["workflow-files"][$target][] = array( $data["workflow-files"][$target][] = array(
"filename" => basename($templatesFile), "filename" => $filename,
"filepath" => str_replace($templatesDir, "", $templatesFile), "filepath" => $this->prjUid . PATH_SEP . $filename,
"file_content" => file_get_contents($templatesFile) "file_content" => file_get_contents($templatesFile)
); );
} }

View File

@@ -135,7 +135,7 @@ class XmlExporter extends Exporter
private function getTextNode($value) 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); return $this->dom->createTextNode($value);
} else { } else {
return $this->dom->createCDATASection($value); return $this->dom->createCDATASection($value);

View File

@@ -1,7 +1,8 @@
<?php <?php
namespace ProcessMaker\Importer; namespace ProcessMaker\Importer;
use ProcessMaker\Project\Adapter; use ProcessMaker\Project\Adapter;
use ProcessMaker\Util;
class XmlImporter extends Importer class XmlImporter extends Importer
{ {
@@ -79,8 +80,9 @@ class XmlImporter extends Importer
foreach ($recordsNode->childNodes as $columnNode) { foreach ($recordsNode->childNodes as $columnNode) {
if ($columnNode->nodeName == "#text") continue; if ($columnNode->nodeName == "#text") continue;
//$columns[strtoupper($columnNode->nodeName)] = self::getNodeText($columnNode);; //$columns[strtoupper($columnNode->nodeName)] = self::createTextNode($columnNode);;
$columns[$columnNode->nodeName] = self::getNodeText($columnNode);; $columnName = $defClass == "WORKFLOW" ? strtoupper($columnNode->nodeName) : $columnNode->nodeName;
$columns[$columnName] = self::createTextNode($columnNode);
} }
$tables[$defClass][$tableName][] = $columns; $tables[$defClass][$tableName][] = $columns;
@@ -101,12 +103,12 @@ class XmlImporter extends Importer
$wfFiles[$target] = array(); $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); $fileContent = base64_decode($fileContent);
$wfFiles[$target][] = array( $wfFiles[$target][] = array(
"file_name" => self::getNodeText($fileNode->getElementsByTagName("file_name")->item(0)), "file_name" => self::createTextNode($fileNode->getElementsByTagName("file_name")->item(0)),
"file_path" => self::getNodeText($fileNode->getElementsByTagName("file_path")->item(0)), "file_path" => self::createTextNode($fileNode->getElementsByTagName("file_path")->item(0)),
"file_content" => $fileContent "file_content" => $fileContent
); );
} }
@@ -114,12 +116,12 @@ class XmlImporter extends Importer
//print_r($tables); //print_r($tables);
//print_r($wfFiles); //print_r($wfFiles);
return $tables; return array($tables, $wfFiles);
} }
public function import($data = array()) public function import($data = array())
{ {
$tables = $this->load(); list($tables, $files) = $this->load();
// Build BPMN project struct // Build BPMN project struct
$project = $tables["BPMN"]["PROJECT"][0]; $project = $tables["BPMN"]["PROJECT"][0];
@@ -136,10 +138,13 @@ class XmlImporter extends Importer
$project["process"] = $tables["BPMN"]["PROCESS"][0]; $project["process"] = $tables["BPMN"]["PROCESS"][0];
$result = Adapter\BpmnWorkflow::createFromStruct($project); $result = Adapter\BpmnWorkflow::createFromStruct($project);
$this->importWfTables($tables["WORKFLOW"]);
$this->importWfFiles($files);
return $result; return $result;
} }
private static function getNodeText($node) private static function createTextNode($node)
{ {
if ($node->nodeType == XML_ELEMENT_NODE) { if ($node->nodeType == XML_ELEMENT_NODE) {
return $node->textContent; return $node->textContent;
@@ -147,4 +152,42 @@ class XmlImporter extends Importer
return (string) simplexml_import_dom($node->parentNode); 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);
}
} }

View File

@@ -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) public static function getList($start = null, $limit = null, $filter = "", $changeCaseTo = CASE_UPPER)
{ {
$bpmnProjects = parent::getList($start, $limit, $filter); $bpmnProjects = parent::getList($start, $limit, $filter);
@@ -403,7 +413,7 @@ class BpmnWorkflow extends Project\Bpmn
$this->wp->remove(); $this->wp->remove();
} }
public static function createFromStruct($projectData) public static function createFromStruct(array $projectData)
{ {
$bwp = new self; $bwp = new self;
$result = array(); $result = array();
@@ -423,8 +433,18 @@ class BpmnWorkflow extends Project\Bpmn
"PRJ_UID" => $projectData["prj_uid"], "PRJ_UID" => $projectData["prj_uid"],
"PRJ_AUTHOR" => $projectData["prj_author"] "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)); $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(); $diagram = isset($projectData["diagrams"]) && isset($projectData["diagrams"][0]) ? $projectData["diagrams"][0] : array();
$result = array(); $result = array();
$bwp = BpmnWorkflow::load($prjUid); $bwp = BpmnWorkflow::load($prjUid);
//var_dump($bwp->getUid()); die; $projectRecord = array_change_key_case($projectData, CASE_UPPER);
$bwp->update($projectRecord);
/* /*
* Diagram's Activities Handling * Diagram's Activities Handling
@@ -636,7 +657,7 @@ class BpmnWorkflow extends Project\Bpmn
// looking for removed elements // looking for removed elements
foreach ($events as $eventData) { foreach ($events as $eventData) {
if (! in_array($eventData["EVN_UID"], $whiteList)) { 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"]); $bwp->removeEvent($eventData["EVN_UID"]);
} }
} }

View File

@@ -111,9 +111,21 @@ class Bpmn extends Handler
self::log("Create Project Success!"); 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() public function remove()
@@ -209,6 +221,19 @@ class Bpmn extends Handler
$this->diagram->save(); $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") public function getDiagram($retType = "array")
{ {
if (empty($this->diagram)) { if (empty($this->diagram)) {

View File

@@ -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() public function remove()
@@ -755,11 +756,11 @@ class Workflow extends Handler
//Delete the process //Delete the process
try { try {
$oProcess->remove($sProcessUID); $oProcess->remove($sProcessUID);
} catch (Exception $oError) { } catch (\Exception $oError) {
throw ($oError); throw ($oError);
} }
return true; return true;
} catch (Exception $oError) { } catch (\Exception $oError) {
throw ($oError); throw ($oError);
} }
} }