Adding Exporter for BPMN Projects (1st commit)
This commit is contained in:
@@ -2609,7 +2609,7 @@ class G
|
|||||||
* @param integer $permission
|
* @param integer $permission
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function uploadFile ($file, $path, $nameToSave, $permission = 0660)
|
public static function uploadFile ($file, $path, $nameToSave, $permission = 0755)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if ($file == '') {
|
if ($file == '') {
|
||||||
@@ -3618,7 +3618,7 @@ class G
|
|||||||
* @param $pattern pattern to filter some especified files
|
* @param $pattern pattern to filter some especified files
|
||||||
* @return <array> array containing the recursive glob results
|
* @return <array> array containing the recursive glob results
|
||||||
*/
|
*/
|
||||||
public function rglob($pattern = '*', $flags = 0, $path = '')
|
public static function rglob($pattern = '*', $flags = 0, $path = '')
|
||||||
{
|
{
|
||||||
$paths = glob($path.'*', GLOB_MARK|GLOB_ONLYDIR|GLOB_NOSORT);
|
$paths = glob($path.'*', GLOB_MARK|GLOB_ONLYDIR|GLOB_NOSORT);
|
||||||
$files = glob($path.$pattern, $flags);
|
$files = glob($path.$pattern, $flags);
|
||||||
|
|||||||
@@ -2584,8 +2584,14 @@ class Processes
|
|||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function serializeProcess ($sProUid = '')
|
public function serializeProcess ($sProUid = '')
|
||||||
|
{
|
||||||
|
return serialize($this->getWorkflowData($sProUid));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getWorkflowData($sProUid = '')
|
||||||
{
|
{
|
||||||
$oProcess = new Process();
|
$oProcess = new Process();
|
||||||
|
$oData = new StdClass();
|
||||||
$oData->process = $this->getProcessRow( $sProUid, false );
|
$oData->process = $this->getProcessRow( $sProUid, false );
|
||||||
$oData->tasks = $this->getTaskRows( $sProUid );
|
$oData->tasks = $this->getTaskRows( $sProUid );
|
||||||
$oData->routes = $this->getRouteRows( $sProUid );
|
$oData->routes = $this->getRouteRows( $sProUid );
|
||||||
@@ -2619,7 +2625,7 @@ class Processes
|
|||||||
//$oJSON = new Services_JSON();
|
//$oJSON = new Services_JSON();
|
||||||
//krumo ( $oJSON->encode($oData) );
|
//krumo ( $oJSON->encode($oData) );
|
||||||
//return $oJSON->encode($oData);
|
//return $oJSON->encode($oData);
|
||||||
return serialize( $oData );
|
return $oData;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -41,4 +41,25 @@ class BpmnBound extends BaseBpmnBound
|
|||||||
|
|
||||||
return BpmnBoundPeer::doSelectOne($c);
|
return BpmnBoundPeer::doSelectOne($c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getAll($prjUid = null, $start = null, $limit = null, $filter = '', $changeCaseTo = CASE_UPPER)
|
||||||
|
{
|
||||||
|
$c = new Criteria('workflow');
|
||||||
|
$c->addSelectColumn("BPMN_BOUND.*");
|
||||||
|
|
||||||
|
if (! is_null($prjUid)) {
|
||||||
|
$c->add(BpmnBoundPeer::PRJ_UID, $prjUid, Criteria::EQUAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
$rs = BpmnBoundPeer::doSelectRS($c);
|
||||||
|
$rs->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||||
|
|
||||||
|
$activities = array();
|
||||||
|
|
||||||
|
while ($rs->next()) {
|
||||||
|
$activities[] = $changeCaseTo !== CASE_UPPER ? array_change_key_case($rs->getRow(), CASE_LOWER) : $rs->getRow();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $activities;
|
||||||
|
}
|
||||||
} // BpmnBound
|
} // BpmnBound
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ class DbSource extends BaseDbSource
|
|||||||
return $aRow[0];
|
return $aRow[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Exists($Uid, $ProUID)
|
public function Exists($Uid, $ProUID = "")
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$oPro = DbSourcePeer::retrieveByPk($Uid, $ProUID);
|
$oPro = DbSourcePeer::retrieveByPk($Uid, $ProUID);
|
||||||
|
|||||||
114
workflow/engine/src/ProcessMaker/Exporter/Exporter.php
Normal file
114
workflow/engine/src/ProcessMaker/Exporter/Exporter.php
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
<?php
|
||||||
|
namespace ProcessMaker\Exporter;
|
||||||
|
|
||||||
|
use ProcessMaker\Project;
|
||||||
|
|
||||||
|
abstract class Exporter
|
||||||
|
{
|
||||||
|
protected $prjUid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \ProcessMaker\Project\Adapter\BpmnWorkflow
|
||||||
|
*/
|
||||||
|
protected $bpmnProject;
|
||||||
|
|
||||||
|
public function __construct($prjUid)
|
||||||
|
{
|
||||||
|
$this->prjUid = $prjUid;
|
||||||
|
|
||||||
|
$this->bpmnProject = Project\Bpmn::load($prjUid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildData()
|
||||||
|
{
|
||||||
|
$data = array();
|
||||||
|
$project = $this->bpmnProject->getProject();
|
||||||
|
$data["METADATA"] = $this->getSystemInfo();
|
||||||
|
$data["METADATA"]["project_name"] = $project["PRJ_NAME"];
|
||||||
|
|
||||||
|
|
||||||
|
$bpmnStruct["ACTIVITY"] = \BpmnActivity::getAll($this->prjUid);
|
||||||
|
//$data["BPMN_STRUCTURE"]["BPMN_BOUND"] = $this->bwap->getBounds();
|
||||||
|
// $data["bpmn_data"] = $this->bwap->getProject();
|
||||||
|
// $data["bpmn_diagram"] = $this->bwap->getProject();
|
||||||
|
// $data["bpmn_documentation"] = $this->bwap->getProject();
|
||||||
|
$bpmnStruct["BPMN_EVENT"] = \BpmnEvent::getAll($this->prjUid);
|
||||||
|
// $data["bpmn_extension"] = $this->bwap->getProject();
|
||||||
|
// $data["bpmn_flow"] = $this->bwap->getProject();
|
||||||
|
$bpmnStruct["BPMN_GATEWAY"] = \BpmnGateway::getAll($this->prjUid);
|
||||||
|
// $data["bpmn_lane"] = $this->bwap->getProject();
|
||||||
|
// $data["bpmn_laneset"] = $this->bwap->getProject();
|
||||||
|
// $data["bpmn_participant"] = $this->bwap->getProject();
|
||||||
|
// $data["bpmn_process"] = $this->bwap->getProject();
|
||||||
|
// $data["bpmn_project"] = $this->bwap->getProject();
|
||||||
|
|
||||||
|
|
||||||
|
\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();
|
||||||
|
|
||||||
|
// getting dynaforms
|
||||||
|
$dynaforms = array();
|
||||||
|
|
||||||
|
foreach ($workflowData["dynaforms"] as $dynaform) {
|
||||||
|
$dynFile = PATH_DYNAFORM . $dynaform['DYN_FILENAME'] . '.xml';
|
||||||
|
$dynaforms[] = array(
|
||||||
|
"filename" => $dynaform['DYN_TITLE'],
|
||||||
|
"filepath" => $dynaform['DYN_FILENAME'] . '.xml',
|
||||||
|
"file_content" => file_get_contents($dynFile)
|
||||||
|
);
|
||||||
|
|
||||||
|
$htmlFile = PATH_DYNAFORM . $dynaform['DYN_FILENAME'] . '.html';
|
||||||
|
|
||||||
|
if (file_exists($htmlFile)) {
|
||||||
|
$dynaforms[] = array(
|
||||||
|
"filename" => $dynaform['DYN_FILENAME'] . '.html',
|
||||||
|
"filepath" => $dynaform['DYN_FILENAME'] . '.html',
|
||||||
|
"file_content" => file_get_contents($htmlFile)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// getting templates files
|
||||||
|
$templates = array();
|
||||||
|
$workspaceDir = PATH_DATA . 'sites' . PATH_SEP . SYS_SYS . PATH_SEP;
|
||||||
|
$templatesDir = $workspaceDir . 'mailTemplates' . PATH_SEP . $this->prjUid;
|
||||||
|
$templatesFiles = \G::rglob("*", 0, $templatesDir);
|
||||||
|
|
||||||
|
foreach ($templatesFiles as $templatesFile) {
|
||||||
|
if (is_dir($templatesFile)) continue;
|
||||||
|
|
||||||
|
$templates[] = array(
|
||||||
|
"filename" => basename($templatesFile),
|
||||||
|
"filepath" => str_replace($templatesDir, "", $templatesFile),
|
||||||
|
"file_content" => file_get_contents($templatesFile)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$data["WORKFLOW_FILES"]["DYNAFORMS"] = $dynaforms;
|
||||||
|
$data["WORKFLOW_FILES"]["TEMPLATES"] = $templates;
|
||||||
|
$data["WORKFLOW_FILES"]["PUBLIC"] = array();
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSystemInfo()
|
||||||
|
{
|
||||||
|
//$sysInfo = \System::getSysInfo();
|
||||||
|
//print_r($sysInfo); die;
|
||||||
|
|
||||||
|
return array(
|
||||||
|
"vendor" => "ProcessMaker",
|
||||||
|
"codename" => "Michelangelo",
|
||||||
|
"version" => \System::getVersion(),
|
||||||
|
"workspace" => defined("SYS_SYS") ? SYS_SYS : "Unknown",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
116
workflow/engine/src/ProcessMaker/Exporter/XmlExporter.php
Normal file
116
workflow/engine/src/ProcessMaker/Exporter/XmlExporter.php
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
<?php
|
||||||
|
namespace ProcessMaker\Exporter;
|
||||||
|
|
||||||
|
class XmlExporter extends Exporter
|
||||||
|
{
|
||||||
|
protected $dom;
|
||||||
|
protected $rootNode;
|
||||||
|
|
||||||
|
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->formatOutput = true;
|
||||||
|
|
||||||
|
$this->rootNode = $this->dom->createElement("PROJECT");
|
||||||
|
$this->rootNode->setAttribute("version", "1.0");
|
||||||
|
$this->dom->appendChild($this->rootNode);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function build()
|
||||||
|
{
|
||||||
|
$data = $this->buildData();
|
||||||
|
|
||||||
|
// metadata set up
|
||||||
|
$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);
|
||||||
|
$metadataNode->appendChild($metaNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->rootNode->appendChild($metadataNode);
|
||||||
|
// end setting metadata
|
||||||
|
|
||||||
|
// bpmn struct data set up
|
||||||
|
$dbData = array("BPMN_DATA" => $data["BPMN_DATA"], "WORKFLOW_DATA" => $data["WORKFLOW_DATA"]);
|
||||||
|
//file_put_contents("/home/erik/out.log", print_r($dbData, true)); die;
|
||||||
|
foreach ($dbData as $sectionName => $sectionData) {
|
||||||
|
$dataNode = $this->dom->createElement($sectionName);
|
||||||
|
|
||||||
|
foreach ($sectionData as $elementName => $elementData) {
|
||||||
|
$elementNode = $this->dom->createElement(strtoupper($elementName));
|
||||||
|
|
||||||
|
foreach ($elementData as $recordData) {
|
||||||
|
$recordNode = $this->dom->createElement("ROW");
|
||||||
|
|
||||||
|
foreach ($recordData as $key => $value) {
|
||||||
|
$columnNode = $this->dom->createElement(strtoupper($key));
|
||||||
|
|
||||||
|
if (preg_match('/^[\w\s]+$/', $value, $match) || empty($value)) {
|
||||||
|
$textNode = $this->dom->createTextNode($value);
|
||||||
|
} else {
|
||||||
|
$textNode = $this->dom->createCDATASection($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
$columnNode->appendChild($textNode);
|
||||||
|
$recordNode->appendChild($columnNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
$elementNode->appendChild($recordNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
$dataNode->appendChild($elementNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->rootNode->appendChild($dataNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
$workflowFilesNode = $this->dom->createElement("WORKFLOW_FILES");
|
||||||
|
|
||||||
|
// workflow dynaforms files
|
||||||
|
foreach ($data["WORKFLOW_FILES"] as $elementName => $elementData) {
|
||||||
|
//$wfFilesNode = $this->dom->createElement($elementName);
|
||||||
|
|
||||||
|
foreach ($elementData as $fileData) {
|
||||||
|
$fileNode = $this->dom->createElement("FILE");
|
||||||
|
$fileNode->setAttribute("target", strtolower($elementName));
|
||||||
|
|
||||||
|
$filenameNode = $this->dom->createElement("FILE_NAME");
|
||||||
|
$filenameNode->appendChild($this->dom->createCDATASection($fileData["filename"]));
|
||||||
|
$fileNode->appendChild($filenameNode);
|
||||||
|
|
||||||
|
$filepathNode = $this->dom->createElement("FILE_PATH");
|
||||||
|
$filepathNode->appendChild($this->dom->createCDATASection($fileData["filepath"]));
|
||||||
|
$fileNode->appendChild($filepathNode);
|
||||||
|
|
||||||
|
$fileContentNode = $this->dom->createElement("FILE_CONTENT");
|
||||||
|
$fileContentNode->appendChild($this->dom->createCDATASection(base64_encode($fileData["file_content"])));
|
||||||
|
$fileNode->appendChild($fileContentNode);
|
||||||
|
|
||||||
|
$workflowFilesNode->appendChild($fileNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
//$workflowFilesNode->appendChild($wfFilesNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->rootNode->appendChild($workflowFilesNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save($outputFile)
|
||||||
|
{
|
||||||
|
file_put_contents($outputFile, $this->export());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function export()
|
||||||
|
{
|
||||||
|
return $this->dom->saveXml();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -237,6 +237,10 @@ class Workflow extends Handler
|
|||||||
return $tasks->getAllTasks($this->proUid);
|
return $tasks->getAllTasks($this->proUid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $tasUid
|
||||||
|
* @param bool $value
|
||||||
|
*/
|
||||||
public function setStartTask($tasUid, $value = true)
|
public function setStartTask($tasUid, $value = true)
|
||||||
{
|
{
|
||||||
$value = $value ? "TRUE" : "FALSE";
|
$value = $value ? "TRUE" : "FALSE";
|
||||||
@@ -248,6 +252,10 @@ class Workflow extends Handler
|
|||||||
self::log("Setting Start Task -> $value, Success!");
|
self::log("Setting Start Task -> $value, Success!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $tasUid
|
||||||
|
* @param bool $value
|
||||||
|
*/
|
||||||
public function setEndTask($tasUid, $value = true)
|
public function setEndTask($tasUid, $value = true)
|
||||||
{
|
{
|
||||||
self::log("Setting End Task with Uid: $tasUid: " . ($value ? "TRUE" : "FALSE"));
|
self::log("Setting End Task with Uid: $tasUid: " . ($value ? "TRUE" : "FALSE"));
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
namespace Tests\ProcessMaker\Exporter;
|
||||||
|
|
||||||
|
use \ProcessMaker\Project;
|
||||||
|
use \ProcessMaker\Exporter;
|
||||||
|
|
||||||
|
if (! class_exists("Propel")) {
|
||||||
|
include_once __DIR__ . "/../../bootstrap.php";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class XmlExporterTest
|
||||||
|
*
|
||||||
|
* @package Tests\ProcessMaker\Project
|
||||||
|
* @author Erik Amaru Ortiz <aortiz.erik@gmail.com, erik@colosa.com>
|
||||||
|
*/
|
||||||
|
class XmlExporterTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
function testExport()
|
||||||
|
{
|
||||||
|
$exporter = new Exporter\XmlExporter("4857540205310b25f3d51a5020772457");
|
||||||
|
$exporter->build();
|
||||||
|
$exporter->save("/home/erik/out.xml");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user