diff --git a/workflow/engine/classes/class.processes.php b/workflow/engine/classes/class.processes.php index bc0da1403..7be0ba5c9 100755 --- a/workflow/engine/classes/class.processes.php +++ b/workflow/engine/classes/class.processes.php @@ -1466,6 +1466,18 @@ class Processes return $oTask->updateTaskRows($aTasks); } + /** + * Add New Task Rows from a $aTasks array data and returns those in an array. + * + * @param $aTasks array + * @return array $oTask array + */ + public function addNewTaskRows($aTasks) + { + $oTask = new Tasks(); + return $oTask->addNewTaskRows($aTasks); + } + /** * Gets all Route rows from a Process and returns those in an array. * @@ -1805,6 +1817,24 @@ class Processes } } + /** + * @param array $arrayData + */ + public function addNewProcessUser(array $arrayData) + { + try { + $processUser = new ProcessUser(); + foreach ($arrayData as $value) { + $record = $value; + if (!$processUser->Exists($record["PU_UID"])) { + $result = $processUser->create($record); + } + } + } catch (Exception $e) { + throw $e; + } + } + /** * Create "Process Variables" records * @@ -1849,6 +1879,24 @@ class Processes } } + /** + * @param $arrayData + */ + public function addNewProcessVariables($arrayData) + { + try { + foreach ($arrayData as $value) { + $processVariables = new ProcessVariables(); + $record = $value; + if (!$processVariables->Exists($record["VAR_UID"])) { + $processVariables->create($record); + } + } + } catch (Exception $e) { + throw $e; + } + } + /** * Gets Input Documents Rows from aProcess. @@ -1912,6 +1960,20 @@ class Processes return; } + /** + * @param $aInput + */ + public function addNewInputRows($aInput) + { + foreach ($aInput as $key => $row) { + $oInput = new InputDocument(); + if (!$oInput->InputExists($row['INP_DOC_UID'])) { + $oInput->create($row); + } + } + return; + } + /** * change and Renew all Input GUID, because the process needs to have a new set of Inputs * @@ -2019,7 +2081,7 @@ class Processes { foreach ($aOutput as $key => $row) { $oOutput = new OutputDocument(); - if (!$oOutput->OutputExists($row['OUT_DOC_UID'])) { + if ($oOutput->OutputExists($row['OUT_DOC_UID'])) { $oOutput->update($row); } else { $oOutput->create($row); @@ -2028,6 +2090,20 @@ class Processes return; } + /** + * @param $aOutput + */ + public function addNewOutputRows($aOutput) + { + foreach ($aOutput as $key => $row) { + $oOutput = new OutputDocument(); + if (!$oOutput->OutputExists($row['OUT_DOC_UID'])) { + $oOutput->create($row); + } + } + return; + } + /** * change and Renew all Output GUID, because the process needs to have a new set of Outputs * @@ -2931,6 +3007,20 @@ class Processes } } + /** + * @param $aTrigger + * @throws Exception + */ + public function addNewTriggerRows($aTrigger) + { + $oTrigger = new Triggers(); + foreach ($aTrigger as $key => $row) { + if (!$oTrigger->TriggerExists($row['TRI_UID'])) { + $oTrigger->create($row); + } + } + } + /** * Get Groupwf Rows for a Process form an array * @@ -3615,6 +3705,35 @@ class Processes } } + /** + * Add new Connection rows if the passed ones are not existent + * @param $aConnections + */ + public function addNewDBConnectionsRows($aConnections) + { + try { + $oConnection = new DbSource(); + foreach ($aConnections as $sKey => $aRow) { + if (!$oConnection->Exists($aRow['DBS_UID'], $aRow['PRO_UID'])) { + $oConnection->create($aRow); + } + + // Update information in the table of contents + $oContent = new Content(); + $ConCategory = 'DBS_DESCRIPTION'; + $ConParent = ''; + $ConId = $aRow['DBS_UID']; + $ConLang = SYS_LANG; + if ($oContent->Exists($ConCategory, $ConParent, $ConId, $ConLang)) { + $oContent->removeContent($ConCategory, $ConParent, $ConId); + } + $oContent->addContent($ConCategory, $ConParent, $ConId, $ConLang, $aRow['DBS_DESCRIPTION']); + } + } catch (Exception $e) { + throw $e; + } + } + /** * Create Report Tables from an array of data @@ -3943,6 +4062,24 @@ class Processes } } + /** + * @param array $arrayData + * @throws Exception + */ + public function addNewFilesManager($processUid, array $arrayData) + { + try { + $filesManager = new \ProcessMaker\BusinessModel\FilesManager(); + foreach ($arrayData as $value) { + if (!$filesManager->existsProcessFile($value['PRF_UID'])) { + $filesManager->addProcessFilesManagerInDb($value); + } + } + } catch (Exception $e) { + throw $e; + } + } + /** * Cleanup Report Tables References from an array of data * diff --git a/workflow/engine/classes/class.tasks.php b/workflow/engine/classes/class.tasks.php index b19b9949a..39e596651 100755 --- a/workflow/engine/classes/class.tasks.php +++ b/workflow/engine/classes/class.tasks.php @@ -147,6 +147,24 @@ class Tasks return; } + /** + * updates row tasks from an Task Array + * + * @param string $aTasks + * @return array + */ + public function addNewTaskRows($aTask) + { + foreach ($aTask as $key => $row) { + $oTask = new Task(); + if (!$oTask->taskExists($row['TAS_UID'])) { + $res = $oTask->create($row); + } + } + return; + } + + /** * Get all Routes for any Process * diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/AssignmentRulesMigrator.php b/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/AssignmentRulesMigrator.php index d65820870..901f9f8d4 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/AssignmentRulesMigrator.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/AssignmentRulesMigrator.php @@ -38,7 +38,7 @@ class AssignmentRulesMigrator implements Importable, Exportable if ($replace) { $this->processes->createTaskRows($data); } else { - $this->processes->updateTaskRows($data); + $this->processes->addNewTaskRows($data); } } catch (\Exception $e) { diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/DBConnectionMigrator.php b/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/DBConnectionMigrator.php index d334fb663..45cca9d9b 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/DBConnectionMigrator.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/DBConnectionMigrator.php @@ -29,7 +29,7 @@ class DBConnectionMigrator implements Importable, Exportable if ($replace) { $this->processes->createDBConnectionsRows($data); } else { - $this->processes->updateDBConnectionsRows($data); + $this->processes->addNewDBConnectionsRows($data); } } catch (\Exception $e) { \Logger::log($e->getMessage()); diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/DynaformsMigrator.php b/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/DynaformsMigrator.php index 771d23088..0fac69a19 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/DynaformsMigrator.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/DynaformsMigrator.php @@ -29,7 +29,7 @@ class DynaformsMigrator implements Importable, Exportable if ($replace) { $this->processes->createDynaformRows($data); } else { - $this->processes->updateDynaformRows($data); + $this->processes->addNewDynaformRows($data); } } catch (\Exception $e) { \Logger::log($e->getMessage()); diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/FilesMigrator.php b/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/FilesMigrator.php index e568c25d7..30a8d5fcb 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/FilesMigrator.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/FilesMigrator.php @@ -2,8 +2,7 @@ namespace ProcessMaker\BusinessModel\Migrator; -use ProcessMaker\BusinessModel\Process; -use Symfony\Component\Config\Definition\Exception\Exception; +use ProcessMaker\BusinessModel\Util; use \ProcessMaker\BusinessModel\Migrator\FileHandler; class FilesMigrator implements Importable, Exportable @@ -37,7 +36,7 @@ class FilesMigrator implements Importable, Exportable if ($replace) { $this->processes->createFilesManager($value['PRO_UID'], array($value)); } else { - $this->processes->updateFilesManager($value['PRO_UID'], array($value)); + $this->processes->addNewFilesManager($value['PRO_UID'], array($value)); } } } @@ -48,12 +47,18 @@ class FilesMigrator implements Importable, Exportable foreach ($files as $file) { $filename = $basePath . ((isset($file["file_path"])) ? $file["file_path"] : $file["filepath"]); $path = dirname($filename); - if (!is_dir($path)) { Util\Common::mk_dir($path, 0775); } + if (file_exists($filename)) { + if ($replace) { + file_put_contents($filename, $file["file_content"]); + } + } else { + file_put_contents($filename, $file["file_content"]); + } + - file_put_contents($filename, $file["file_content"]); @chmod($filename, 0775); } } diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/InputDocumentsMigrator.php b/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/InputDocumentsMigrator.php index 4f390b85e..754989fb6 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/InputDocumentsMigrator.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/InputDocumentsMigrator.php @@ -29,7 +29,7 @@ class InputDocumentsMigrator implements Importable, Exportable if ($replace) { $this->processes->createInputRows($data); } else { - $this->processes->updateInputRows($data); + $this->processes->addNewInputRows($data); } } catch (\Exception $e) { \Logger::log($e->getMessage()); diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/OutputDocumentsMigrator.php b/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/OutputDocumentsMigrator.php index eaa545c28..3428ca563 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/OutputDocumentsMigrator.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/OutputDocumentsMigrator.php @@ -31,7 +31,7 @@ class OutputDocumentsMigrator implements Importable, Exportable if ($replace) { $this->processes->createOutputRows($data); } else { - $this->processes->updateOutputRows($data); + $this->processes->addNewOutputRows($data); } } catch (\Exception $e) { \Logger::log($e->getMessage()); diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/SupervisorsMigrator.php b/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/SupervisorsMigrator.php index 762e871c9..fe64d87c5 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/SupervisorsMigrator.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/SupervisorsMigrator.php @@ -30,7 +30,7 @@ class SupervisorsMigrator implements Importable, Exportable if ($replace) { $this->processes->createProcessUser($data); } else { - $this->processes->updateProcessUser($data); + $this->processes->addNewProcessUser($data); } } catch (\Exception $e) { \Logger::log($e->getMessage()); diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/TemplatesMigrator.php b/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/TemplatesMigrator.php index 5aeacbc23..e1ee75cc2 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/TemplatesMigrator.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/TemplatesMigrator.php @@ -2,7 +2,8 @@ namespace ProcessMaker\BusinessModel\Migrator; -use Symfony\Component\Config\Definition\Exception\Exception; +use ProcessMaker\BusinessModel\Util; + class TemplatesMigrator implements Importable, Exportable { @@ -35,7 +36,7 @@ class TemplatesMigrator implements Importable, Exportable if ($replace) { $this->processes->createFilesManager($value['PRO_UID'], array($value)); } else { - $this->processes->updateFilesManager($value['PRO_UID'], array($value)); + $this->processes->addNewFilesManager($value['PRO_UID'], array($value)); } } } @@ -51,7 +52,13 @@ class TemplatesMigrator implements Importable, Exportable Util\Common::mk_dir($path, 0775); } - file_put_contents($filename, $file["file_content"]); + if (file_exists($filename)) { + if ($replace) { + file_put_contents($filename, $file["file_content"]); + } + } else { + file_put_contents($filename, $file["file_content"]); + } @chmod($filename, 0775); } } diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/TriggersMigrator.php b/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/TriggersMigrator.php index 795008731..6dcdbb765 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/TriggersMigrator.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/TriggersMigrator.php @@ -31,7 +31,7 @@ class TriggersMigrator implements Importable, Exportable if ($replace) { $this->processes->createTriggerRows($data); } else { - $this->processes->updateTriggerRows($data); + $this->processes->addNewTriggerRows($data); } } catch (\Exception $e) { \Logger::log($e->getMessage());