import bpmn projects (1st commit - still not functional)
This commit is contained in:
@@ -24,16 +24,66 @@ abstract class Importer
|
||||
const IMPORT_STAT_INVALID_SOURCE_FILE = 102;
|
||||
|
||||
|
||||
public abstract function import();
|
||||
public abstract function validateSource();
|
||||
public abstract function targetExists();
|
||||
public function import($option = self::IMPORT_OPTION_CREATE_NEW)
|
||||
{
|
||||
switch ($option) {
|
||||
case self::IMPORT_OPTION_CREATE_NEW:
|
||||
$this->prepare();
|
||||
$this->createNewProject();
|
||||
break;
|
||||
case self::IMPORT_OPTION_DISABLE_AND_CREATE_NEW:
|
||||
break;
|
||||
case self::IMPORT_OPTION_OVERWRITE:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the source file
|
||||
* @return mixed
|
||||
*/
|
||||
public function validateSource()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if the project already exists
|
||||
* @return mixed
|
||||
*/
|
||||
public function targetExists()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function createNewProject()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function updateProject()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function disableCurrentProject()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the temporal file save directory
|
||||
* @param $dirName
|
||||
*/
|
||||
public function setSaveDir($dirName)
|
||||
{
|
||||
$this->saveDir = rtrim($dirName, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the temporal file save directory
|
||||
* @return string
|
||||
*/
|
||||
public function getSaveDir()
|
||||
{
|
||||
if (empty($this->saveDir)) {
|
||||
@@ -43,11 +93,20 @@ abstract class Importer
|
||||
return $this->saveDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the temporal source file
|
||||
* @param $filename
|
||||
*/
|
||||
public function setSourceFile($filename)
|
||||
{
|
||||
$this->filename = $filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set source from Global Http Request resource
|
||||
* @param $varName
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function setSourceFromGlobals($varName)
|
||||
{
|
||||
/*[PROCESS_FILENAME] => Array
|
||||
@@ -77,6 +136,11 @@ abstract class Importer
|
||||
umask($oldUmask);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare for import, it makes all validations needed
|
||||
* @return int
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function prepare()
|
||||
{
|
||||
if ($this->validateSource() === false) {
|
||||
|
||||
@@ -1,17 +1,133 @@
|
||||
<?php
|
||||
namespace ProcessMaker\Importer;
|
||||
|
||||
class XmlImporter
|
||||
class XmlImporter extends Importer
|
||||
{
|
||||
public $filename = "";
|
||||
/**
|
||||
* @var \DOMDocument
|
||||
*/
|
||||
protected $dom;
|
||||
protected $root;
|
||||
protected $version = "";
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->dom = new \DOMDocument();
|
||||
}
|
||||
|
||||
public function setSourceFile($filename)
|
||||
{
|
||||
$this->filename = $filename;
|
||||
}
|
||||
|
||||
public function load()
|
||||
{
|
||||
$this->dom->load($this->filename);
|
||||
$this->root = $this->dom->documentElement;
|
||||
|
||||
// validate version
|
||||
$this->version = $this->root->getAttribute("version");
|
||||
|
||||
if (empty($this->version)) {
|
||||
throw new \Exception("ProcessMaker Project version is missing on file source.");
|
||||
}
|
||||
|
||||
// read metadata section
|
||||
$metadata = $this->root->getElementsByTagName("metadata");
|
||||
|
||||
if ($metadata->length != 1) {
|
||||
throw new \Exception("Invalid Document format, metadata section is missing or has multiple definition.");
|
||||
}
|
||||
|
||||
$metadata = $metadata->item(0);
|
||||
|
||||
// load project definition
|
||||
/** @var \DOMElement[]|\DomNodeList $definitions */
|
||||
$definitions = $this->root->getElementsByTagName("definition");
|
||||
|
||||
if ($definitions->length == 0) {
|
||||
throw new \Exception("Definition section is missing.");
|
||||
} elseif ($definitions->length < 2) {
|
||||
throw new \Exception("Definition section is incomplete.");
|
||||
}
|
||||
|
||||
$tables = array();
|
||||
|
||||
foreach ($definitions as $definition) {
|
||||
$defClass = strtoupper($definition->getAttribute("class"));
|
||||
$tables[$defClass] = array();
|
||||
|
||||
// getting tables def
|
||||
// first we need to know if the project already exists
|
||||
/** @var \DOMElement[] $tablesNodeList */
|
||||
$tablesNodeList = $definition->getElementsByTagName("table");
|
||||
|
||||
foreach ($tablesNodeList as $tableNode) {
|
||||
$tableName = strtoupper($tableNode->getAttribute("name"));
|
||||
$tables[$defClass][$tableName] = array();
|
||||
/** @var \DOMElement[] $recordsNodeList */
|
||||
$recordsNodeList = $tableNode->getElementsByTagName("record");
|
||||
|
||||
foreach ($recordsNodeList as $recordsNode) {
|
||||
if (! $recordsNode->hasChildNodes()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$columns = array();
|
||||
|
||||
foreach ($recordsNode->childNodes as $columnNode) {
|
||||
if ($columnNode->nodeName == "#text") continue;
|
||||
$columns[strtoupper($columnNode->nodeName)] = self::getNodeText($columnNode);;
|
||||
}
|
||||
|
||||
$tables[$defClass][$tableName][] = $columns;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$wfFilesNodeList = $this->root->getElementsByTagName("workflow-files");
|
||||
$wfFiles = array();
|
||||
|
||||
if ($wfFilesNodeList->length > 0) {
|
||||
$filesNodeList = $wfFilesNodeList->item(0)->getElementsByTagName("file");
|
||||
|
||||
foreach ($filesNodeList as $fileNode) {
|
||||
$target = $fileNode->getAttribute("target");
|
||||
|
||||
if (! isset($wfFiles[$target])) {
|
||||
$wfFiles[$target] = array();
|
||||
}
|
||||
|
||||
$fileContent = self::getNodeText($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_content" => $fileContent
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
print_r($tables);
|
||||
print_r($wfFiles);
|
||||
|
||||
|
||||
// load workflow definition
|
||||
// load workflow files
|
||||
}
|
||||
|
||||
public function import()
|
||||
{
|
||||
$this->load();
|
||||
}
|
||||
|
||||
private static function getNodeText($node)
|
||||
{
|
||||
if ($node->nodeType == XML_ELEMENT_NODE) {
|
||||
return $node->textContent;
|
||||
} else if ($node->nodeType == XML_TEXT_NODE || $node->nodeType == XML_CDATA_SECTION_NODE) {
|
||||
return (string) simplexml_import_dom($node->parentNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user