diff --git a/workflow/engine/classes/Processes.php b/workflow/engine/classes/Processes.php index 3ad46b442..431aee38b 100644 --- a/workflow/engine/classes/Processes.php +++ b/workflow/engine/classes/Processes.php @@ -4179,12 +4179,15 @@ class Processes $arrayEmailServerDefault = $emailServer->getEmailServerDefault(); foreach ($arrayData as $value) { - unset($value['EMAIL_EVENT_FROM']); - unset($value['EMAIL_SERVER_UID']); - - if (!empty($arrayEmailServerDefault)) { - $value['EMAIL_EVENT_FROM'] = $arrayEmailServerDefault['MESS_ACCOUNT']; - $value['EMAIL_SERVER_UID'] = $arrayEmailServerDefault['MESS_UID']; + if (isset($value['__EMAIL_SERVER_UID_PRESERVED__']) && $value['__EMAIL_SERVER_UID_PRESERVED__'] === true) { + unset($value['__EMAIL_SERVER_UID_PRESERVED__']); + } else { + unset($value['EMAIL_EVENT_FROM']); + unset($value['EMAIL_SERVER_UID']); + if (!empty($arrayEmailServerDefault)) { + $value['EMAIL_EVENT_FROM'] = $arrayEmailServerDefault['MESS_ACCOUNT']; + $value['EMAIL_SERVER_UID'] = $arrayEmailServerDefault['MESS_UID']; + } } $emailEventData = $emailEvent->save($processUid, $value); diff --git a/workflow/engine/src/ProcessMaker/Importer/Importer.php b/workflow/engine/src/ProcessMaker/Importer/Importer.php index cf98c2e0e..f36dc271a 100644 --- a/workflow/engine/src/ProcessMaker/Importer/Importer.php +++ b/workflow/engine/src/ProcessMaker/Importer/Importer.php @@ -1,12 +1,15 @@ metadata['uid']); + $this->saveCurrentProcess($this->metadata['uid']); + $obj = $this->getCurrentProcess()->process; if (is_object($obj)) { if ($obj->getProTitle() !== $name) { if (\Process::existsByProTitle($name)) { @@ -273,6 +282,25 @@ abstract class Importer } } if(sizeof($newObjectArray)){ + + if (isset($this->importData["tables"]["workflow"]["tasks"])) { + foreach ($this->importData["tables"]["workflow"]["tasks"] as &$task) { + $this->preserveTaskConfiguration($task); + } + } + + if (isset($this->importData["tables"]["workflow"]["abeConfiguration"])) { + foreach ($this->importData["tables"]["workflow"]["abeConfiguration"] as &$abeConfiguration) { + $this->preserveAbeConfiguration($abeConfiguration); + } + } + + if (isset($this->importData["tables"]["workflow"]["emailEvent"])) { + foreach ($this->importData["tables"]["workflow"]["emailEvent"] as &$emailEvent) { + $this->preserveEmailEventConfiguration($emailEvent); + } + } + $objectList = $granularObj->loadObjectsListSelected($this->importData, $newObjectArray); if (sizeof($objectList) > 0 && $processGranulate) { $granularObj->import($objectList); @@ -567,6 +595,14 @@ abstract class Importer list($arrayWorkflowTables, $arrayWorkflowFiles) = $workflow->updateDataUidByArrayUid($arrayWorkflowTables, $arrayWorkflowFiles, $result); } + foreach ($arrayWorkflowTables["abeConfiguration"] as &$abeConfiguration) { + $this->preserveAbeConfiguration($abeConfiguration); + } + + foreach ($arrayWorkflowTables["emailEvent"] as &$emailEvent) { + $this->preserveEmailEventConfiguration($emailEvent); + } + $this->importWfTables($arrayWorkflowTables); //Import workflow files @@ -579,6 +615,7 @@ abstract class Importer foreach ($arrayWorkflowTables["tasks"] as $key => $value) { $arrayTaskData = $value; if ( !in_array($arrayTaskData["TAS_TYPE"], $dummyTaskTypes) ) { + $this->preserveTaskConfiguration($arrayTaskData); $result = $workflow->updateTask($arrayTaskData["TAS_UID"], $arrayTaskData); } } @@ -800,4 +837,111 @@ abstract class Importer return $e->getMessage(); } } + + /** + * Set the current objects before import. + * + * @param object $currentProcess + */ + public function setCurrentProcess($currentProcess) + { + $this->currentProcess = $currentProcess; + } + + /** + * Get the current objects before import. + * + * @return object + */ + public function getCurrentProcess() + { + return $this->currentProcess; + } + + /** + * Saves the current objects before import. + * + * @param string $proUid + */ + public function saveCurrentProcess($proUid) + { + $result = new StdClass(); + + $result->process = ProcessPeer::retrieveByPK($proUid); + + $processes = new Processes(); + $result->tasks = $processes->getTaskRows($proUid); + $result->abeConfigurations = $processes->getActionsByEmail($proUid); + $result->emailEvents = $processes->getEmailEvent($proUid); + + $this->setCurrentProcess($result); + } + + /** + * Restore some specific values for the tasks configuration. + * + * @param array $data + */ + public function preserveTaskConfiguration(&$data) + { + $currentProcess = $this->getCurrentProcess(); + if (is_object($currentProcess)) { + $tasks = $currentProcess->tasks; + if (is_array($tasks)) { + foreach ($tasks as $task) { + if ($task["TAS_UID"] === $data["TAS_UID"]) { + $data["TAS_EMAIL_SERVER_UID"] = $task["TAS_EMAIL_SERVER_UID"]; + $data["TAS_RECEIVE_SERVER_UID"] = $task["TAS_RECEIVE_SERVER_UID"]; + break; + } + } + } + } + } + + /** + * Restore some specific values for the abe configuration. + * + * @param array $data + */ + public function preserveAbeConfiguration(&$data) + { + $currentProcess = $this->getCurrentProcess(); + if (is_object($currentProcess)) { + $abeConfigurations = $currentProcess->abeConfigurations; + if (is_array($abeConfigurations)) { + foreach ($abeConfigurations as $abeConfiguration) { + if ($abeConfiguration["PRO_UID"] === $data["PRO_UID"] && + $abeConfiguration["TAS_UID"] === $data["TAS_UID"]) { + $data["ABE_EMAIL_SERVER_UID"] = $abeConfiguration["ABE_EMAIL_SERVER_UID"]; + break; + } + } + } + } + } + + /** + * Restore some specific values for the email event configuration. + * + * @param array $data + */ + public function preserveEmailEventConfiguration(&$data) + { + $currentProcess = $this->getCurrentProcess(); + if (is_object($currentProcess)) { + $emailEvents = $currentProcess->emailEvents; + if (is_array($emailEvents)) { + foreach ($emailEvents as $emailEvent) { + if ($emailEvent["PRJ_UID"] === $data["PRJ_UID"] && + $emailEvent["EVN_UID"] === $data["EVN_UID"]) { + $data["EMAIL_SERVER_UID"] = $emailEvent["EMAIL_SERVER_UID"]; + $data["EMAIL_EVENT_FROM"] = $emailEvent["EMAIL_EVENT_FROM"]; + $data["__EMAIL_SERVER_UID_PRESERVED__"] = true; + break; + } + } + } + } + } }