PMCORE-980

This commit is contained in:
Andrea Adamczyk
2021-03-23 15:13:52 -04:00
parent 3c21cfa277
commit 22a2a334fa
8 changed files with 192 additions and 8 deletions

View File

@@ -0,0 +1,18 @@
<?php
$factory->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' => ''
];
});

View File

@@ -13,6 +13,7 @@ use ProcessMaker\Model\GroupUser;
use ProcessMaker\Model\Groupwf; use ProcessMaker\Model\Groupwf;
use ProcessMaker\Model\Process; use ProcessMaker\Model\Process;
use ProcessMaker\Model\ProcessCategory; use ProcessMaker\Model\ProcessCategory;
use ProcessMaker\Model\SubProcess;
use ProcessMaker\Model\Task; use ProcessMaker\Model\Task;
use ProcessMaker\Model\TaskUser; use ProcessMaker\Model\TaskUser;
use ProcessMaker\Model\User; use ProcessMaker\Model\User;
@@ -2538,4 +2539,41 @@ class DelegationTest extends TestCase
$this->assertNotEmpty($result); $this->assertNotEmpty($result);
$this->assertEquals($result, $delegation->DEL_TITLE); $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);
}
} }

View File

@@ -0,0 +1,64 @@
<?php
namespace Tests\unit\workflow\engine\src\ProcessMaker\Model;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use ProcessMaker\Model\Process;
use ProcessMaker\Model\SubProcess;
use Tests\TestCase;
/**
* Class ProcessTest
*
* @coversDefaultClass \ProcessMaker\Model\SubProcess
*/
class SubProcessTest extends TestCase
{
use DatabaseTransactions;
/**
* Call the setUp parent method
*/
public function setUp()
{
parent::setUp();
}
/**
* It should test the getProParents() method
*
* @covers \ProcessMaker\Model\SubProcess::getProParents()
* @test
*/
public function it_should_test_the_get_pro_parents_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']
]);
$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);
}
}

View File

@@ -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." 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." 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 # TRANSLATION
# LABEL/ID_CANT_DELETE_DEPARTMENT_HAS_USERS # LABEL/ID_CANT_DELETE_DEPARTMENT_HAS_USERS
#: LABEL/ID_CANT_DELETE_DEPARTMENT_HAS_USERS #: LABEL/ID_CANT_DELETE_DEPARTMENT_HAS_USERS

View File

@@ -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_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_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_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_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_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') , ( 'LABEL','ID_CANT_SAVE_TRIGGER','en','A trigger with the same name already exists in this process.','2014-05-29') ,

View File

@@ -1,4 +1,8 @@
<?php <?php
use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\SubProcess;
/** /**
* processes_DeleteCases.php * processes_DeleteCases.php
* *
@@ -14,6 +18,15 @@ try {
$uids = explode(',', $_POST['PRO_UIDS']); $uids = explode(',', $_POST['PRO_UIDS']);
$process = new Process(); $process = new Process();
foreach ($uids as $uid) { foreach ($uids as $uid) {
$parents = SubProcess::getProParents($uid);
if (!empty($parents)) {
if (Delegation::hasActiveParentsCases($parents)) {
$resp->status = false;
$resp->msg = G::LoadTranslation('ID_CANT_DELETE_SUB_PROCESS_PARENT_HAS_ACTIVE_CASES');
echo G::json_encode($resp);
die();
}
}
$process->deleteProcessCases($uid); $process->deleteProcessCases($uid);
} }
@@ -21,11 +34,9 @@ try {
$resp->msg = G::LoadTranslation('ID_ALL_RECORDS_DELETED_SUCESSFULLY'); $resp->msg = G::LoadTranslation('ID_ALL_RECORDS_DELETED_SUCESSFULLY');
echo G::json_encode($resp); echo G::json_encode($resp);
} catch (Exception $e) { } catch (Exception $e) {
$resp->status = false; $resp->status = false;
$resp->msg = $e->getMessage(); $resp->msg = $e->getMessage();
$resp->trace = $e->getTraceAsString(); $resp->trace = $e->getTraceAsString();
echo G::json_encode($resp); echo G::json_encode($resp);
} }

View File

@@ -834,9 +834,9 @@ class Delegation extends Model
*/ */
public function scopeJoinPreviousIndex($query) 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') $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; return $query;
@@ -1863,7 +1863,7 @@ class Delegation extends Model
$cases = new Cases; $cases = new Cases;
if (!is_array($caseData)) { if (!is_array($caseData)) {
$r = $cases->unserializeData($caseData); $r = $cases->unserializeData($caseData);
if($r !== false) { if ($r !== false) {
$caseData = $r; $caseData = $r;
} }
} }
@@ -1877,13 +1877,13 @@ class Delegation extends Model
// If is empty get the previous title // If is empty get the previous title
if ($delIndexPrevious > 0) { if ($delIndexPrevious > 0) {
$thread = self::getThreadInfo($appNumber, $delIndexPrevious); $thread = self::getThreadInfo($appNumber, $delIndexPrevious);
if(empty($thread['DEL_TITLE'])) { if (empty($thread['DEL_TITLE'])) {
$threadTitle = '# '. $appNumber; $threadTitle = '# ' . $appNumber;
} else { } else {
$threadTitle = $thread['DEL_TITLE']; $threadTitle = $thread['DEL_TITLE'];
} }
} else { } else {
$threadTitle = '# '. $appNumber; $threadTitle = '# ' . $appNumber;
} }
} }
@@ -1949,4 +1949,24 @@ class Delegation extends Model
return $results; 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;
}
} }

View File

@@ -0,0 +1,26 @@
<?php
namespace ProcessMaker\Model;
use Illuminate\Database\Eloquent\Model;
use ProcessMaker\Model\Application;
class SubProcess extends Model
{
protected $table = 'SUB_PROCESS';
protected $primaryKey = 'SP_UID';
// We do not have create/update timestamps for this table
public $timestamps = false;
/**
* Get he Process parents of a subprocess
*
* @param string $proUid
* @return array
*/
public static function getProParents($proUid)
{
$query = SubProcess::select('PRO_PARENT', 'TAS_PARENT')->where('PRO_UID', $proUid);
return $query->get()->values()->toArray();
}
}