$oDirectory = dir(PATH_OUTTRUNK . 'compiled' . PATH_SEP . 'xmlform' . PATH_SEP . $sProUid); while ($sObjectName = $oDirectory->read()) { if ($sObjectName != '.' && $sObjectName != '..') { unlink(PATH_OUTTRUNK . 'compiled' . PATH_SEP . 'xmlform' . PATH_SEP . $sProUid . PATH_SEP . $sObjectName); } } $oDirectory->close(); } $sNewProUid = $sProUid; } //Disable current Process and create a new version of the Process if ($option == 2) { $oProcess->disablePreviousProcesses($sProUid); $sNewProUid = $oProcess->getUnusedProcessGUID(); $oProcess->setProcessGuid($oData, $sNewProUid); $oProcess->setProcessParent($oData, $sProUid); $oData->process['PRO_TITLE'] = "New - " . $oData->process['PRO_TITLE'] . ' - ' . date('M d, H:i'); $oProcess->renewAll($oData); $oProcess->createProcessFromData($oData, $path . $filename); } //Create a completely new Process without change the current Process if ($option == 3) { //krumo ($oData); die; $sNewProUid = $oProcess->getUnusedProcessGUID(); $oProcess->setProcessGuid($oData, $sNewProUid); $oData->process['PRO_TITLE'] = "Copy of - " . $oData->process['PRO_TITLE'] . ' - ' . date('M d, H:i'); $oProcess->renewAll($oData); $oProcess->createProcessFromData($oData, $path . $filename); } G::header('Location: processes_Map?PRO_UID=' . $sNewProUid); } catch (Exception $e) {
/** * import process fromLibrary: downloads and imports a process from the ProcessMaker library * * @param string sessionId : The session ID (which was obtained at login). * @param string processId : * @param string version : * @param string importOption : * @param string usernameLibrary : The username to obtain access to the ProcessMaker library. * @param string passwordLibrary : The password to obtain access to the ProcessMaker library. * @return $eturns will return an object */ public function importProcessFromLibrary($processId, $version = '', $importOption = '', $usernameLibrary = '', $passwordLibrary = '') { try { G::LoadClass('processes'); //$versionReq = $_GET['v']; //. (isset($_GET['s']) ? '&s=' . $_GET['s'] : '') $ipaddress = $_SERVER['REMOTE_ADDR']; $oProcesses = new Processes(); $oProcesses->ws_open_public(); $oProcess = $oProcesses->ws_processGetData($processId); if ($oProcess->status_code != 0) { throw new Exception($oProcess->message); } $privacy = $oProcess->privacy; $strSession = ''; if ($privacy != 'FREE') { global $sessionId; $antSession = $sessionId; $oProcesses->ws_open($usernameLibrary, $passwordLibrary); $strSession = "&s=" . $sessionId; $sessionId = $antSession; } //downloading the file $localPath = PATH_DOCUMENT . 'input' . PATH_SEP; G::mk_dir($localPath); $newfilename = G::GenerateUniqueId() . '.pm'; $downloadUrl = PML_DOWNLOAD_URL . '?id=' . $processId . $strSession; $oProcess = new Processes(); $oProcess->downloadFile($downloadUrl, $localPath, $newfilename); //getting the ProUid from the file recently downloaded $oData = $oProcess->getProcessData($localPath . $newfilename); if (is_null($oData)) { $data['DOWNLOAD_URL'] = $downloadUrl; $data['LOCAL_PATH'] = $localPath; $data['NEW_FILENAME'] = $newfilename; throw new Exception(G::loadTranslation('ID_ERROR_URL_PROCESS_INVALID', SYS_LANG, $data)); } $sProUid = $oData->process['PRO_UID']; $oData->process['PRO_UID_OLD'] = $sProUid; //if the process exists, we need to check the $importOption to and re-import if the user wants, if ($oProcess->processExists($sProUid)) { //Update the current Process, overwriting all tasks and steps if ($importOption == 1) { $oProcess->updateProcessFromData($oData, $localPath . $newfilename); //delete the xmlform cache 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()) { if ($sObjectName != '.' && $sObjectName != '..') { $strAux = PATH_OUTTRUNK . 'compiled' . PATH_SEP . 'xmlform' . PATH_SEP; $strAux = $strAux . $sProUid . PATH_SEP . $sObjectName; unlink($strAux); } } $oDirectory->close(); } $sNewProUid = $sProUid; } //Disable current Process and create a new version of the Process if ($importOption == 2) { $oProcess->disablePreviousProcesses($sProUid); $sNewProUid = $oProcess->getUnusedProcessGUID(); $oProcess->setProcessGuid($oData, $sNewProUid); $oProcess->setProcessParent($oData, $sProUid); $oData->process['PRO_TITLE'] = "New - " . $oData->process['PRO_TITLE'] . ' - ' . date('M d, H:i'); $oProcess->renewAll($oData); $oProcess->createProcessFromData($oData, $localPath . $newfilename); } //Create a completely new Process without change the current Process if ($importOption == 3) { //krumo ($oData); die; $sNewProUid = $oProcess->getUnusedProcessGUID(); $oProcess->setProcessGuid($oData, $sNewProUid); $strAux = "Copy of - " . $oData->process['PRO_TITLE'] . ' - ' . date('M d, H:i'); $oData->process['PRO_TITLE'] = $strAux; $oProcess->renewAll($oData); $oProcess->createProcessFromData($oData, $localPath . $newfilename); } if ($importOption != 1 && $importOption != 2 && $importOption != 3) { throw new Exception(G::loadTranslation('ID_PROCESS_ALREADY_IN_SYSTEM')); } } //finally, creating the process if the process doesn't exist if (!$oProcess->processExists($processId)) { $oProcess->createProcessFromData($oData, $localPath . $newfilename); } //show the info after the imported process $oProcess = new Processes(); $oProcess->ws_open_public(); $processData = $oProcess->ws_processGetData($processId); $result->status_code = 0; $result->message = G::loadTranslation('ID_COMMAND_EXECUTED_SUCCESSFULLY'); $result->timestamp = date('Y-m-d H:i:s'); $result->processId = $processId; $result->processTitle = $processData->title; $result->category = isset($processData->category) ? $processData->category : ''; $result->version = $processData->version; return $result; } catch (Exception $e) { $result = new wsResponse(100, $e->getMessage()); return $result; } }