BPMN Project Import chages to import alll workflow properties data
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<?php
|
||||
namespace ProcessMaker\Importer;
|
||||
|
||||
use ProcessMaker\Project\Adapter;
|
||||
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