Adding the PMXPublisher class in order to create the export file.
This commit is contained in:
@@ -7,8 +7,6 @@
|
||||
|
||||
namespace ProcessMaker\BusinessModel\Migrator;
|
||||
|
||||
use Symfony\Component\Config\Definition\Exception\Exception;
|
||||
|
||||
class DynaformsMigrator implements Importable, Exportable
|
||||
{
|
||||
protected $processes;
|
||||
@@ -30,8 +28,8 @@ class DynaformsMigrator implements Importable, Exportable
|
||||
{
|
||||
try {
|
||||
$this->processes->createDynaformRows($data);
|
||||
} catch (Exception $e) {
|
||||
Logger::log($e);
|
||||
} catch (\Exception $e) {
|
||||
\Logger::log($e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,12 +4,15 @@
|
||||
*/
|
||||
|
||||
namespace ProcessMaker\BusinessModel\Migrator;
|
||||
use \ProcessMaker\Exporter\XmlExporter;
|
||||
|
||||
use ProcessMaker\Project;
|
||||
|
||||
class GranularExporter
|
||||
{
|
||||
|
||||
protected $factory;
|
||||
protected $publisher;
|
||||
protected $generator;
|
||||
protected $data;
|
||||
protected $prjuid;
|
||||
/**
|
||||
@@ -19,15 +22,17 @@ class GranularExporter
|
||||
{
|
||||
$this->prjuid = $prj_uid;
|
||||
$this->factory = new MigratorFactory();
|
||||
$this->publisher = new PMXGenerator();
|
||||
$this->generator = new PMXGenerator();
|
||||
$this->publisher = new PMXPublisher();
|
||||
}
|
||||
|
||||
public function export($objectList)
|
||||
{
|
||||
foreach ($objectList as $key => $data) {
|
||||
$migrator = $this->factory->create($key);
|
||||
$migratorData = $migrator->export($data);
|
||||
$this->prepareData($migratorData);
|
||||
$this->beforeExport();
|
||||
foreach ($objectList as $data) {
|
||||
$migrator = $this->factory->create($data);
|
||||
$migratorData = $migrator->export($this->prjuid);
|
||||
$this->addData($migratorData);
|
||||
}
|
||||
return $this->publish();
|
||||
|
||||
@@ -35,20 +40,30 @@ class GranularExporter
|
||||
|
||||
protected function beforeExport()
|
||||
{
|
||||
$exporter = new XmlExporter($this->prjuid);
|
||||
$getProjectName = $exporter->truncateName($exporter->getProjectName(), false);
|
||||
$bpmnProject = Project\Bpmn::load($this->prjuid);
|
||||
$projectData = $bpmnProject->getProject();
|
||||
$getProjectName = $this->publisher->truncateName($projectData['PRJ_NAME'], false);
|
||||
$outputDir = PATH_DATA . "sites" . PATH_SEP . SYS_SYS . PATH_SEP . "files" . PATH_SEP . "output" . PATH_SEP;
|
||||
$version = \ProcessMaker\Util\Common::getLastVersion($outputDir . $getProjectName . "-*.pmx") + 1;
|
||||
$outputFilename = $outputDir . sprintf("%s-%s.%s", str_replace(" ", "_", $getProjectName), $version, "pmx");
|
||||
$exporter->setMetadata("export_version", $version);
|
||||
|
||||
$data = array();
|
||||
$data["filename"] = $outputFilename;
|
||||
$data["version"] = "3.0";
|
||||
$data["container"] = "ProcessMaker-Project";
|
||||
$data["metadata"] = $this->getMetadata();
|
||||
$data["metadata"] = array(
|
||||
"vendor_version" => \System::getVersion(),
|
||||
"vendor_version_code" => "Michelangelo",
|
||||
"export_timestamp" => date("U"),
|
||||
"export_datetime" => date("Y-m-d\TH:i:sP"),
|
||||
"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,
|
||||
);
|
||||
$data["metadata"]["workspace"] = defined("SYS_SYS") ? SYS_SYS : "Unknown";
|
||||
$data["metadata"]["name"] = $this->getProjectName();
|
||||
$data["metadata"]["uid"] = $this->getProjectUid();
|
||||
$data["metadata"]["name"] = $projectData['PRJ_NAME'];
|
||||
$data["metadata"]["uid"] = $projectData['PRJ_UID'];
|
||||
$data["metadata"]["export_version"] = $version;
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
@@ -59,8 +74,11 @@ class GranularExporter
|
||||
|
||||
public function publish()
|
||||
{
|
||||
return $this->generator->generate(
|
||||
$this->data
|
||||
return $this->publisher->publish(
|
||||
$this->data['filename'],
|
||||
$this->generator->generate(
|
||||
$this->data
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: gustav
|
||||
* Date: 3/18/16
|
||||
* Time: 3:13 PM
|
||||
*/
|
||||
|
||||
namespace ProcessMaker\BusinessModel\Migrator;
|
||||
|
||||
use ProcessMaker\Util;
|
||||
|
||||
class PMXPublisher
|
||||
{
|
||||
public function publish($filename, $data)
|
||||
{
|
||||
$parentDir = dirname();
|
||||
|
||||
if (! is_dir($parentDir)) {
|
||||
Util\Common::mk_dir($parentDir, 0775);
|
||||
}
|
||||
|
||||
$outputFile = $this->truncateName($filename);
|
||||
|
||||
file_put_contents($outputFile, $data);
|
||||
chmod($outputFile, 0755);
|
||||
|
||||
return basename($outputFile);
|
||||
}
|
||||
|
||||
public function truncateName($outputFile,$dirName = true)
|
||||
{
|
||||
$limit = 200;
|
||||
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
||||
$limit = 150;
|
||||
}
|
||||
if($dirName) {
|
||||
if (strlen(basename($outputFile)) >= $limit) {
|
||||
$lastPos = strrpos(basename($outputFile),'.');
|
||||
$fileName = substr(basename($outputFile),0,$lastPos);
|
||||
$newFileName = str_replace(".","_",$fileName);
|
||||
$newFileName = str_replace(" ","_",$fileName);
|
||||
$excess = strlen($newFileName) - $limit;
|
||||
$newFileName = substr($newFileName,0,strlen($newFileName)-$excess);
|
||||
$newOutputFile = str_replace($fileName,$newFileName,$outputFile);
|
||||
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
||||
$newOutputFile = str_replace("/", DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR, $newOutputFile);
|
||||
}
|
||||
$outputFile = $newOutputFile;
|
||||
}
|
||||
} else {
|
||||
$outputFile = str_replace(".","_",$outputFile);
|
||||
$outputFile = str_replace(" ","_",$outputFile);
|
||||
if (strlen($outputFile) >= $limit) {
|
||||
$excess = strlen($outputFile) - $limit;
|
||||
$newFileName = substr($outputFile,0,strlen($outputFile)-$excess);
|
||||
$outputFile = $newFileName;
|
||||
}
|
||||
}
|
||||
return $outputFile;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user