diff --git a/database/factories/SubProcessFactory.php b/database/factories/SubProcessFactory.php new file mode 100644 index 000000000..b98d4ee9b --- /dev/null +++ b/database/factories/SubProcessFactory.php @@ -0,0 +1,18 @@ +define(\ProcessMaker\Model\SubProcess::class, function () { + return [ + 'SP_UID' => G::generateUniqueID(), + 'PRO_UID' => G::generateUniqueID(), + 'TAS_UID' => G::generateUniqueID(), + 'PRO_PARENT' => G::generateUniqueID(), + 'TAS_PARENT' => G::generateUniqueID(), + 'SP_TYPE' => '', + 'SP_SYNCHRONOUS' => 0, + 'SP_SYNCHRONOUS_TYPE' => '', + 'SP_SYNCHRONOUS_WAIT' => 0, + 'SP_VARIABLES_OUT' => '', + 'SP_VARIABLES_IN' => '', + 'SP_GRID_IN' => '' + ]; +}); diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php index d7dc062ed..f26de1584 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php @@ -13,6 +13,7 @@ use ProcessMaker\Model\GroupUser; use ProcessMaker\Model\Groupwf; use ProcessMaker\Model\Process; use ProcessMaker\Model\ProcessCategory; +use ProcessMaker\Model\SubProcess; use ProcessMaker\Model\Task; use ProcessMaker\Model\TaskUser; use ProcessMaker\Model\User; @@ -2538,4 +2539,41 @@ class DelegationTest extends TestCase $this->assertNotEmpty($result); $this->assertEquals($result, $delegation->DEL_TITLE); } + + /** + * It should test the hasActiveParentsCases() method + * + * @covers \ProcessMaker\Model\Delegation::hasActiveParentsCases() + * @test + */ + public function it_should_test_the_has_active_parents_cases_method() + { + $process = factory(Process::class)->create(); + $processParent = factory(Process::class, 3)->create(); + factory(SubProcess::class)->create([ + 'PRO_UID' => $process['PRO_UID'], + 'PRO_PARENT' => $processParent[0]['PRO_UID'] + ]); + factory(SubProcess::class)->create([ + 'PRO_UID' => $process['PRO_UID'], + 'PRO_PARENT' => $processParent[1]['PRO_UID'] + ]); + factory(SubProcess::class)->create([ + 'PRO_UID' => $process['PRO_UID'], + 'PRO_PARENT' => $processParent[2]['PRO_UID'] + ]); + + $parents = SubProcess::getProParents($process['PRO_UID']); + + factory(Delegation::class)->create([ + 'PRO_UID' => $parents[0]['PRO_PARENT'], + 'TAS_UID' => $parents[0]['TAS_PARENT'], + 'DEL_THREAD_STATUS' => 'OPEN' + ]); + + $res = Delegation::hasActiveParentsCases($parents); + + // Assert the result is true + $this->assertTrue($res); + } } \ No newline at end of file diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/SubProcessTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/SubProcessTest.php new file mode 100644 index 000000000..61edcbb5f --- /dev/null +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/SubProcessTest.php @@ -0,0 +1,64 @@ +create(); + $processParent = factory(Process::class, 3)->create(); + factory(SubProcess::class)->create([ + 'PRO_UID' => $process['PRO_UID'], + 'PRO_PARENT' => $processParent[0]['PRO_UID'] + ]); + factory(SubProcess::class)->create([ + 'PRO_UID' => $process['PRO_UID'], + 'PRO_PARENT' => $processParent[1]['PRO_UID'] + ]); + factory(SubProcess::class)->create([ + 'PRO_UID' => $process['PRO_UID'], + 'PRO_PARENT' => $processParent[2]['PRO_UID'] + ]); + + $res = SubProcess::getProParents($process['PRO_UID']); + + $res = array_map(function ($x) { + return $x['PRO_PARENT']; + }, $res); + + // Assert the subprocess has three parents + $this->assertCount(3, $res); + + // Assert that the parents are the processes created + $this->assertContains($processParent[0]['PRO_UID'], $res); + $this->assertContains($processParent[1]['PRO_UID'], $res); + $this->assertContains($processParent[2]['PRO_UID'], $res); + } +} diff --git a/workflow/engine/content/translations/english/processmaker.en.po b/workflow/engine/content/translations/english/processmaker.en.po index 23221227e..5ffcd9d01 100755 --- a/workflow/engine/content/translations/english/processmaker.en.po +++ b/workflow/engine/content/translations/english/processmaker.en.po @@ -3383,6 +3383,12 @@ msgstr "You can not delete the template {0} because it has a relationship with E msgid "It is not possible to delete the department because it has subdepartments." msgstr "It is not possible to delete the department because it has subdepartments." +# TRANSLATION +# LABEL/ID_CANT_DELETE_SUB_PROCESS_PARENT_HAS_ACTIVE_CASES +#: LABEL/ID_CANT_DELETE_SUB_PROCESS_PARENT_HAS_ACTIVE_CASES +msgid "Is not possible to delete sub-process cases, while the master process has active cases." +msgstr "Is not possible to delete sub-process cases, while the master process has active cases." + # TRANSLATION # LABEL/ID_CANT_DELETE_DEPARTMENT_HAS_USERS #: LABEL/ID_CANT_DELETE_DEPARTMENT_HAS_USERS diff --git a/workflow/engine/data/mysql/insert.sql b/workflow/engine/data/mysql/insert.sql index 9f3b08360..6ef6d89ce 100755 --- a/workflow/engine/data/mysql/insert.sql +++ b/workflow/engine/data/mysql/insert.sql @@ -57371,6 +57371,7 @@ INSERT INTO TRANSLATION (TRN_CATEGORY,TRN_ID,TRN_LANG,TRN_VALUE,TRN_UPDATE_DATE ( 'LABEL','ID_CANNOT_IMPORT','en','CANNOT IMPORT','2017-10-03') , ( 'LABEL','ID_CANNOT_REMOVE_TEMPLATE_EMAIL_EVENT','en','You can not delete the template {0} because it has a relationship with Email Event','2016-07-05') , ( 'LABEL','ID_CANT_DELETE_DEPARTMENT_HAS_CHILDREN','en','It is not possible to delete the department because it has subdepartments.','2014-10-21') , +( 'LABEL','ID_CANT_DELETE_SUB_PROCESS_PARENT_HAS_ACTIVE_CASES','en','Is not possible to delete sub-process cases, while the master process has active cases.','2021-03-23') , ( 'LABEL','ID_CANT_DELETE_DEPARTMENT_HAS_USERS','en','Department cannot be deleted while it has assigned users.','2015-03-23') , ( 'LABEL','ID_CANT_RESOLVE_APPLICATION','en','Can''t resolve the Aplication ID for this request.','2014-01-15') , ( 'LABEL','ID_CANT_SAVE_TRIGGER','en','A trigger with the same name already exists in this process.','2014-05-29') , diff --git a/workflow/engine/methods/processes/processes_DeleteCases.php b/workflow/engine/methods/processes/processes_DeleteCases.php index 7fdaee1bb..f2f156133 100644 --- a/workflow/engine/methods/processes/processes_DeleteCases.php +++ b/workflow/engine/methods/processes/processes_DeleteCases.php @@ -1,4 +1,8 @@ status = false; + $resp->msg = G::LoadTranslation('ID_CANT_DELETE_SUB_PROCESS_PARENT_HAS_ACTIVE_CASES'); + echo G::json_encode($resp); + die(); + } + } $process->deleteProcessCases($uid); } @@ -21,11 +34,9 @@ try { $resp->msg = G::LoadTranslation('ID_ALL_RECORDS_DELETED_SUCESSFULLY'); echo G::json_encode($resp); - } catch (Exception $e) { $resp->status = false; $resp->msg = $e->getMessage(); $resp->trace = $e->getTraceAsString(); echo G::json_encode($resp); } - diff --git a/workflow/engine/src/ProcessMaker/Model/Delegation.php b/workflow/engine/src/ProcessMaker/Model/Delegation.php index 241ca7e93..2d889e07a 100644 --- a/workflow/engine/src/ProcessMaker/Model/Delegation.php +++ b/workflow/engine/src/ProcessMaker/Model/Delegation.php @@ -834,9 +834,9 @@ class Delegation extends Model */ public function scopeJoinPreviousIndex($query) { - $query->leftJoin('APP_DELEGATION AS AD', function( $leftJoin) { + $query->leftJoin('APP_DELEGATION AS AD', function ($leftJoin) { $leftJoin->on('APP_DELEGATION.APP_NUMBER', '=', 'AD.APP_NUMBER') - ->on('APP_DELEGATION.DEL_PREVIOUS', '=', 'AD.DEL_INDEX'); + ->on('APP_DELEGATION.DEL_PREVIOUS', '=', 'AD.DEL_INDEX'); }); return $query; @@ -1863,7 +1863,7 @@ class Delegation extends Model $cases = new Cases; if (!is_array($caseData)) { $r = $cases->unserializeData($caseData); - if($r !== false) { + if ($r !== false) { $caseData = $r; } } @@ -1877,13 +1877,13 @@ class Delegation extends Model // If is empty get the previous title if ($delIndexPrevious > 0) { $thread = self::getThreadInfo($appNumber, $delIndexPrevious); - if(empty($thread['DEL_TITLE'])) { - $threadTitle = '# '. $appNumber; + if (empty($thread['DEL_TITLE'])) { + $threadTitle = '# ' . $appNumber; } else { $threadTitle = $thread['DEL_TITLE']; } } else { - $threadTitle = '# '. $appNumber; + $threadTitle = '# ' . $appNumber; } } @@ -1949,4 +1949,24 @@ class Delegation extends Model return $results; } + + /** + * Check if a subprocess has active parent cases + * + * @param array $parents + * @return bool + */ + public static function hasActiveParentsCases($parents) + { + foreach ($parents as $parent) { + $query = Delegation::select()->where('PRO_UID', $parent['PRO_PARENT']) + ->where('TAS_UID', $parent['TAS_PARENT'])->where('DEL_THREAD_STATUS', 'OPEN') + ->limit(1); + $res = $query->get()->values()->toArray(); + if (!empty($res)) { + return true; + } + } + return false; + } } diff --git a/workflow/engine/src/ProcessMaker/Model/SubProcess.php b/workflow/engine/src/ProcessMaker/Model/SubProcess.php new file mode 100644 index 000000000..e7ec2421e --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Model/SubProcess.php @@ -0,0 +1,26 @@ +where('PRO_UID', $proUid); + return $query->get()->values()->toArray(); + } +}