Adding the PMXGenerator class and some granular definitions.
This commit is contained in:
@@ -5,6 +5,6 @@ namespace ProcessMaker\BusinessModel\Migrator;
|
|||||||
interface Exportable
|
interface Exportable
|
||||||
{
|
{
|
||||||
public function beforeExport();
|
public function beforeExport();
|
||||||
public function export();
|
public function export($prj_uid);
|
||||||
public function afterExport();
|
public function afterExport();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Created by PhpStorm.
|
* ProcessMaker.
|
||||||
* User: gustav
|
|
||||||
* Date: 3/18/16
|
|
||||||
* Time: 10:14 AM
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace ProcessMaker\BusinessModel\Migrator;
|
namespace ProcessMaker\BusinessModel\Migrator;
|
||||||
|
|
||||||
|
|
||||||
class GranularExporter
|
class GranularExporter
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $factory;
|
protected $factory;
|
||||||
|
protected $publisher;
|
||||||
protected $data;
|
protected $data;
|
||||||
/**
|
/**
|
||||||
* GranularExporter constructor.
|
* GranularExporter constructor.
|
||||||
@@ -20,6 +16,7 @@ class GranularExporter
|
|||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->factory = new MigratorFactory();
|
$this->factory = new MigratorFactory();
|
||||||
|
$this->publisher = new PMXGenerator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function export($objectList)
|
public function export($objectList)
|
||||||
@@ -29,11 +26,34 @@ class GranularExporter
|
|||||||
$migratorData = $migrator->export($data);
|
$migratorData = $migrator->export($data);
|
||||||
$this->prepareData($migratorData);
|
$this->prepareData($migratorData);
|
||||||
}
|
}
|
||||||
return $this->data;
|
return $this->publish();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function prepareData($migratorData)
|
protected function beforeExport()
|
||||||
{
|
{
|
||||||
$this->data = $this->data . $migratorData;
|
$data = array();
|
||||||
|
$data["version"] = "3.0";
|
||||||
|
$data["container"] = "ProcessMaker-Project";
|
||||||
|
$data["metadata"] = $this->getMetadata();
|
||||||
|
$data["metadata"]["workspace"] = defined("SYS_SYS") ? SYS_SYS : "Unknown";
|
||||||
|
$data["metadata"]["name"] = $this->getProjectName();
|
||||||
|
$data["metadata"]["uid"] = $this->getProjectUid();
|
||||||
|
$this->data = $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function addData($migratorData)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//$this->data = $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function publish()
|
||||||
|
{
|
||||||
|
return $this->generator->generate(
|
||||||
|
$this->data
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace ProcessMaker\BusinessModel\Migrator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class PMXGenerator
|
||||||
|
* This class generates the a PMX class based on the data passed on the generate method.
|
||||||
|
*
|
||||||
|
* @package ProcessMaker\BusinessModel\Migrator
|
||||||
|
*/
|
||||||
|
|
||||||
|
class PMXGenerator
|
||||||
|
{
|
||||||
|
protected $domDocument;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PMXPublisher constructor.
|
||||||
|
* @param $domDocument
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->domDocument = new \DOMDocument("1.0", "utf-8");
|
||||||
|
$this->domDocument->formatOutput = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a PMX xml string based on the $data passed along.
|
||||||
|
*
|
||||||
|
* @param $data
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function generate($data)
|
||||||
|
{
|
||||||
|
$rootNode = $this->domDocument->createElement($data['container_name']);
|
||||||
|
$rootNode->setAttribute("version", $data['container_name']);
|
||||||
|
$this->domDocument->appendChild($rootNode);
|
||||||
|
|
||||||
|
$metadata = $data["metadata"];
|
||||||
|
$metadataNode = $this->domDocument->createElement("metadata");
|
||||||
|
|
||||||
|
foreach ($metadata as $key => $value) {
|
||||||
|
$metaNode = $this->domDocument->createElement("meta");
|
||||||
|
$metaNode->setAttribute("key", $key);
|
||||||
|
$metaNode->appendChild($this->getTextNode($value));
|
||||||
|
$metadataNode->appendChild($metaNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
$rootNode->appendChild($metadataNode);
|
||||||
|
|
||||||
|
$dbData = array("BPMN" => $data["bpmn-definition"], "workflow" => $data["workflow-definition"]);
|
||||||
|
foreach ($dbData as $sectionName => $sectionData) {
|
||||||
|
$dataNode = $this->domDocument->createElement("definition");
|
||||||
|
$dataNode->setAttribute("class", $sectionName);
|
||||||
|
|
||||||
|
foreach ($sectionData as $elementName => $elementData) {
|
||||||
|
$elementNode = $this->domDocument->createElement("table");
|
||||||
|
$elementNode->setAttribute("name", $elementName);
|
||||||
|
|
||||||
|
foreach ($elementData as $recordData) {
|
||||||
|
$recordNode = $this->domDocument->createElement("record");
|
||||||
|
$recordData = array_change_key_case($recordData, CASE_LOWER);
|
||||||
|
|
||||||
|
foreach ($recordData as $key => $value) {
|
||||||
|
if(is_object($value)){
|
||||||
|
$value = serialize($value);
|
||||||
|
}
|
||||||
|
$columnNode = $this->domDocument->createElement($key);
|
||||||
|
$columnNode->appendChild($this->getTextNode($value));
|
||||||
|
$recordNode->appendChild($columnNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
$elementNode->appendChild($recordNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
$dataNode->appendChild($elementNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
$rootNode->appendChild($dataNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
$workflowFilesNode = $this->domDocument->createElement("workflow-files");
|
||||||
|
|
||||||
|
foreach ($data["workflow-files"] as $elementName => $elementData) {
|
||||||
|
foreach ($elementData as $fileData) {
|
||||||
|
$fileNode = $this->domDocument->createElement("file");
|
||||||
|
$fileNode->setAttribute("target", strtolower($elementName));
|
||||||
|
|
||||||
|
$filenameNode = $this->domDocument->createElement("file_name");
|
||||||
|
$filenameNode->appendChild($this->getTextNode($fileData["filename"]));
|
||||||
|
$fileNode->appendChild($filenameNode);
|
||||||
|
|
||||||
|
$filepathNode = $this->domDocument->createElement("file_path");
|
||||||
|
$filepathNode->appendChild($this->domDocument->createCDATASection($fileData["filepath"]));
|
||||||
|
$fileNode->appendChild($filepathNode);
|
||||||
|
|
||||||
|
$fileContentNode = $this->domDocument->createElement("file_content");
|
||||||
|
$fileContentNode->appendChild($this->domDocument->createCDATASection(base64_encode($fileData["file_content"])));
|
||||||
|
$fileNode->appendChild($fileContentNode);
|
||||||
|
|
||||||
|
$workflowFilesNode->appendChild($fileNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$rootNode->appendChild($workflowFilesNode);
|
||||||
|
return $this->domDocument->saveXML($rootNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
namespace ProcessMaker\BusinessModel\Migrator;
|
namespace ProcessMaker\BusinessModel\Migrator;
|
||||||
|
|
||||||
|
|
||||||
class ProcessDefinitionMigrator implements Importable
|
class ProcessDefinitionMigrator implements Importable, Exportable
|
||||||
{
|
{
|
||||||
public function beforeImport($data)
|
public function beforeImport($data)
|
||||||
{
|
{
|
||||||
@@ -26,4 +26,19 @@ class ProcessDefinitionMigrator implements Importable
|
|||||||
// TODO: Implement afterImport() method.
|
// TODO: Implement afterImport() method.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function beforeExport()
|
||||||
|
{
|
||||||
|
// TODO: Implement beforeExport() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
public function export($prj_uid)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function afterExport()
|
||||||
|
{
|
||||||
|
// TODO: Implement afterExport() method.
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user