Merged in victorsl/processmaker (pull request #493)
ProcessMaker-BE "BPMN Import, add new option for group"
This commit is contained in:
@@ -24,57 +24,18 @@
|
|||||||
|
|
||||||
use ProcessMaker\Importer\XmlImporter;
|
use ProcessMaker\Importer\XmlImporter;
|
||||||
|
|
||||||
ini_set( 'max_execution_time', '0' );
|
ini_set("max_execution_time", 0);
|
||||||
|
|
||||||
if (isset($_FILES["PROCESS_FILENAME"])) {
|
|
||||||
$ext = pathinfo($_FILES["PROCESS_FILENAME"]["name"], PATHINFO_EXTENSION);
|
|
||||||
|
|
||||||
if ($ext == "pmx") {
|
|
||||||
$importer = new XmlImporter();
|
|
||||||
$importer->setData("usr_uid", $_SESSION['USER_LOGGED']);
|
|
||||||
$importer->setSaveDir(PATH_DOCUMENT . 'input');
|
|
||||||
$importer->setSourceFromGlobals("PROCESS_FILENAME");
|
|
||||||
|
|
||||||
try {
|
|
||||||
$prjUid = $importer->import();
|
|
||||||
|
|
||||||
$result = array(
|
|
||||||
"success" => true,
|
|
||||||
"catchMessage" => "",
|
|
||||||
"ExistProcessInDatabase" => 0,
|
|
||||||
"ExistGroupsInDatabase" => 0,
|
|
||||||
"sNewProUid" => $prjUid,
|
|
||||||
"project_type" => "bpmn"
|
|
||||||
);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
$result = array(
|
|
||||||
"success" => true,
|
|
||||||
"catchMessage" => "", //$e->getMessage(),
|
|
||||||
"ExistProcessInDatabase" => 1,
|
|
||||||
"ExistGroupsInDatabase" => 0,
|
|
||||||
"groupBeforeAccion" => "uploadFileNewProcess",
|
|
||||||
"sNewProUid" => "",
|
|
||||||
"proFileName" => $_FILES['PROCESS_FILENAME']['name'],
|
|
||||||
"project_type" => "bpmn"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
echo json_encode($result);
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
} elseif (isset($_POST["PRO_FILENAME"]) && file_exists(PATH_DOCUMENT . "input" . PATH_SEP . $_POST["PRO_FILENAME"]) && pathinfo(PATH_DOCUMENT . "input" . PATH_SEP . $_POST["PRO_FILENAME"], PATHINFO_EXTENSION) == "pmx") {
|
|
||||||
switch ($_POST["IMPORT_OPTION"]) {
|
|
||||||
case 1: $option = XmlImporter::IMPORT_OPTION_OVERWRITE; break;
|
|
||||||
case 2: $option = XmlImporter::IMPORT_OPTION_DISABLE_AND_CREATE_NEW; break;
|
|
||||||
case 3: $option = XmlImporter::IMPORT_OPTION_KEEP_WITHOUT_CHANGING_AND_CREATE_NEW; break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (isset($_FILES["PROCESS_FILENAME"]) &&
|
||||||
|
pathinfo($_FILES["PROCESS_FILENAME"]["name"], PATHINFO_EXTENSION) == "pmx"
|
||||||
|
) {
|
||||||
$importer = new XmlImporter();
|
$importer = new XmlImporter();
|
||||||
$importer->setData("usr_uid", $_SESSION['USER_LOGGED']);
|
$importer->setData("usr_uid", $_SESSION["USER_LOGGED"]);
|
||||||
$importer->setSourceFile(PATH_DOCUMENT . 'input' . PATH_SEP . $_POST["PRO_FILENAME"]);
|
$importer->setSaveDir(PATH_DOCUMENT . "input");
|
||||||
|
$importer->setSourceFromGlobals("PROCESS_FILENAME");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$prjUid = $importer->import($option);
|
$prjUid = $importer->import();
|
||||||
|
|
||||||
$result = array(
|
$result = array(
|
||||||
"success" => true,
|
"success" => true,
|
||||||
@@ -84,16 +45,18 @@ if (isset($_FILES["PROCESS_FILENAME"])) {
|
|||||||
"sNewProUid" => $prjUid,
|
"sNewProUid" => $prjUid,
|
||||||
"project_type" => "bpmn"
|
"project_type" => "bpmn"
|
||||||
);
|
);
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
$result = array(
|
$result = array(
|
||||||
"success" => true,
|
"success" => true,
|
||||||
"catchMessage" => $e->getMessage(),
|
"catchMessage" => (in_array($e->getCode(), array(XmlImporter::IMPORT_STAT_TARGET_ALREADY_EXISTS, XmlImporter::IMPORT_STAT_GROUP_ALREADY_EXISTS)))? "" : $e->getMessage(),
|
||||||
"ExistProcessInDatabase" => 1,
|
"ExistProcessInDatabase" => ($e->getCode() == XmlImporter::IMPORT_STAT_TARGET_ALREADY_EXISTS)? 1 : 0,
|
||||||
"ExistGroupsInDatabase" => 0,
|
"ExistGroupsInDatabase" => ($e->getCode() == XmlImporter::IMPORT_STAT_GROUP_ALREADY_EXISTS)? 1 : 0,
|
||||||
"groupBeforeAccion" => "uploadFileNewProcess",
|
|
||||||
"sNewProUid" => "",
|
"sNewProUid" => "",
|
||||||
"proFileName" => "",
|
"project_type" => "bpmn",
|
||||||
"project_type" => "bpmn"
|
|
||||||
|
"proFileName" => $_FILES["PROCESS_FILENAME"]["name"],
|
||||||
|
"groupBeforeAccion" => "uploadFileNewProcess",
|
||||||
|
"importOption" => 0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,38 +64,73 @@ if (isset($_FILES["PROCESS_FILENAME"])) {
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function reservedWordsSqlValidate ($data)
|
if (isset($_POST["PRO_FILENAME"]) &&
|
||||||
{
|
file_exists(PATH_DOCUMENT . "input" . PATH_SEP . $_POST["PRO_FILENAME"]) &&
|
||||||
$arrayAux = array ();
|
pathinfo(PATH_DOCUMENT . "input" . PATH_SEP . $_POST["PRO_FILENAME"], PATHINFO_EXTENSION) == "pmx"
|
||||||
$reservedWordsSql = G::reservedWordsSql();
|
) {
|
||||||
|
$option = XmlImporter::IMPORT_OPTION_CREATE_NEW;
|
||||||
|
|
||||||
foreach ($data->reportTables as $rptIndex => $rptValue) {
|
switch ((isset($_POST["IMPORT_OPTION"]))? (int)($_POST["IMPORT_OPTION"]) : 0) {
|
||||||
if (in_array( strtoupper( $rptValue["REP_TAB_NAME"] ), $reservedWordsSql )) {
|
case 1:
|
||||||
$arrayAux[] = $rptValue["REP_TAB_NAME"];
|
$option = XmlImporter::IMPORT_OPTION_OVERWRITE;
|
||||||
}
|
break;
|
||||||
|
case 2:
|
||||||
|
$option = XmlImporter::IMPORT_OPTION_DISABLE_AND_CREATE_NEW;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
$option = XmlImporter::IMPORT_OPTION_KEEP_WITHOUT_CHANGING_AND_CREATE_NEW;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count( $arrayAux ) > 0) {
|
$optionGroup = XmlImporter::GROUP_IMPORT_OPTION_CREATE_NEW;
|
||||||
throw (new Exception( G::LoadTranslation( "ID_PMTABLE_INVALID_NAME", array (implode( ", ", $arrayAux )
|
|
||||||
) ) ));
|
switch ((isset($_POST["optionGroupExistInDatabase"]))? (int)($_POST["optionGroupExistInDatabase"]) : 0) {
|
||||||
|
case 1:
|
||||||
|
$optionGroup = XmlImporter::GROUP_IMPORT_OPTION_RENAME;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
$optionGroup = XmlImporter::GROUP_IMPORT_OPTION_MERGE_PREEXISTENT;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$arrayAux = array ();
|
$importer = new XmlImporter();
|
||||||
|
$importer->setData("usr_uid", $_SESSION["USER_LOGGED"]);
|
||||||
|
$importer->setSourceFile(PATH_DOCUMENT . "input" . PATH_SEP . $_POST["PRO_FILENAME"]);
|
||||||
|
|
||||||
foreach ($data->reportTablesVars as $rptIndex => $rptValue) {
|
try {
|
||||||
if (in_array( strtoupper( $rptValue["REP_VAR_NAME"] ), $reservedWordsSql )) {
|
$prjUid = $importer->import($option, $optionGroup);
|
||||||
$arrayAux[] = $rptValue["REP_VAR_NAME"];
|
|
||||||
}
|
$result = array(
|
||||||
|
"success" => true,
|
||||||
|
"catchMessage" => "",
|
||||||
|
"ExistProcessInDatabase" => 0,
|
||||||
|
"ExistGroupsInDatabase" => 0,
|
||||||
|
"sNewProUid" => $prjUid,
|
||||||
|
"project_type" => "bpmn"
|
||||||
|
);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$result = array(
|
||||||
|
"success" => true,
|
||||||
|
"catchMessage" => (in_array($e->getCode(), array(XmlImporter::IMPORT_STAT_TARGET_ALREADY_EXISTS, XmlImporter::IMPORT_STAT_GROUP_ALREADY_EXISTS)))? "" : $e->getMessage(),
|
||||||
|
"ExistProcessInDatabase" => ($e->getCode() == XmlImporter::IMPORT_STAT_TARGET_ALREADY_EXISTS)? 1 : 0,
|
||||||
|
"ExistGroupsInDatabase" => ($e->getCode() == XmlImporter::IMPORT_STAT_GROUP_ALREADY_EXISTS)? 1 : 0,
|
||||||
|
"sNewProUid" => "",
|
||||||
|
"project_type" => "bpmn",
|
||||||
|
|
||||||
|
"proFileName" => $_POST["PRO_FILENAME"],
|
||||||
|
"groupBeforeAccion" => "uploadFileNewProcess",
|
||||||
|
"importOption" => (isset($_POST["IMPORT_OPTION"]))? (int)($_POST["IMPORT_OPTION"]) : 0
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count( $arrayAux ) > 0) {
|
echo G::json_encode($result);
|
||||||
throw (new Exception( G::LoadTranslation( "ID_PMTABLE_INVALID_FIELD_NAME", array (implode( ", ", $arrayAux )
|
exit(0);
|
||||||
) ) ));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$action = isset( $_REQUEST['ajaxAction'] ) ? $_REQUEST['ajaxAction'] : null;
|
$action = isset( $_REQUEST['ajaxAction'] ) ? $_REQUEST['ajaxAction'] : null;
|
||||||
|
|
||||||
|
$importer = new XmlImporter();
|
||||||
|
|
||||||
$result = new stdClass();
|
$result = new stdClass();
|
||||||
$result->success = true;
|
$result->success = true;
|
||||||
$result->catchMessage = "";
|
$result->catchMessage = "";
|
||||||
@@ -201,7 +199,7 @@ if ($action == "uploadFileNewProcess") {
|
|||||||
$oData = $oProcess->getProcessData( $path . $filename );
|
$oData = $oProcess->getProcessData( $path . $filename );
|
||||||
}
|
}
|
||||||
|
|
||||||
reservedWordsSqlValidate( $oData );
|
$importer->throwExceptionIfExistsReservedWordsSql($oData);
|
||||||
|
|
||||||
//!Upload file
|
//!Upload file
|
||||||
$Fields['PRO_FILENAME'] = $filename;
|
$Fields['PRO_FILENAME'] = $filename;
|
||||||
@@ -286,7 +284,7 @@ if ($action == "uploadFileNewProcessExist") {
|
|||||||
$oData = $oProcess->getProcessData( $path . $filename );
|
$oData = $oProcess->getProcessData( $path . $filename );
|
||||||
}
|
}
|
||||||
|
|
||||||
reservedWordsSqlValidate( $oData );
|
$importer->throwExceptionIfExistsReservedWordsSql($oData);
|
||||||
|
|
||||||
$Fields['PRO_FILENAME'] = $filename;
|
$Fields['PRO_FILENAME'] = $filename;
|
||||||
$sProUid = $oData->process['PRO_UID'];
|
$sProUid = $oData->process['PRO_UID'];
|
||||||
@@ -352,7 +350,7 @@ if ($action == "uploadFileNewProcessExist") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//!data ouput
|
//!data ouput
|
||||||
$result->fileName = $filename;
|
$result->proFileName = $filename;
|
||||||
$result->importOption = $option;
|
$result->importOption = $option;
|
||||||
$result->sNewProUid = $sNewProUid;
|
$result->sNewProUid = $sNewProUid;
|
||||||
$result->success = true;
|
$result->success = true;
|
||||||
|
|||||||
@@ -18,22 +18,58 @@ abstract class Importer
|
|||||||
const IMPORT_OPTION_KEEP_WITHOUT_CHANGING_AND_CREATE_NEW = "project.import.keep_without_changing_and_create_new";
|
const IMPORT_OPTION_KEEP_WITHOUT_CHANGING_AND_CREATE_NEW = "project.import.keep_without_changing_and_create_new";
|
||||||
const IMPORT_OPTION_CREATE_NEW = "project.import.create_new";
|
const IMPORT_OPTION_CREATE_NEW = "project.import.create_new";
|
||||||
|
|
||||||
/**
|
const GROUP_IMPORT_OPTION_RENAME = "group.import.rename";
|
||||||
* Success, Project imported successfully.
|
const GROUP_IMPORT_OPTION_MERGE_PREEXISTENT = "group.import.merge.preexistent";
|
||||||
*/
|
const GROUP_IMPORT_OPTION_CREATE_NEW = "group.import.create_new";
|
||||||
const IMPORT_STAT_SUCCESS = 100;
|
|
||||||
/**
|
const IMPORT_STAT_SUCCESS = 100; //Success, Project imported successfully.
|
||||||
* Error, Target Project already exists.
|
const IMPORT_STAT_TARGET_ALREADY_EXISTS = 101; //Error, Target Project already exists.
|
||||||
*/
|
const IMPORT_STAT_INVALID_SOURCE_FILE = 102; //Error, Invalid file type or the file have corrupt data.
|
||||||
const IMPORT_STAT_TARGET_ALREADY_EXISTS = 101;
|
const IMPORT_STAT_GROUP_ALREADY_EXISTS = 105; //Error, Group already exists.
|
||||||
/**
|
|
||||||
* Error, Invalid file type or the file have corrupt data.
|
|
||||||
*/
|
|
||||||
const IMPORT_STAT_INVALID_SOURCE_FILE = 102;
|
|
||||||
|
|
||||||
public abstract function load();
|
public abstract function load();
|
||||||
|
|
||||||
public function import($option = self::IMPORT_OPTION_CREATE_NEW)
|
/**
|
||||||
|
* Verify if exists reserved words SQL
|
||||||
|
*
|
||||||
|
* @param object $data Data
|
||||||
|
*
|
||||||
|
* return void Throw exception if exists reserved words SQL
|
||||||
|
*/
|
||||||
|
public function throwExceptionIfExistsReservedWordsSql($data)
|
||||||
|
{
|
||||||
|
$arrayReservedWordsSql = \G::reservedWordsSql();
|
||||||
|
|
||||||
|
$arrayAux = array();
|
||||||
|
|
||||||
|
foreach ($data->reportTables as $key => $value) {
|
||||||
|
$record = $value;
|
||||||
|
|
||||||
|
if (in_array(strtoupper($record["REP_TAB_NAME"]), $arrayReservedWordsSql)) {
|
||||||
|
$arrayAux[] = $record["REP_TAB_NAME"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($arrayAux) > 0) {
|
||||||
|
throw new \Exception(\G::LoadTranslation("ID_PMTABLE_INVALID_NAME", array(implode(", ", $arrayAux))));
|
||||||
|
}
|
||||||
|
|
||||||
|
$arrayAux = array();
|
||||||
|
|
||||||
|
foreach ($data->reportTablesVars as $key => $value) {
|
||||||
|
$record = $value;
|
||||||
|
|
||||||
|
if (in_array(strtoupper($record["REP_VAR_NAME"]), $arrayReservedWordsSql)) {
|
||||||
|
$arrayAux[] = $record["REP_VAR_NAME"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($arrayAux) > 0) {
|
||||||
|
throw new \Exception(\G::LoadTranslation("ID_PMTABLE_INVALID_FIELD_NAME", array(implode(", ", $arrayAux))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function import($option = self::IMPORT_OPTION_CREATE_NEW, $optionGroup = self::GROUP_IMPORT_OPTION_CREATE_NEW)
|
||||||
{
|
{
|
||||||
$this->prepare();
|
$this->prepare();
|
||||||
|
|
||||||
@@ -68,6 +104,35 @@ abstract class Importer
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$processes = new \Processes();
|
||||||
|
|
||||||
|
switch ($optionGroup) {
|
||||||
|
case self::GROUP_IMPORT_OPTION_CREATE_NEW:
|
||||||
|
$arrayAux = $processes->checkExistingGroups($this->importData["tables"]["workflow"]["groupwfs"]);
|
||||||
|
|
||||||
|
if (is_array($arrayAux) && count($arrayAux) > 0) {
|
||||||
|
throw new \Exception(
|
||||||
|
str_replace(
|
||||||
|
array("{0}"),
|
||||||
|
array(implode("|", array(self::GROUP_IMPORT_OPTION_CREATE_NEW, self::GROUP_IMPORT_OPTION_RENAME, self::GROUP_IMPORT_OPTION_MERGE_PREEXISTENT))),
|
||||||
|
"Group already exists, you need set an action to continue. Available actions: [{0}]."
|
||||||
|
),
|
||||||
|
self::IMPORT_STAT_GROUP_ALREADY_EXISTS
|
||||||
|
);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case self::GROUP_IMPORT_OPTION_RENAME:
|
||||||
|
$arrayAux = $processes->renameExistingGroups($this->importData["tables"]["workflow"]["groupwfs"]);
|
||||||
|
|
||||||
|
if (is_array($arrayAux) && count($arrayAux) > 0) {
|
||||||
|
$this->importData["tables"]["workflow"]["groupwfs"] = $arrayAux;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case self::GROUP_IMPORT_OPTION_MERGE_PREEXISTENT:
|
||||||
|
$this->importData["tables"]["workflow"] = (array)($processes->groupwfsUpdateUidByDatabase((object)($this->importData["tables"]["workflow"])));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
$this->importData["tables"]["bpmn"]["project"][0]["prj_name"] = $name;
|
$this->importData["tables"]["bpmn"]["project"][0]["prj_name"] = $name;
|
||||||
$this->importData["tables"]["bpmn"]["diagram"][0]["dia_name"] = $name;
|
$this->importData["tables"]["bpmn"]["diagram"][0]["dia_name"] = $name;
|
||||||
$this->importData["tables"]["bpmn"]["process"][0]["pro_name"] = $name;
|
$this->importData["tables"]["bpmn"]["process"][0]["pro_name"] = $name;
|
||||||
@@ -128,6 +193,8 @@ abstract class Importer
|
|||||||
throw new \Exception("BPMN table: \"Project\", definition is missing or has multiple definition.");
|
throw new \Exception("BPMN table: \"Project\", definition is missing or has multiple definition.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->throwExceptionIfExistsReservedWordsSql((object)($this->importData["tables"]["workflow"]));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -386,17 +453,19 @@ abstract class Importer
|
|||||||
* Imports a Project sent through the POST method ($_FILES)
|
* Imports a Project sent through the POST method ($_FILES)
|
||||||
*
|
*
|
||||||
* @param array $arrayData Data
|
* @param array $arrayData Data
|
||||||
* @param string $option Option ("CREATE", "OVERWRITE", "DISABLE", "KEEP")
|
* @param string $option Option for Project ("CREATE", "OVERWRITE", "DISABLE", "KEEP")
|
||||||
|
* @param string $optionGroup Option for Group ("CREATE", "RENAME", "MERGE")
|
||||||
* @param array $arrayFieldName The field's names
|
* @param array $arrayFieldName The field's names
|
||||||
*
|
*
|
||||||
* return array Returns the data sent and the unique id of Project
|
* return array Returns the data sent and the unique id of Project
|
||||||
*/
|
*/
|
||||||
public function importPostFile(array $arrayData, $option = "CREATE", array $arrayFieldName = array())
|
public function importPostFile(array $arrayData, $option = "CREATE", $optionGroup = "CREATE", array $arrayFieldName = array())
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
//Set data
|
//Set data
|
||||||
$arrayFieldName["projectFile"] = (isset($arrayFieldName["projectFile"]))? $arrayFieldName["projectFile"] : "PROJECT_FILE";
|
$arrayFieldName["projectFile"] = (isset($arrayFieldName["projectFile"]))? $arrayFieldName["projectFile"] : "PROJECT_FILE";
|
||||||
$arrayFieldName["option"] = (isset($arrayFieldName["option"]))? $arrayFieldName["option"] : "OPTION";
|
$arrayFieldName["option"] = (isset($arrayFieldName["option"]))? $arrayFieldName["option"] : "OPTION";
|
||||||
|
$arrayFieldName["optionGroup"] = (isset($arrayFieldName["optionGroup"]))? $arrayFieldName["optionGroup"] : "OPTION_GROUP";
|
||||||
|
|
||||||
$arrayFieldDefinition = array(
|
$arrayFieldDefinition = array(
|
||||||
$arrayFieldName["projectFile"] => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "projectFile")
|
$arrayFieldName["projectFile"] => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "projectFile")
|
||||||
@@ -418,6 +487,9 @@ abstract class Importer
|
|||||||
$optionCaseUpper = (strtoupper($option) == $option)? true : false;
|
$optionCaseUpper = (strtoupper($option) == $option)? true : false;
|
||||||
$option = strtoupper($option);
|
$option = strtoupper($option);
|
||||||
|
|
||||||
|
$optionGroupCaseUpper = (strtoupper($optionGroup) == $optionGroup)? true : false;
|
||||||
|
$optionGroup = strtoupper($optionGroup);
|
||||||
|
|
||||||
//Verify data
|
//Verify data
|
||||||
$process = new \ProcessMaker\BusinessModel\Process();
|
$process = new \ProcessMaker\BusinessModel\Process();
|
||||||
$validator = new \ProcessMaker\BusinessModel\Validator();
|
$validator = new \ProcessMaker\BusinessModel\Validator();
|
||||||
@@ -427,12 +499,29 @@ abstract class Importer
|
|||||||
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $arrayFieldDefinition, $arrayFieldNameForException, true);
|
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $arrayFieldDefinition, $arrayFieldNameForException, true);
|
||||||
|
|
||||||
$arrayOptionDefaultValues = array("CREATE", "OVERWRITE", "DISABLE", "KEEP");
|
$arrayOptionDefaultValues = array("CREATE", "OVERWRITE", "DISABLE", "KEEP");
|
||||||
|
$arrayOptionGroupDefaultValues = array("CREATE", "RENAME", "MERGE");
|
||||||
|
|
||||||
if ($option . "" != "") {
|
$arrayAux = array(
|
||||||
if (!in_array($option, $arrayOptionDefaultValues, true)) {
|
array($option, $arrayOptionDefaultValues, $arrayFieldNameForException["option"], $optionCaseUpper),
|
||||||
$strdv = implode("|", $arrayOptionDefaultValues);
|
array($optionGroup, $arrayOptionGroupDefaultValues, $arrayFieldNameForException["optionGroup"], $optionGroupCaseUpper)
|
||||||
|
);
|
||||||
|
|
||||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($arrayFieldNameForException["option"], ($optionCaseUpper)? $strdv : strtolower($strdv)), "Invalid value for \"{0}\", it only accepts values: \"{1}\".")));
|
foreach ($arrayAux as $value) {
|
||||||
|
$opt = $value[0];
|
||||||
|
$arrayDefaultValues = $value[1];
|
||||||
|
$fieldNameForException = $value[2];
|
||||||
|
$caseUpper = $value[3];
|
||||||
|
|
||||||
|
if ($opt != "") {
|
||||||
|
if (!in_array($opt, $arrayDefaultValues, true)) {
|
||||||
|
$strdv = implode("|", $arrayDefaultValues);
|
||||||
|
|
||||||
|
throw new \Exception(
|
||||||
|
str_replace(array("{0}", "{1}"),
|
||||||
|
array($fieldNameForException, ($caseUpper)? $strdv : strtolower($strdv)),
|
||||||
|
"Invalid value for \"{0}\", it only accepts values: \"{1}\".")
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -443,21 +532,22 @@ abstract class Importer
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Set variables
|
//Set variables
|
||||||
$opt = self::IMPORT_OPTION_CREATE_NEW; //CREATE
|
$arrayAux = array(
|
||||||
|
(($option != "")? "CREATE" : "") => self::IMPORT_OPTION_CREATE_NEW,
|
||||||
|
"OVERWRITE" => self::IMPORT_OPTION_OVERWRITE,
|
||||||
|
"DISABLE" => self::IMPORT_OPTION_DISABLE_AND_CREATE_NEW,
|
||||||
|
"KEEP" => self::IMPORT_OPTION_KEEP_WITHOUT_CHANGING_AND_CREATE_NEW
|
||||||
|
);
|
||||||
|
|
||||||
switch ($option) {
|
$option = $arrayAux[$option];
|
||||||
case "OVERWRITE":
|
|
||||||
$opt = self::IMPORT_OPTION_OVERWRITE;
|
|
||||||
break;
|
|
||||||
case "DISABLE":
|
|
||||||
$opt = self::IMPORT_OPTION_DISABLE_AND_CREATE_NEW;
|
|
||||||
break;
|
|
||||||
case "KEEP":
|
|
||||||
$opt = self::IMPORT_OPTION_KEEP_WITHOUT_CHANGING_AND_CREATE_NEW;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$option = $opt;
|
$arrayAux = array(
|
||||||
|
(($optionGroup != "")? "CREATE" : "") => self::GROUP_IMPORT_OPTION_CREATE_NEW,
|
||||||
|
"RENAME" => self::GROUP_IMPORT_OPTION_RENAME,
|
||||||
|
"MERGE" => self::GROUP_IMPORT_OPTION_MERGE_PREEXISTENT
|
||||||
|
);
|
||||||
|
|
||||||
|
$optionGroup = $arrayAux[$optionGroup];
|
||||||
|
|
||||||
if (isset($_FILES["filePmx"])) {
|
if (isset($_FILES["filePmx"])) {
|
||||||
$this->setSourceFromGlobals("filePmx");
|
$this->setSourceFromGlobals("filePmx");
|
||||||
@@ -473,13 +563,32 @@ abstract class Importer
|
|||||||
|
|
||||||
//Import
|
//Import
|
||||||
try {
|
try {
|
||||||
$projectUid = $this->import($option);
|
$projectUid = $this->import($option, $optionGroup);
|
||||||
|
|
||||||
$arrayData = array_merge(array("PRJ_UID" => $projectUid), $arrayData);
|
$arrayData = array_merge(array("PRJ_UID" => $projectUid), $arrayData);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$msg = str_replace(array(self::IMPORT_OPTION_CREATE_NEW, self::IMPORT_OPTION_OVERWRITE, self::IMPORT_OPTION_DISABLE_AND_CREATE_NEW, self::IMPORT_OPTION_KEEP_WITHOUT_CHANGING_AND_CREATE_NEW), $arrayOptionDefaultValues, $e->getMessage());
|
$strOpt = implode("|", $arrayOptionDefaultValues);
|
||||||
|
$strOptg = implode("|", $arrayOptionGroupDefaultValues);
|
||||||
|
|
||||||
throw (new \Exception($msg));
|
$strOpt = ($optionCaseUpper)? $strOpt : strtolower($strOpt);
|
||||||
|
$strOptg = ($optionGroupCaseUpper)? $strOptg : strtolower($strOptg);
|
||||||
|
|
||||||
|
$msg = str_replace(
|
||||||
|
array(
|
||||||
|
self::IMPORT_OPTION_CREATE_NEW,
|
||||||
|
self::IMPORT_OPTION_OVERWRITE,
|
||||||
|
self::IMPORT_OPTION_DISABLE_AND_CREATE_NEW,
|
||||||
|
self::IMPORT_OPTION_KEEP_WITHOUT_CHANGING_AND_CREATE_NEW,
|
||||||
|
|
||||||
|
self::GROUP_IMPORT_OPTION_CREATE_NEW,
|
||||||
|
self::GROUP_IMPORT_OPTION_RENAME,
|
||||||
|
self::GROUP_IMPORT_OPTION_MERGE_PREEXISTENT
|
||||||
|
),
|
||||||
|
array_merge(explode("|", $strOpt), explode("|", $strOptg)),
|
||||||
|
$e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
|
throw new \Exception($msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Return
|
//Return
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ class Project extends Api
|
|||||||
*
|
*
|
||||||
* @status 201
|
* @status 201
|
||||||
*/
|
*/
|
||||||
public function doPostImport(array $request_data, $option = null)
|
public function doPostImport(array $request_data, $option = null, $option_group = null)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$importer = new \ProcessMaker\Importer\XmlImporter();
|
$importer = new \ProcessMaker\Importer\XmlImporter();
|
||||||
@@ -139,7 +139,12 @@ class Project extends Api
|
|||||||
$importer->setSaveDir(PATH_DOCUMENT . "input");
|
$importer->setSaveDir(PATH_DOCUMENT . "input");
|
||||||
$importer->setData("usr_uid", $this->getUserId());
|
$importer->setData("usr_uid", $this->getUserId());
|
||||||
|
|
||||||
$arrayData = $importer->importPostFile($request_data, $option, array("projectFile" => "project_file", "option" => "option"));
|
$arrayData = $importer->importPostFile(
|
||||||
|
$request_data,
|
||||||
|
$option,
|
||||||
|
$option_group,
|
||||||
|
array("projectFile" => "project_file", "option" => "option", "optionGroup" => "option_group")
|
||||||
|
);
|
||||||
|
|
||||||
$response = $arrayData;
|
$response = $arrayData;
|
||||||
|
|
||||||
|
|||||||
@@ -846,7 +846,12 @@ importProcessExistGroup = function()
|
|||||||
success : function(o, resp) {
|
success : function(o, resp) {
|
||||||
var resp_ = Ext.util.JSON.decode(resp.response.responseText);
|
var resp_ = Ext.util.JSON.decode(resp.response.responseText);
|
||||||
var sNewProUid = resp_.sNewProUid;
|
var sNewProUid = resp_.sNewProUid;
|
||||||
window.location.href = "processes_Map?PRO_UID=" + sNewProUid;
|
|
||||||
|
if (typeof(resp_.project_type) != "undefined" && resp_.project_type == "bpmn") {
|
||||||
|
window.location.href = "../designer?prj_uid=" + sNewProUid;
|
||||||
|
} else {
|
||||||
|
window.location.href = "processes_Map?PRO_UID=" + sNewProUid;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
failure: function(o, resp) {
|
failure: function(o, resp) {
|
||||||
w.close();
|
w.close();
|
||||||
@@ -975,17 +980,16 @@ importProcessExistProcess = function()
|
|||||||
success: function(o, resp) {
|
success: function(o, resp) {
|
||||||
var resp_ = Ext.util.JSON.decode(resp.response.responseText);
|
var resp_ = Ext.util.JSON.decode(resp.response.responseText);
|
||||||
var sNewProUid = resp_.sNewProUid;
|
var sNewProUid = resp_.sNewProUid;
|
||||||
var projectType = (typeof(resp_.project_type) != "undefined")? resp_.project_type : "classicProject";
|
|
||||||
|
|
||||||
if (resp_.ExistGroupsInDatabase == 0) {
|
if (resp_.ExistGroupsInDatabase == 0) {
|
||||||
if (projectType == "classicProject") {
|
if (typeof(resp_.project_type) != "undefined" && resp_.project_type == "bpmn") {
|
||||||
window.location.href = "processes_Map?PRO_UID=" + sNewProUid;
|
|
||||||
} else {
|
|
||||||
window.location.href = "../designer?prj_uid=" + sNewProUid;
|
window.location.href = "../designer?prj_uid=" + sNewProUid;
|
||||||
|
} else {
|
||||||
|
window.location.href = "processes_Map?PRO_UID=" + sNewProUid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
importProcessGlobal.proFileName = resp_.fileName;
|
importProcessGlobal.proFileName = resp_.proFileName;
|
||||||
importProcessGlobal.groupBeforeAccion = resp_.groupBeforeAccion;
|
importProcessGlobal.groupBeforeAccion = resp_.groupBeforeAccion;
|
||||||
importProcessGlobal.sNewProUid = resp_.sNewProUid;
|
importProcessGlobal.sNewProUid = resp_.sNewProUid;
|
||||||
importProcessGlobal.importOption = resp_.importOption;
|
importProcessGlobal.importOption = resp_.importOption;
|
||||||
@@ -1090,8 +1094,9 @@ importProcess = function()
|
|||||||
if (resp_.catchMessage == "") {
|
if (resp_.catchMessage == "") {
|
||||||
if (resp_.ExistProcessInDatabase == "0") {
|
if (resp_.ExistProcessInDatabase == "0") {
|
||||||
if (resp_.ExistGroupsInDatabase == "0") {
|
if (resp_.ExistGroupsInDatabase == "0") {
|
||||||
var sNewProUid = resp_.sNewProUid;
|
var sNewProUid = resp_.sNewProUid;
|
||||||
if (resp_.project_type && resp_.project_type == "bpmn") {
|
|
||||||
|
if (typeof(resp_.project_type) != "undefined" && resp_.project_type == "bpmn") {
|
||||||
window.location.href = "../designer?prj_uid=" + sNewProUid;
|
window.location.href = "../designer?prj_uid=" + sNewProUid;
|
||||||
} else {
|
} else {
|
||||||
window.location.href = "processes_Map?PRO_UID=" + sNewProUid;
|
window.location.href = "processes_Map?PRO_UID=" + sNewProUid;
|
||||||
|
|||||||
Reference in New Issue
Block a user