Example #1
0
 public function updateDataUidByArrayUid(array $arrayWorkflowData, array $arrayWorkflowFile, array $arrayUid)
 {
     try {
         $processUidOld = $arrayUid[0]["old_uid"];
         $processUid = $arrayUid[0]["new_uid"];
         //Update Table.Field
         $arrayUpdateTableField = array("tasks" => array("fieldname" => "TAS_UID", "oldFieldname" => "TAS_UID_OLD"), "webEntryEvent" => array("fieldname" => "EVN_UID", "oldFieldname" => "EVN_UID_OLD"), "messageEventDefinition" => array("fieldname" => "EVN_UID", "oldFieldname" => "EVN_UID_OLD"), "scriptTask" => array("fieldname" => "ACT_UID", "oldFieldname" => "ACT_UID_OLD"), "timerEvent" => array("fieldname" => "EVN_UID", "oldFieldname" => "EVN_UID_OLD"), "emailEvent" => array("fieldname" => "EVN_UID", "oldFieldname" => "EVN_UID_OLD"), "abeConfiguration" => array("fieldname" => "TAS_UID", "oldFieldname" => "TAS_UID_OLD"));
         foreach ($arrayUpdateTableField as $key => $value) {
             $table = $key;
             $fieldname = $value["fieldname"];
             $oldFieldname = $value["oldFieldname"];
             if (isset($arrayWorkflowData[$table])) {
                 foreach ($arrayWorkflowData[$table] as $key2 => $value2) {
                     $uid = $arrayWorkflowData[$table][$key2][$fieldname];
                     foreach ($arrayUid as $value3) {
                         $arrayItem = $value3;
                         if ($arrayItem["old_uid"] == $uid) {
                             $arrayWorkflowData[$table][$key2][$fieldname] = $arrayItem["new_uid"];
                             $arrayWorkflowData[$table][$key2][$oldFieldname] = $uid;
                             break;
                         }
                     }
                 }
             }
         }
         //Workflow tables
         $workflowData = (object) $arrayWorkflowData;
         $processes = new \Processes();
         $processes->setProcessGUID($workflowData, $processUid);
         $processes->renewAll($workflowData);
         $arrayWorkflowData = (array) $workflowData;
         foreach ($arrayWorkflowData["dynaforms"] as $key => $value) {
             if ($arrayWorkflowData["dynaforms"][$key]["DYN_CONTENT"] != "") {
                 $dynaFormContent = $arrayWorkflowData["dynaforms"][$key]["DYN_CONTENT"];
                 foreach ($arrayWorkflowData["uid"] as $value2) {
                     $arrayAux = $value2;
                     foreach ($arrayAux as $key3 => $value3) {
                         $uidOld = $key3;
                         $uid = $value3;
                         $dynaFormContent = str_replace($uidOld, $uid, $dynaFormContent);
                     }
                 }
                 $arrayWorkflowData["dynaforms"][$key]["DYN_CONTENT"] = $dynaFormContent;
             }
         }
         //Workflow files
         foreach ($arrayWorkflowFile as $key => $value) {
             $arrayFile = $value;
             foreach ($arrayFile as $key2 => $value2) {
                 $file = $value2;
                 $arrayWorkflowFile[$key][$key2]["file_path"] = str_replace($processUidOld, $processUid, isset($file["file_path"]) ? $file["file_path"] : $file["filepath"]);
                 $arrayWorkflowFile[$key][$key2]["file_content"] = str_replace($processUidOld, $processUid, $file["file_content"]);
             }
         }
         if (isset($arrayWorkflowData["uid"])) {
             foreach ($arrayWorkflowData["uid"] as $key => $value) {
                 $arrayT = $value;
                 foreach ($arrayT as $key2 => $value2) {
                     $uidOld = $key2;
                     $uid = $value2;
                     foreach ($arrayWorkflowFile as $key3 => $value3) {
                         $arrayFile = $value3;
                         foreach ($arrayFile as $key4 => $value4) {
                             $file = $value4;
                             $arrayWorkflowFile[$key3][$key4]["file_path"] = str_replace($uidOld, $uid, $file["file_path"]);
                             $arrayWorkflowFile[$key3][$key4]["file_content"] = str_replace($uidOld, $uid, $file["file_content"]);
                         }
                     }
                 }
             }
         }
         //Return
         return array($arrayWorkflowData, $arrayWorkflowFile);
     } catch (\Exception $e) {
         self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
         throw $e;
     }
 }
                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) {
    $G_PUBLISH = new Publisher();
    $aMessage['MESSAGE'] = $e->getMessage();
Example #3
0
    public function updateDataUidByArrayUid(array $arrayWorkflowData, array $arrayWorkflowFile, array $arrayUid)
    {
        try {
            $processUidOld = $arrayUid[0]["old_uid"];
            $processUid = $arrayUid[0]["new_uid"];

            //Update Table.Field
            $arrayUpdateTableField = array(
                "tasks"                  => array("fieldname" => "TAS_UID", "oldFieldname" => "TAS_UID_OLD"), //Update TASK.TAS_UID
                "webEntryEvent"          => array("fieldname" => "EVN_UID", "oldFieldname" => "EVN_UID_OLD"), //Update WEB_ENTRY_EVENT.EVN_UID
                "messageEventDefinition" => array("fieldname" => "EVN_UID", "oldFieldname" => "EVN_UID_OLD"), //Update MESSAGE_EVENT_DEFINITION.EVN_UID
                "scriptTask"             => array("fieldname" => "ACT_UID", "oldFieldname" => "ACT_UID_OLD"), //Update SCRIPT_TASK.ACT_UID
                "timerEvent"             => array("fieldname" => "EVN_UID", "oldFieldname" => "EVN_UID_OLD"), //Update TIMER_EVENT.EVN_UID
                "emailEvent"             => array("fieldname" => "EVN_UID", "oldFieldname" => "EVN_UID_OLD")  //Update EMAIL_EVENT.EVN_UID
            );

            foreach ($arrayUpdateTableField as $key => $value) {
                $table = $key;
                $fieldname = $value["fieldname"];
                $oldFieldname = $value["oldFieldname"];

                if (isset($arrayWorkflowData[$table])) {
                    foreach ($arrayWorkflowData[$table] as $key2 => $value2) {
                        $uid = $arrayWorkflowData[$table][$key2][$fieldname];

                        foreach ($arrayUid as $value3) {
                            $arrayItem = $value3;

                            if ($arrayItem["old_uid"] == $uid) {
                                $arrayWorkflowData[$table][$key2][$fieldname]    = $arrayItem["new_uid"];
                                $arrayWorkflowData[$table][$key2][$oldFieldname] = $uid;
                                break;
                            }
                        }
                    }
                }
            }

            //Workflow tables
            $workflowData = (object)($arrayWorkflowData);

            $processes = new \Processes();
            $processes->setProcessGUID($workflowData, $processUid);
            $processes->renewAll($workflowData);

            $arrayWorkflowData = (array)($workflowData);

            //Workflow files
            foreach ($arrayWorkflowFile as $key => $value) {
                $arrayFile = $value;

                foreach ($arrayFile as $key2 => $value2) {
                    $file = $value2;

                    $arrayWorkflowFile[$key][$key2]["file_path"] = str_replace($processUidOld, $processUid, (isset($file["file_path"]))? $file["file_path"] : $file["filepath"]);
                    $arrayWorkflowFile[$key][$key2]["file_content"] = str_replace($processUidOld, $processUid, $file["file_content"]);
                }
            }

            if (isset($arrayWorkflowData["uid"])) {
                foreach ($arrayWorkflowData["uid"] as $key => $value) {
                    $arrayT = $value;

                    foreach ($arrayT as $key2 => $value2) {
                        $uidOld = $key2;
                        $uid = $value2;

                        foreach ($arrayWorkflowFile as $key3 => $value3) {
                            $arrayFile = $value3;

                            foreach ($arrayFile as $key4 => $value4) {
                                $file = $value4;

                                $arrayWorkflowFile[$key3][$key4]["file_path"] = str_replace($uidOld, $uid, $file["file_path"]);
                                $arrayWorkflowFile[$key3][$key4]["file_content"] = str_replace($uidOld, $uid, $file["file_content"]);
                            }
                        }
                    }
                }
            }

            //Return
            return array($arrayWorkflowData, $arrayWorkflowFile);
        } catch (\Exception $e) {
            self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());

            throw $e;
        }
    }
Example #4
0
 /**
  * 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;
     }
 }
Example #5
0
    public function updateDataUidByArrayUid(array $arrayWorkflowData, array $arrayWorkflowFile, array $arrayUid)
    {
        try {
            $processUidOld = $arrayUid[0]["old_uid"];
            $processUid = $arrayUid[0]["new_uid"];

            //Update TASK.TAS_UID
            foreach ($arrayWorkflowData["tasks"] as $key => $value) {
                $taskUid = $arrayWorkflowData["tasks"][$key]["TAS_UID"];

                foreach ($arrayUid as $value2) {
                    $arrayItem = $value2;

                    if ($arrayItem["old_uid"] == $taskUid) {
                        $arrayWorkflowData["tasks"][$key]["TAS_UID_OLD"] = $taskUid;
                        $arrayWorkflowData["tasks"][$key]["TAS_UID"] = $arrayItem["new_uid"];
                        break;
                    }
                }
            }

            //Update WEB_ENTRY_EVENT.EVN_UID
            if (isset($arrayWorkflowData["webEntryEvent"])) {
                foreach ($arrayWorkflowData["webEntryEvent"] as $key => $value) {
                    $webEntryEventEventUid = $arrayWorkflowData["webEntryEvent"][$key]["EVN_UID"];

                    foreach ($arrayUid as $value2) {
                        $arrayItem = $value2;

                        if ($arrayItem["old_uid"] == $webEntryEventEventUid) {
                            $arrayWorkflowData["webEntryEvent"][$key]["EVN_UID"] = $arrayItem["new_uid"];
                            break;
                        }
                    }
                }
            }

            //Update MESSAGE_EVENT_DEFINITION.EVN_UID
            if (isset($arrayWorkflowData["messageEventDefinition"])) {
                foreach ($arrayWorkflowData["messageEventDefinition"] as $key => $value) {
                    $messageEventDefinitionEventUid = $arrayWorkflowData["messageEventDefinition"][$key]["EVN_UID"];

                    foreach ($arrayUid as $value2) {
                        $arrayItem = $value2;

                        if ($arrayItem["old_uid"] == $messageEventDefinitionEventUid) {
                            $arrayWorkflowData["messageEventDefinition"][$key]["EVN_UID"] = $arrayItem["new_uid"];
                            break;
                        }
                    }
                }
            }

            //Workflow tables
            $workflowData = (object)($arrayWorkflowData);

            $processes = new \Processes();
            $processes->setProcessGUID($workflowData, $processUid);
            $processes->renewAll($workflowData);

            $arrayWorkflowData = (array)($workflowData);

            //Workflow files
            foreach ($arrayWorkflowFile as $key => $value) {
                $arrayFile = $value;

                foreach ($arrayFile as $key2 => $value2) {
                    $file = $value2;

                    $arrayWorkflowFile[$key][$key2]["file_path"] = str_replace($processUidOld, $processUid, (isset($file["file_path"]))? $file["file_path"] : $file["filepath"]);
                    $arrayWorkflowFile[$key][$key2]["file_content"] = str_replace($processUidOld, $processUid, $file["file_content"]);
                }
            }

            if (isset($arrayWorkflowData["uid"])) {
                foreach ($arrayWorkflowData["uid"] as $key => $value) {
                    $arrayT = $value;

                    foreach ($arrayT as $key2 => $value2) {
                        $uidOld = $key2;
                        $uid = $value2;

                        foreach ($arrayWorkflowFile as $key3 => $value3) {
                            $arrayFile = $value3;

                            foreach ($arrayFile as $key4 => $value4) {
                                $file = $value4;

                                $arrayWorkflowFile[$key3][$key4]["file_path"] = str_replace($uidOld, $uid, $file["file_path"]);
                                $arrayWorkflowFile[$key3][$key4]["file_content"] = str_replace($uidOld, $uid, $file["file_content"]);
                            }
                        }
                    }
                }
            }

            //Return
            return array($arrayWorkflowData, $arrayWorkflowFile);
        } catch (\Exception $e) {
            self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());

            throw $e;
        }
    }