Merge pull request #1887 from Jennydmz/BUG-11846

BUG 11846 Al importar un proceso PM siempre debe tomar al usuario actual como Process Owner.
This commit is contained in:
julceslauhub
2013-07-12 10:30:15 -07:00

View File

@@ -1,303 +1,298 @@
<?php <?php
/** /**
* processes_ImportFile.php * processes_ImportFile.php
* *
* ProcessMaker Open Source Edition * ProcessMaker Open Source Edition
* Copyright (C) 2004 - 2008 Colosa Inc. * Copyright (C) 2004 - 2008 Colosa Inc.
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the * published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version. * License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
* For more information, contact Colosa Inc, 2566 Le Jeune Rd., * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com. * Coral Gables, FL, 33134, USA, or email info@colosa.com.
*/ */
ini_set( 'max_execution_time', '0' ); ini_set( 'max_execution_time', '0' );
function reservedWordsSqlValidate ($data) function reservedWordsSqlValidate ($data)
{ {
$arrayAux = array (); $arrayAux = array ();
$reservedWordsSql = G::reservedWordsSql(); $reservedWordsSql = G::reservedWordsSql();
foreach ($data->reportTables as $rptIndex => $rptValue) { foreach ($data->reportTables as $rptIndex => $rptValue) {
if (in_array( strtoupper( $rptValue["REP_TAB_NAME"] ), $reservedWordsSql )) { if (in_array( strtoupper( $rptValue["REP_TAB_NAME"] ), $reservedWordsSql )) {
$arrayAux[] = $rptValue["REP_TAB_NAME"]; $arrayAux[] = $rptValue["REP_TAB_NAME"];
} }
} }
if (count( $arrayAux ) > 0) { if (count( $arrayAux ) > 0) {
throw (new Exception( G::LoadTranslation( "ID_PMTABLE_INVALID_NAME", array (implode( ", ", $arrayAux ) throw (new Exception( G::LoadTranslation( "ID_PMTABLE_INVALID_NAME", array (implode( ", ", $arrayAux )
) ) )); ) ) ));
} }
$arrayAux = array (); $arrayAux = array ();
foreach ($data->reportTablesVars as $rptIndex => $rptValue) { foreach ($data->reportTablesVars as $rptIndex => $rptValue) {
if (in_array( strtoupper( $rptValue["REP_VAR_NAME"] ), $reservedWordsSql )) { if (in_array( strtoupper( $rptValue["REP_VAR_NAME"] ), $reservedWordsSql )) {
$arrayAux[] = $rptValue["REP_VAR_NAME"]; $arrayAux[] = $rptValue["REP_VAR_NAME"];
} }
} }
if (count( $arrayAux ) > 0) { if (count( $arrayAux ) > 0) {
throw (new Exception( G::LoadTranslation( "ID_PMTABLE_INVALID_FIELD_NAME", array (implode( ", ", $arrayAux ) throw (new Exception( G::LoadTranslation( "ID_PMTABLE_INVALID_FIELD_NAME", array (implode( ", ", $arrayAux )
) ) )); ) ) ));
} }
} }
$action = isset( $_REQUEST['ajaxAction'] ) ? $_REQUEST['ajaxAction'] : null; $action = isset( $_REQUEST['ajaxAction'] ) ? $_REQUEST['ajaxAction'] : null;
$result = new stdClass(); $result = new stdClass();
$result->success = true; $result->success = true;
$result->catchMessage = ""; $result->catchMessage = "";
if ($action == "uploadFileNewProcess") { if ($action == "uploadFileNewProcess") {
try { try {
//type of file: only pm //type of file: only pm
$processFileType = $_REQUEST["processFileType"]; $processFileType = $_REQUEST["processFileType"];
$oProcess = new stdClass(); $oProcess = new stdClass();
$oData = new stdClass(); $oData = new stdClass();
$isCorrectTypeFile = 1; $isCorrectTypeFile = 1;
if (isset( $_FILES['form']['type']['PROCESS_FILENAME'] )) { if (isset( $_FILES['form']['type']['PROCESS_FILENAME'] )) {
$allowedExtensions = array ($processFileType $allowedExtensions = array ($processFileType
); );
$allowedExtensions = array ('pm'); $allowedExtensions = array ('pm');
if (! in_array( end( explode( ".", $_FILES['form']['name']['PROCESS_FILENAME'] ) ), $allowedExtensions )) { if (! in_array( end( explode( ".", $_FILES['form']['name']['PROCESS_FILENAME'] ) ), $allowedExtensions )) {
throw new Exception( G::LoadTranslation( "ID_FILE_UPLOAD_INCORRECT_EXTENSION" ) ); throw new Exception( G::LoadTranslation( "ID_FILE_UPLOAD_INCORRECT_EXTENSION" ) );
} }
} }
if ($processFileType != "pm") { if ($processFileType != "pm") {
throw new Exception( G::LoadTranslation( "ID_ERROR_UPLOAD_FILE_CONTACT_ADMINISTRATOR" ) ); throw new Exception( G::LoadTranslation( "ID_ERROR_UPLOAD_FILE_CONTACT_ADMINISTRATOR" ) );
} }
if ($processFileType == "pm") { if ($processFileType == "pm") {
G::LoadClass( 'processes' ); G::LoadClass( 'processes' );
$oProcess = new Processes(); $oProcess = new Processes();
} }
$result->success = true; $result->success = true;
$result->ExistProcessInDatabase = ""; //"" -Default $result->ExistProcessInDatabase = ""; //"" -Default
//0 -Dont exist process //0 -Dont exist process
//1 -exist process //1 -exist process
$result->ExistGroupsInDatabase = ""; //"" -Default $result->ExistGroupsInDatabase = ""; //"" -Default
//0 -Dont exist process //0 -Dont exist process
//1 -exist process //1 -exist process
$optionGroupExistInDatabase = isset( $_REQUEST["optionGroupExistInDatabase"] ) ? $_REQUEST["optionGroupExistInDatabase"] : null; $optionGroupExistInDatabase = isset( $_REQUEST["optionGroupExistInDatabase"] ) ? $_REQUEST["optionGroupExistInDatabase"] : null;
//!Upload file //!Upload file
if (! is_null( $optionGroupExistInDatabase )) { if (! is_null( $optionGroupExistInDatabase )) {
$filename = $_REQUEST["PRO_FILENAME"]; $filename = $_REQUEST["PRO_FILENAME"];
$path = PATH_DOCUMENT . 'input' . PATH_SEP; $path = PATH_DOCUMENT . 'input' . PATH_SEP;
} else { } else {
if ($_FILES['form']['error']['PROCESS_FILENAME'] == 0) { if ($_FILES['form']['error']['PROCESS_FILENAME'] == 0) {
$filename = $_FILES['form']['name']['PROCESS_FILENAME']; $filename = $_FILES['form']['name']['PROCESS_FILENAME'];
$path = PATH_DOCUMENT . 'input' . PATH_SEP; $path = PATH_DOCUMENT . 'input' . PATH_SEP;
$tempName = $_FILES['form']['tmp_name']['PROCESS_FILENAME']; $tempName = $_FILES['form']['tmp_name']['PROCESS_FILENAME'];
//$action = "none"; //$action = "none";
G::uploadFile( $tempName, $path, $filename ); G::uploadFile( $tempName, $path, $filename );
}
} }
}
//importing a bpmn diagram, using external class to do it.
if ($processFileType == "bpmn") { //importing a bpmn diagram, using external class to do it.
G::LoadClass( 'bpmnExport' ); if ($processFileType == "bpmn") {
$bpmn = new bpmnExport(); G::LoadClass( 'bpmnExport' );
$bpmn->importBpmn( $path . $filename ); $bpmn = new bpmnExport();
die(); $bpmn->importBpmn( $path . $filename );
} die();
}
//if file is a .pm file continues normally the importing
if ($processFileType == "pm") { //if file is a .pm file continues normally the importing
$oData = $oProcess->getProcessData( $path . $filename ); if ($processFileType == "pm") {
} $oData = $oProcess->getProcessData( $path . $filename );
}
reservedWordsSqlValidate( $oData );
reservedWordsSqlValidate( $oData );
//!Upload file
$Fields['PRO_FILENAME'] = $filename; //!Upload file
$Fields['IMPORT_OPTION'] = 2; $Fields['PRO_FILENAME'] = $filename;
$Fields['IMPORT_OPTION'] = 2;
$sProUid = $oData->process['PRO_UID'];
$sProUid = $oData->process['PRO_UID'];
$oData->process['PRO_UID_OLD'] = $sProUid;
$oData->process['PRO_UID_OLD'] = $sProUid;
if ($oProcess->processExists( $sProUid )) {
$result->ExistProcessInDatabase = 1; if ($oProcess->processExists( $sProUid )) {
} else { $result->ExistProcessInDatabase = 1;
$result->ExistProcessInDatabase = 0; } else {
} $result->ExistProcessInDatabase = 0;
}
//!respect of the groups
$result->ExistGroupsInDatabase = 1; //!respect of the groups
$result->groupBeforeAccion = $action; $result->ExistGroupsInDatabase = 1;
if (! is_null( $optionGroupExistInDatabase )) { $result->groupBeforeAccion = $action;
if ($optionGroupExistInDatabase == 1) { if (! is_null( $optionGroupExistInDatabase )) {
$oData->groupwfs = $oProcess->renameExistingGroups( $oData->groupwfs ); if ($optionGroupExistInDatabase == 1) {
} else if ($optionGroupExistInDatabase == 2) { $oData->groupwfs = $oProcess->renameExistingGroups( $oData->groupwfs );
$oBaseGroup = $oData->groupwfs; } else if ($optionGroupExistInDatabase == 2) {
$oNewGroup = $oProcess->mergeExistingGroups( $oData->groupwfs ); $oBaseGroup = $oData->groupwfs;
$oData->groupwfs = $oNewGroup; $oNewGroup = $oProcess->mergeExistingGroups( $oData->groupwfs );
$oData->taskusers = $oProcess->mergeExistingUsers( $oBaseGroup, $oNewGroup, $oData->taskusers ); $oData->groupwfs = $oNewGroup;
$oData->objectPermissions = $oProcess->mergeExistingUsers( $oBaseGroup, $oNewGroup, $oData->objectPermissions ); $oData->taskusers = $oProcess->mergeExistingUsers( $oBaseGroup, $oNewGroup, $oData->taskusers );
} $oData->objectPermissions = $oProcess->mergeExistingUsers( $oBaseGroup, $oNewGroup, $oData->objectPermissions );
$result->ExistGroupsInDatabase = 0; }
} else { $result->ExistGroupsInDatabase = 0;
if (! ($oProcess->checkExistingGroups( $oData->groupwfs ) > 0)) { } else {
$result->ExistGroupsInDatabase = 0; if (! ($oProcess->checkExistingGroups( $oData->groupwfs ) > 0)) {
} $result->ExistGroupsInDatabase = 0;
} }
}
//replacing a nonexistent user for the current user
$UsrUid = $oData->process['PRO_CREATE_USER']; //replacing the processOwner user for the current user
G::LoadClass( 'Users' ); $oData->process['PRO_CREATE_USER'] = $_SESSION['USER_LOGGED'];
$user = new Users();
if (!$user->userExists( $UsrUid )) //!respect of the groups
{
$oData->process['PRO_CREATE_USER'] = $_SESSION['USER_LOGGED']; if ($result->ExistProcessInDatabase == 0 && $result->ExistGroupsInDatabase == 0) {
} if ($processFileType == "pm") {
$oProcess->createProcessFromData( $oData, $path . $filename );
//!respect of the groups }
}
if ($result->ExistProcessInDatabase == 0 && $result->ExistGroupsInDatabase == 0) {
if ($processFileType == "pm") { //!data ouput
$oProcess->createProcessFromData( $oData, $path . $filename ); $result->sNewProUid = $sProUid;
} $result->proFileName = $Fields['PRO_FILENAME'];
} } catch (Exception $e) {
$result->response = $e->getMessage();
//!data ouput $result->catchMessage = $e->getMessage();
$result->sNewProUid = $sProUid; $result->success = true;
$result->proFileName = $Fields['PRO_FILENAME']; }
} catch (Exception $e) { }
$result->response = $e->getMessage();
$result->catchMessage = $e->getMessage(); if ($action == "uploadFileNewProcessExist") {
$result->success = true; try {
} $option = $_REQUEST["IMPORT_OPTION"];
} $filename = $_REQUEST["PRO_FILENAME"];
$processFileType = $_REQUEST["processFileType"];
if ($action == "uploadFileNewProcessExist") {
try { $result->ExistGroupsInDatabase = ""; //"" -Default
$option = $_REQUEST["IMPORT_OPTION"]; //0 -Dont exist process
$filename = $_REQUEST["PRO_FILENAME"]; //1 -exist process
$processFileType = $_REQUEST["processFileType"];
$result->ExistGroupsInDatabase = ""; //"" -Default $optionGroupExistInDatabase = isset( $_REQUEST["optionGroupExistInDatabase"] ) ? $_REQUEST["optionGroupExistInDatabase"] : null;
//0 -Dont exist process $sNewProUid = "";
//1 -exist process
$oProcess = new stdClass();
if ($processFileType != "pm") {
$optionGroupExistInDatabase = isset( $_REQUEST["optionGroupExistInDatabase"] ) ? $_REQUEST["optionGroupExistInDatabase"] : null; throw new Exception( G::LoadTranslation( "ID_ERROR_UPLOAD_FILE_CONTACT_ADMINISTRATOR" ) );
$sNewProUid = ""; }
$oProcess = new stdClass(); //load the variables
if ($processFileType != "pm") { if ($processFileType == "pm") {
throw new Exception( G::LoadTranslation( "ID_ERROR_UPLOAD_FILE_CONTACT_ADMINISTRATOR" ) ); G::LoadClass( 'processes' );
} $oProcess = new Processes();
}
//load the variables
if ($processFileType == "pm") { $path = PATH_DOCUMENT . 'input' . PATH_SEP;
G::LoadClass( 'processes' );
$oProcess = new Processes(); if ($processFileType == "pm") {
} $oData = $oProcess->getProcessData( $path . $filename );
}
$path = PATH_DOCUMENT . 'input' . PATH_SEP;
reservedWordsSqlValidate( $oData );
if ($processFileType == "pm") {
$oData = $oProcess->getProcessData( $path . $filename ); $Fields['PRO_FILENAME'] = $filename;
} $sProUid = $oData->process['PRO_UID'];
reservedWordsSqlValidate( $oData ); $oData->process['PRO_UID_OLD'] = $sProUid;
$Fields['PRO_FILENAME'] = $filename; $result->ExistGroupsInDatabase = 1;
$sProUid = $oData->process['PRO_UID']; if (! is_null( $optionGroupExistInDatabase )) {
if ($optionGroupExistInDatabase == 1) {
$oData->process['PRO_UID_OLD'] = $sProUid; $oData->groupwfs = $oProcess->renameExistingGroups( $oData->groupwfs );
} else if ($optionGroupExistInDatabase == 2) {
$result->ExistGroupsInDatabase = 1; $oBaseGroup = $oData->groupwfs;
if (! is_null( $optionGroupExistInDatabase )) { $oNewGroup = $oProcess->mergeExistingGroups( $oData->groupwfs );
if ($optionGroupExistInDatabase == 1) { $oData->groupwfs = $oNewGroup;
$oData->groupwfs = $oProcess->renameExistingGroups( $oData->groupwfs ); $oData->taskusers = $oProcess->mergeExistingUsers( $oBaseGroup, $oNewGroup, $oData->taskusers );
} else if ($optionGroupExistInDatabase == 2) { }
$oBaseGroup = $oData->groupwfs; $result->ExistGroupsInDatabase = 0;
$oNewGroup = $oProcess->mergeExistingGroups( $oData->groupwfs ); } else {
$oData->groupwfs = $oNewGroup; if (! ($oProcess->checkExistingGroups( $oData->groupwfs ) > 0)) {
$oData->taskusers = $oProcess->mergeExistingUsers( $oBaseGroup, $oNewGroup, $oData->taskusers ); $result->ExistGroupsInDatabase = 0;
} }
$result->ExistGroupsInDatabase = 0; }
} else {
if (! ($oProcess->checkExistingGroups( $oData->groupwfs ) > 0)) { if ($result->ExistGroupsInDatabase == 0) {
$result->ExistGroupsInDatabase = 0; //Update the current Process, overwriting all tasks and steps
} if ($option == 1) {
} $oProcess->updateProcessFromData( $oData, $path . $filename );
if (file_exists( PATH_OUTTRUNK . 'compiled' . PATH_SEP . 'xmlform' . PATH_SEP . $sProUid )) {
if ($result->ExistGroupsInDatabase == 0) { $oDirectory = dir( PATH_OUTTRUNK . 'compiled' . PATH_SEP . 'xmlform' . PATH_SEP . $sProUid );
//Update the current Process, overwriting all tasks and steps while ($sObjectName = $oDirectory->read()) {
if ($option == 1) { if (($sObjectName != '.') && ($sObjectName != '..')) {
$oProcess->updateProcessFromData( $oData, $path . $filename ); unlink( PATH_OUTTRUNK . 'compiled' . PATH_SEP . 'xmlform' . PATH_SEP . $sProUid . PATH_SEP . $sObjectName );
if (file_exists( PATH_OUTTRUNK . 'compiled' . PATH_SEP . 'xmlform' . PATH_SEP . $sProUid )) { }
$oDirectory = dir( PATH_OUTTRUNK . 'compiled' . PATH_SEP . 'xmlform' . PATH_SEP . $sProUid ); }
while ($sObjectName = $oDirectory->read()) { $oDirectory->close();
if (($sObjectName != '.') && ($sObjectName != '..')) { }
unlink( PATH_OUTTRUNK . 'compiled' . PATH_SEP . 'xmlform' . PATH_SEP . $sProUid . PATH_SEP . $sObjectName ); $sNewProUid = $sProUid;
} }
}
$oDirectory->close(); //Disable current Process and create a new version of the Process
} if ($option == 2) {
$sNewProUid = $sProUid; $oProcess->disablePreviousProcesses( $sProUid );
} $sNewProUid = $oProcess->getUnusedProcessGUID();
$oProcess->setProcessGuid( $oData, $sNewProUid );
//Disable current Process and create a new version of the Process $oProcess->setProcessParent( $oData, $sProUid );
if ($option == 2) { $oData->process['PRO_TITLE'] = "New - " . $oData->process['PRO_TITLE'] . ' - ' . date( 'M d, H:i' );
$oProcess->disablePreviousProcesses( $sProUid ); $oProcess->renewAll( $oData );
$sNewProUid = $oProcess->getUnusedProcessGUID();
$oProcess->setProcessGuid( $oData, $sNewProUid ); if ($processFileType == "pm") {
$oProcess->setProcessParent( $oData, $sProUid ); $oProcess->createProcessFromData( $oData, $path . $filename );
$oData->process['PRO_TITLE'] = "New - " . $oData->process['PRO_TITLE'] . ' - ' . date( 'M d, H:i' ); }
$oProcess->renewAll( $oData ); }
if ($processFileType == "pm") { //Create a completely new Process without change the current Process
$oProcess->createProcessFromData( $oData, $path . $filename ); if ($option == 3) {
} //krumo ($oData); die;
} $sNewProUid = $oProcess->getUnusedProcessGUID();
$oProcess->setProcessGuid( $oData, $sNewProUid );
//Create a completely new Process without change the current Process $oData->process['PRO_TITLE'] = G::LoadTranslation('ID_COPY_OF'). ' - ' . $oData->process['PRO_TITLE'] . ' - ' . date( 'M d, H:i' );
if ($option == 3) { $oProcess->renewAll( $oData );
//krumo ($oData); die;
$sNewProUid = $oProcess->getUnusedProcessGUID(); if ($processFileType == "pm") {
$oProcess->setProcessGuid( $oData, $sNewProUid ); $oProcess->createProcessFromData( $oData, $path . $filename );
$oData->process['PRO_TITLE'] = G::LoadTranslation('ID_COPY_OF'). ' - ' . $oData->process['PRO_TITLE'] . ' - ' . date( 'M d, H:i' ); }
$oProcess->renewAll( $oData ); }
}
if ($processFileType == "pm") {
$oProcess->createProcessFromData( $oData, $path . $filename ); //!data ouput
} $result->fileName = $filename;
} $result->importOption = $option;
} $result->sNewProUid = $sNewProUid;
$result->success = true;
//!data ouput $result->ExistGroupsInDatabase = $result->ExistGroupsInDatabase;
$result->fileName = $filename; $result->groupBeforeAccion = $action;
$result->importOption = $option; //!data ouput
$result->sNewProUid = $sNewProUid; } catch (Exception $e) {
$result->success = true; $result->response = $e->getMessage();
$result->ExistGroupsInDatabase = $result->ExistGroupsInDatabase; $result->success = true;
$result->groupBeforeAccion = $action; }
//!data ouput }
} catch (Exception $e) {
$result->response = $e->getMessage(); echo G::json_encode( $result );
$result->success = true; exit();
}
}
echo G::json_encode( $result );
exit();