Updating Exporter and XmlExporter classes
This commit is contained in:
@@ -2,30 +2,73 @@
|
||||
namespace ProcessMaker\Exporter;
|
||||
|
||||
use ProcessMaker\Project;
|
||||
use ProcessMaker\Util;
|
||||
|
||||
abstract class Exporter
|
||||
{
|
||||
/**
|
||||
* @var string The Project UID
|
||||
*/
|
||||
protected $prjUid;
|
||||
|
||||
/**
|
||||
* Exporter version
|
||||
*/
|
||||
const VERSION = "2.0";
|
||||
|
||||
/**
|
||||
* @var \ProcessMaker\Project\Adapter\BpmnWorkflow
|
||||
*/
|
||||
protected $bpmnProject;
|
||||
|
||||
protected $projectData;
|
||||
|
||||
public function __construct($prjUid)
|
||||
{
|
||||
$this->prjUid = $prjUid;
|
||||
|
||||
$this->bpmnProject = Project\Bpmn::load($prjUid);
|
||||
$this->projectData = $this->bpmnProject->getProject();
|
||||
}
|
||||
|
||||
public function buildData()
|
||||
/**
|
||||
* Builds Output content of exported project
|
||||
*
|
||||
* @return string xml output of exported project
|
||||
*/
|
||||
public abstract function export();
|
||||
|
||||
/**
|
||||
* Builds Output content of exported project and save it into a given file path
|
||||
*
|
||||
* @param string $outputFile path of output file
|
||||
* @return mixed
|
||||
*/
|
||||
public abstract function saveExport($outputFile);
|
||||
|
||||
/**
|
||||
* Builds exported content of a Project
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public abstract function build();
|
||||
|
||||
public function getProjectName()
|
||||
{
|
||||
return $this->projectData["PRJ_NAME"];
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds Project Data Structure
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function buildData()
|
||||
{
|
||||
$data = array();
|
||||
$project = $this->bpmnProject->getProject();
|
||||
$data["METADATA"] = $this->getSystemInfo();
|
||||
$data["METADATA"]["project_name"] = $project["PRJ_NAME"];
|
||||
|
||||
$data["Metadata"] = $this->getMetadata();
|
||||
$data["Metadata"]["project_name"] = $this->getProjectName();
|
||||
|
||||
$bpmnStruct["ACTIVITY"] = \BpmnActivity::getAll($this->prjUid);
|
||||
$bpmnStruct["BOUND"] = \BpmnBound::getAll($this->prjUid);
|
||||
@@ -42,16 +85,15 @@ abstract class Exporter
|
||||
$bpmnStruct["PROCESS"] = \BpmnProcess::getAll($this->prjUid);
|
||||
$bpmnStruct["PROJECT"] = array(\BpmnProjectPeer::retrieveByPK($this->prjUid)->toArray());
|
||||
|
||||
\G::LoadClass( 'processes' );
|
||||
$oProcess = new \Processes();
|
||||
$workflowData = (array) $oProcess->getWorkflowData($this->prjUid);
|
||||
$workflowData["process"] = array($workflowData["process"]);
|
||||
$workflowData["processCategory"] = empty($workflowData["processCategory"]) ? array() : $workflowData["processCategory"];
|
||||
|
||||
|
||||
$data["BPMN_DATA"] = $bpmnStruct;
|
||||
$data["WORKFLOW_DATA"] = $workflowData;
|
||||
$data["WORKFLOW_FILES"] = array();
|
||||
$data["BPMN-Definition"] = $bpmnStruct;
|
||||
$data["Workflow-Definition"] = $workflowData;
|
||||
$data["Workflow-Files"] = array();
|
||||
|
||||
// getting dynaforms
|
||||
$dynaforms = array();
|
||||
@@ -67,7 +109,7 @@ abstract class Exporter
|
||||
$htmlFile = PATH_DYNAFORM . $dynaform['DYN_FILENAME'] . '.html';
|
||||
|
||||
if (file_exists($htmlFile)) {
|
||||
$data["WORKFLOW_FILES"]["DYNAFORMS"][] = array(
|
||||
$data["Workflow-Files"]["DYNAFORMS"][] = array(
|
||||
"filename" => $dynaform['DYN_FILENAME'] . '.html',
|
||||
"filepath" => $dynaform['DYN_FILENAME'] . '.html',
|
||||
"file_content" => file_get_contents($htmlFile)
|
||||
@@ -81,12 +123,12 @@ abstract class Exporter
|
||||
|
||||
foreach ($workspaceTargetDirs as $target => $workspaceTargetDir) {
|
||||
$templatesDir = $workspaceDir . $workspaceTargetDir . PATH_SEP . $this->prjUid;
|
||||
$templatesFiles = \G::rglob("*", 0, $templatesDir);
|
||||
$templatesFiles = Util\Common::rglob("$templatesDir/*", 0, true);
|
||||
|
||||
foreach ($templatesFiles as $templatesFile) {
|
||||
if (is_dir($templatesFile)) continue;
|
||||
|
||||
$data["WORKFLOW_FILES"][$target][] = array(
|
||||
$data["Workflow-Files"][$target][] = array(
|
||||
"filename" => basename($templatesFile),
|
||||
"filepath" => str_replace($templatesDir, "", $templatesFile),
|
||||
"file_content" => file_get_contents($templatesFile)
|
||||
@@ -97,13 +139,42 @@ abstract class Exporter
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getSystemInfo()
|
||||
/**
|
||||
* Returns the container name of project data structure
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContainerName()
|
||||
{
|
||||
return "ProcessMaker-Project";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the exporter version
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getVersion()
|
||||
{
|
||||
return self::VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all metadata to include on export content
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMetadata()
|
||||
{
|
||||
return array(
|
||||
"vendor" => "ProcessMaker",
|
||||
"codename" => "Michelangelo",
|
||||
"version" => \System::getVersion(),
|
||||
"workspace" => defined("SYS_SYS") ? SYS_SYS : "Unknown",
|
||||
"vendor_version" => \System::getVersion(),
|
||||
"vendor_version_code" => "Michelangelo",
|
||||
"export_timestamp" => date("U"),
|
||||
"export_datetime" => date("F l j, Y - H:i:s (e, \G\M\TP)"),
|
||||
"export_server_addr" => isset($_SERVER["SERVER_ADDR"]) ? $_SERVER["SERVER_ADDR"].":".$_SERVER["SERVER_PORT"] : "Unknown",
|
||||
"export_server_os" => PHP_OS ,
|
||||
"export_server_php_version" => PHP_VERSION_ID,
|
||||
"project_workspace" => defined("SYS_SYS") ? SYS_SYS : "Unknown",
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,38 +1,58 @@
|
||||
<?php
|
||||
namespace ProcessMaker\Exporter;
|
||||
|
||||
/**
|
||||
* Class XmlExporter
|
||||
*
|
||||
* @package ProcessMaker\Exporter
|
||||
* @author Erik Amaru Ortiz <erik@coilosa.com>
|
||||
*/
|
||||
class XmlExporter extends Exporter
|
||||
{
|
||||
/**
|
||||
* @var \DOMDocument
|
||||
*/
|
||||
protected $dom;
|
||||
|
||||
/**
|
||||
* @var \DOMElement
|
||||
*/
|
||||
protected $rootNode;
|
||||
|
||||
/**
|
||||
* XmlExporter Constructor
|
||||
*
|
||||
* @param $prjUid
|
||||
*
|
||||
*/
|
||||
public function __construct($prjUid)
|
||||
{
|
||||
parent::__construct($prjUid);
|
||||
|
||||
/* @var $this->dom DomDocument */
|
||||
$this->dom = new \DOMDocument("1.0", "utf-8"); //\DOMImplementation::createDocument(null, 'project');
|
||||
$this->dom = new \DOMDocument("1.0", "utf-8");
|
||||
$this->dom->formatOutput = true;
|
||||
|
||||
$this->rootNode = $this->dom->createElement("PROJECT");
|
||||
$this->rootNode->setAttribute("version", "1.0");
|
||||
$this->dom->appendChild($this->rootNode);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @inherits
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
$this->rootNode = $this->dom->createElement($this->getContainerName());
|
||||
$this->rootNode->setAttribute("version", self::getVersion());
|
||||
$this->dom->appendChild($this->rootNode);
|
||||
|
||||
$data = $this->buildData();
|
||||
|
||||
// metadata set up
|
||||
$metadata = $data["METADATA"];
|
||||
$metadataNode = $this->dom->createElement("METADATA");
|
||||
$metadata = $data["Metadata"];
|
||||
$metadataNode = $this->dom->createElement("Metadata");
|
||||
|
||||
foreach ($metadata as $key => $value) {
|
||||
$metaNode = $this->dom->createElement("META");
|
||||
$metaNode->setAttribute("key", $key);
|
||||
$metaNode->setAttribute("value", $value);
|
||||
$metaNode = $this->dom->createElement("meta:$key");
|
||||
//$metaNode->setAttribute("key", $key);
|
||||
//$metaNode->setAttribute("value", $value);
|
||||
$metaNode->appendChild($this->dom->createTextNode($value));
|
||||
$metadataNode->appendChild($metaNode);
|
||||
}
|
||||
|
||||
@@ -40,21 +60,26 @@ class XmlExporter extends Exporter
|
||||
// end setting metadata
|
||||
|
||||
// bpmn struct data set up
|
||||
$dbData = array("BPMN_DATA" => $data["BPMN_DATA"], "WORKFLOW_DATA" => $data["WORKFLOW_DATA"]);
|
||||
$dbData = array("BPMN" => $data["BPMN-Definition"], "Workflow" => $data["Workflow-Definition"]);
|
||||
//file_put_contents("/home/erik/out.log", print_r($dbData, true)); die;
|
||||
foreach ($dbData as $sectionName => $sectionData) {
|
||||
$dataNode = $this->dom->createElement($sectionName);
|
||||
$dataNode = $this->dom->createElement("Definition");
|
||||
$dataNode->setAttribute("class", $sectionName);
|
||||
|
||||
foreach ($sectionData as $elementName => $elementData) {
|
||||
$elementNode = $this->dom->createElement(strtoupper($elementName));
|
||||
$elementNode = $this->dom->createElement("table");
|
||||
$elementNode->setAttribute("name", $elementName);
|
||||
|
||||
foreach ($elementData as $recordData) {
|
||||
$recordNode = $this->dom->createElement("ROW");
|
||||
$recordNode = $this->dom->createElement("record");
|
||||
$recordData = array_change_key_case($recordData, CASE_LOWER);
|
||||
//var_dump($recordData); die;
|
||||
|
||||
|
||||
foreach ($recordData as $key => $value) {
|
||||
$columnNode = $this->dom->createElement(strtoupper($key));
|
||||
$columnNode = $this->dom->createElement($key);
|
||||
|
||||
if (preg_match('/^[\w\s]+$/', $value, $match) || empty($value)) {
|
||||
if (preg_match('/^[\w\s\.]+$/', $value, $match) || empty($value)) {
|
||||
$textNode = $this->dom->createTextNode($value);
|
||||
} else {
|
||||
$textNode = $this->dom->createCDATASection($value);
|
||||
@@ -73,23 +98,27 @@ class XmlExporter extends Exporter
|
||||
$this->rootNode->appendChild($dataNode);
|
||||
}
|
||||
|
||||
$workflowFilesNode = $this->dom->createElement("WORKFLOW_FILES");
|
||||
$workflowFilesNode = $this->dom->createElement("Workflow-Files");
|
||||
|
||||
// workflow dynaforms files
|
||||
foreach ($data["WORKFLOW_FILES"] as $elementName => $elementData) {
|
||||
foreach ($data["Workflow-Files"] as $elementName => $elementData) {
|
||||
foreach ($elementData as $fileData) {
|
||||
$fileNode = $this->dom->createElement("FILE");
|
||||
$fileNode = $this->dom->createElement("file");
|
||||
$fileNode->setAttribute("target", strtolower($elementName));
|
||||
|
||||
$filenameNode = $this->dom->createElement("FILE_NAME");
|
||||
$filenameNode->appendChild($this->dom->createCDATASection($fileData["filename"]));
|
||||
$filenameNode = $this->dom->createElement("file_name");
|
||||
if (preg_match('/^[\w\s\.\-]+$/', $fileData["filename"], $match)) {
|
||||
$filenameNode->appendChild($this->dom->createTextNode($fileData["filename"]));
|
||||
} else {
|
||||
$filenameNode->appendChild($this->dom->createCDATASection($fileData["filename"]));
|
||||
}
|
||||
$fileNode->appendChild($filenameNode);
|
||||
|
||||
$filepathNode = $this->dom->createElement("FILE_PATH");
|
||||
$filepathNode = $this->dom->createElement("file_path");
|
||||
$filepathNode->appendChild($this->dom->createCDATASection($fileData["filepath"]));
|
||||
$fileNode->appendChild($filepathNode);
|
||||
|
||||
$fileContentNode = $this->dom->createElement("FILE_CONTENT");
|
||||
$fileContentNode = $this->dom->createElement("file_content");
|
||||
$fileContentNode->appendChild($this->dom->createCDATASection(base64_encode($fileData["file_content"])));
|
||||
$fileNode->appendChild($fileContentNode);
|
||||
|
||||
@@ -100,13 +129,21 @@ class XmlExporter extends Exporter
|
||||
$this->rootNode->appendChild($workflowFilesNode);
|
||||
}
|
||||
|
||||
public function save($outputFile)
|
||||
/**
|
||||
* @inherits
|
||||
*/
|
||||
public function saveExport($outputFile)
|
||||
{
|
||||
file_put_contents($outputFile, $this->export());
|
||||
chmod($outputFile, 0755);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inherits
|
||||
*/
|
||||
public function export()
|
||||
{
|
||||
$this->build();
|
||||
return $this->dom->saveXml();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user