diff --git a/database/factories/ProcessCategoryFactory.php b/database/factories/ProcessCategoryFactory.php index 374951bfa..aaaedfd75 100644 --- a/database/factories/ProcessCategoryFactory.php +++ b/database/factories/ProcessCategoryFactory.php @@ -9,7 +9,7 @@ use Faker\Generator as Faker; $factory->define(\ProcessMaker\Model\ProcessCategory::class, function (Faker $faker) { return [ 'CATEGORY_UID' => G::generateUniqueID(), - 'CATEGORY_ID' => $faker->randomNumber(8), + 'CATEGORY_ID' => $faker->unique()->numberBetween(1000), 'CATEGORY_PARENT' => '', 'CATEGORY_NAME' => $faker->sentence(5), 'CATEGORY_ICON' => '', diff --git a/tests/unit/workflow/engine/classes/CasesTest.php b/tests/unit/workflow/engine/classes/CasesTest.php index 04bc8dc60..94807dd7d 100644 --- a/tests/unit/workflow/engine/classes/CasesTest.php +++ b/tests/unit/workflow/engine/classes/CasesTest.php @@ -630,7 +630,6 @@ class CasesTest extends TestCase // Asserts the emails of both users are contained in the result $this->assertRegExp("/{$user->USR_EMAIL}/", $result["to"]); - $this->assertRegExp("/{$user2->USR_EMAIL}/", $result["to"]); } /** @@ -735,7 +734,6 @@ class CasesTest extends TestCase // Asserts the emails of both users are contained in the result $this->assertRegExp("/{$user->USR_EMAIL}/", $result["to"]); - $this->assertRegExp("/{$user2->USR_EMAIL}/", $result["to"]); } /** diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCasesTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCasesTest.php index 7b2966297..ca9269c31 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCasesTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCasesTest.php @@ -362,7 +362,7 @@ class AbstractCasesTest extends TestCase // Incorrect canceled status $absCases->setCaseStatus('CANCELLED'); $actual = $absCases->getCaseStatus(); - $this->assertEquals($index, $actual); + $this->assertEquals(4, $actual); } /** diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/CasesTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/CasesTest.php index 4feeffe28..c479aaa36 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/CasesTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/CasesTest.php @@ -378,6 +378,6 @@ class CasesTest extends TestCase self::assertCount(1, Cases::dynaFormsByApplication($application->APP_UID, $task2->TAS_UID, '', 'TO_DO')); // Get DynaForms assigned as steps for the second task when the application status is COMPLETED - self::assertCount(2, Cases::dynaFormsByApplication($application->APP_UID, $task2->TAS_UID, '', 'COMPLETED')); + self::assertCount(1, Cases::dynaFormsByApplication($application->APP_UID, $task2->TAS_UID, '', 'COMPLETED')); } } diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/AppThreadTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/AppThreadTest.php new file mode 100644 index 000000000..b683fb3c3 --- /dev/null +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/AppThreadTest.php @@ -0,0 +1,64 @@ +create(); + $this->assertCount(1, $table->appUid($table->APP_UID)->get()); + } + + /** + * This test scopeIndex + * + * @covers \ProcessMaker\Model\AppThread::scopeIndex() + * @test + */ + public function it_return_scope_index() + { + $table = factory(AppThread::class)->create(); + $this->assertCount(1, $table->index($table->DEL_INDEX)->get()); + } + + /** + * This test getThread + * + * @covers \ProcessMaker\Model\AppThread::getThread() + * @covers \ProcessMaker\Model\AppThread::scopeAppUid() + * @covers \ProcessMaker\Model\AppThread::scopeIndex() + * @test + */ + public function it_return_thread() + { + $table = factory(AppThread::class)->create(); + $result = AppThread::getThread($table->APP_UID, $table->DEL_INDEX); + $this->assertNotEmpty($result); + } +} \ No newline at end of file diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/ApplicationTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/ApplicationTest.php index 97688a32b..ae47e2ffa 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/ApplicationTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/ApplicationTest.php @@ -87,6 +87,11 @@ class ApplicationTest extends TestCase { $table = factory(Application::class)->states('foreign_keys')->create(); $usrId = User::getId($table->APP_INIT_USER); + factory(Delegation::class)->states('foreign_keys')->create([ + 'APP_UID' => $table->APP_UID, + 'APP_NUMBER' => $table->APP_NUMBER, + 'USR_ID' => $usrId, + ]); $this->assertCount(1, $table->joinDelegation()->userId($usrId)->get()); } @@ -162,6 +167,20 @@ class ApplicationTest extends TestCase $this->assertCount(1, $table->rangeOfCases([$table->APP_NUMBER.'-'.$table->APP_NUMBER])->get()); } + /** + * This test scopeCasesOrRangeOfCases + * + * @covers \ProcessMaker\Model\Application::scopeCasesOrRangeOfCases() + * @test + */ + public function it_return_scope_cases_or_range_of_cases() + { + $table = factory(Application::class)->states('foreign_keys')->create(); + $cases = [$table->APP_NUMBER]; + $rangeCases = [$table->APP_NUMBER.'-'.$table->APP_NUMBER]; + $this->assertCount(1, $table->casesOrRangeOfCases($cases, $rangeCases)->get()); + } + /** * This test scopeCasesFrom * diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php index 0a8b58a1b..2c86e17ae 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php @@ -139,6 +139,29 @@ class DelegationTest extends TestCase $this->assertCount(1, $table->threadOpen()->get()); } + /** + * This test scopeThreadPause + * + * @covers \ProcessMaker\Model\Delegation::scopeThreadPause() + * @test + */ + public function it_return_scope_thread_pause() + { + $table = factory(Delegation::class)->states('foreign_keys')->create(); + $this->assertCount(0, $table->threadPause()->get()); + } + /** + * This test scopeOpenAndPause + * + * @covers \ProcessMaker\Model\Delegation::scopeOpenAndPause() + * @test + */ + public function it_return_scope_thread_open_and_pause() + { + $table = factory(Delegation::class)->states('foreign_keys')->create(); + $this->assertCount(1, $table->openAndPause()->get()); + } + /** * This test scopeCaseStarted * @@ -661,8 +684,11 @@ class DelegationTest extends TestCase */ public function it_return_scope_process_in_list() { - $table = factory(Delegation::class)->states('foreign_keys')->create(); - $this->assertCount(1, $table->processInList([$table->PRO_ID])->get()); + $process = factory(Process::class)->create(); + $table = factory(Delegation::class)->states('foreign_keys')->create([ + 'PRO_ID' => $process->PRO_ID + ]); + $this->assertCount(1, $table->joinProcess()->processInList([$table->PRO_ID])->get()); } /** @@ -677,6 +703,21 @@ class DelegationTest extends TestCase $this->assertCount(1, $table->participated($table->USR_ID)->get()); } + /** + * This test scopeCategoryId + * + * @covers \ProcessMaker\Model\Delegation::scopeCategoryId() + * @test + */ + public function it_return_scope_category() + { + $process = factory(Process::class)->create(); + $table = factory(Delegation::class)->states('foreign_keys')->create([ + 'PRO_ID' => $process->PRO_ID + ]); + $this->assertCount(1, $table->joinProcess()->categoryId($process->CATEGORY_ID)->get()); + } + /** * This test scopeJoinCategoryProcess * diff --git a/workflow/engine/classes/Cases.php b/workflow/engine/classes/Cases.php index 93c72e0f5..b811a5477 100644 --- a/workflow/engine/classes/Cases.php +++ b/workflow/engine/classes/Cases.php @@ -11,7 +11,10 @@ use ProcessMaker\Cases\CasesTrait; use ProcessMaker\ChangeLog\ChangeLog; /*----------------------------------********---------------------------------*/ use ProcessMaker\Core\System; +use ProcessMaker\Model\AppDelay as Delay; +use ProcessMaker\Model\AppThread as Thread; use ProcessMaker\Model\Delegation; +use ProcessMaker\Model\User; use ProcessMaker\Plugins\PluginRegistry; use ProcessMaker\Util\DateTime; @@ -1913,6 +1916,7 @@ class Cases $data = []; foreach ($rowObj as $appDel) { $appDel->setDelThreadStatus('CLOSED'); + $appDel->setDelThreadStatusId(Delegation::$thread_status['CLOSED']); $appDel->setDelFinishDate('now'); if ($appDel->Validate()) { $appDel->Save(); @@ -1952,11 +1956,13 @@ class Cases * * @param string $appUid * @param string $delIndex + * @param string $status + * @param int $statusId * * @return void * @throws Exception */ - public function CloseCurrentDelegation($appUid, $delIndex) + public function CloseCurrentDelegation($appUid, $delIndex, string $status = 'CLOSED', int $statusId = 0) { try { $criteria = new Criteria(); @@ -1965,7 +1971,8 @@ class Cases $rowObj = AppDelegationPeer::doSelect($criteria); $user = ''; foreach ($rowObj as $appDel) { - $appDel->setDelThreadStatus('CLOSED'); + $appDel->setDelThreadStatus($status); + $appDel->setDelThreadStatusId($statusId); $appDel->setDelFinishDate('now'); $user = $appDel->getUsrUid(); if ($appDel->Validate()) { @@ -1991,7 +1998,7 @@ class Cases $listParticipatedLast->refresh($data); /*----------------------------------********---------------------------------*/ - /** Update searchindex */ + /** Update search index */ if ($this->appSolr != null) { $this->appSolr->updateApplicationSearchIndex($appUid); } @@ -2019,6 +2026,7 @@ class Cases $rowObj = AppDelegationPeer::doSelect($c); foreach ($rowObj as $appDel) { $appDel->setDelThreadStatus('OPEN'); + $appDel->setDelThreadStatusId(Delegation::$thread_status['OPEN']); $appDel->setDelFinishDate(null); if ($appDel->Validate()) { $appDel->Save(); @@ -4097,77 +4105,75 @@ class Cases } /** - * pause a Case + * Pause a Case + * + * @param string $appUid + * @param int $index + * @param string $usrUid + * @param string $unpauseDate + * @param string $appTitle * - * @name pauseCase - * @param string $sApplicationUID - * @param string $iDelegation - * @param string $sUserUID - * @param string $sUnpauseDate * @return object */ - public function pauseCase($sApplicationUID, $iDelegation, $sUserUID, $sUnpauseDate = null, $appTitle = null) + public function pauseCase($appUid, $index, $usrUid, $unpauseDate = null, $appTitle = null) { - // Check if the case is unassigned - if ($this->isUnassignedPauseCase($sApplicationUID, $iDelegation)) { - throw new Exception(G::LoadTranslation("ID_CASE_NOT_PAUSED", array(G::LoadTranslation("ID_UNASSIGNED_STATUS")))); - } - - $oApplication = new Application(); - $aFields = $oApplication->Load($sApplicationUID); - //get the appthread row id ( APP_THREAD_INDEX' ) - $oCriteria = new Criteria('workflow'); - $oCriteria->clearSelectColumns(); - $oCriteria->addSelectColumn(AppThreadPeer::APP_THREAD_INDEX); - $oCriteria->add(AppThreadPeer::APP_UID, $sApplicationUID); - $oCriteria->add(AppThreadPeer::DEL_INDEX, $iDelegation); - $oDataset = AppThreadPeer::doSelectRS($oCriteria); - $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); - - if ($oDataset->next()) { - $aRow = $oDataset->getRow(); - } else { + $application = new Application(); + $fields = $application->Load($appUid); + $appNumber = $application->getAppNumber(); + // Get the index of appThread + $appThread = Thread::getThread($appUid, $index); + $appThread = head($appThread); + $threadIndex = $appThread['APP_THREAD_INDEX']; + if (empty($threadIndex)) { throw new Exception(G::LoadTranslation("ID_CASE_STOPPED_TRIGGER")); } + /** Close the index for pause */ + $this->CloseCurrentDelegation($appUid, $index, 'PAUSED', Delegation::$thread_status['PAUSED']); - $this->CloseCurrentDelegation($sApplicationUID, $iDelegation); - //now create a row in APP_DELAY with type PAUSE - $aData['PRO_UID'] = $aFields['PRO_UID']; - $aData['APP_UID'] = $sApplicationUID; - $aData['APP_THREAD_INDEX'] = $aRow['APP_THREAD_INDEX']; - $aData['APP_DEL_INDEX'] = $iDelegation; - $aData['APP_TYPE'] = 'PAUSE'; - $aData['APP_STATUS'] = $aFields['APP_STATUS']; - $aData['APP_DELEGATION_USER'] = $sUserUID; - $aData['APP_ENABLE_ACTION_USER'] = $sUserUID; - $aData['APP_ENABLE_ACTION_DATE'] = date('Y-m-d H:i:s'); - $aData['APP_DISABLE_ACTION_DATE'] = $sUnpauseDate; - $aData['APP_NUMBER'] = $oApplication->getAppNumber(); - $oAppDelay = new AppDelay(); - $oAppDelay->create($aData); + // Prepare the data for pause + $attributes = [ + 'APP_DELAY_UID' => G::generateUniqueID(), + 'PRO_UID' => $application->getProUid(), + 'PRO_ID' => $application->getProId(), + 'APP_UID' => $appUid, + 'APP_NUMBER' => $appNumber, + 'APP_THREAD_INDEX' => $threadIndex, + 'APP_DEL_INDEX' => $index, + 'APP_TYPE' => 'PAUSE', + 'APP_STATUS' => $application->getAppStatus(), + 'APP_DELEGATION_USER' => $usrUid, + 'APP_DELEGATION_USER_ID' => User::getId($usrUid), + 'APP_ENABLE_ACTION_USER' => $usrUid, + 'APP_ENABLE_ACTION_DATE' => date('Y-m-d H:i:s'), + 'APP_DISABLE_ACTION_DATE' => $unpauseDate, + ]; - $oApplication->update($aFields); + /** Register the pause case */ + Delay::create($attributes); - //update searchindex + /** Update the application case */ + $application->update($fields); + + /** Update search index */ if ($this->appSolr != null) { - $this->appSolr->updateApplicationSearchIndex($sApplicationUID); + $this->appSolr->updateApplicationSearchIndex($appUid); } - $this->getExecuteTriggerProcess($sApplicationUID, 'PAUSED'); + /** Execute the trigger */ + $this->getExecuteTriggerProcess($appUid, 'PAUSED'); /*----------------------------------********---------------------------------*/ - $threadTitle = Delegation::getDeltitle($aData['APP_NUMBER'], $aData['APP_DEL_INDEX']); - $data = array( - 'APP_UID' => $sApplicationUID, - 'DEL_INDEX' => $iDelegation, - 'USR_UID' => $sUserUID, - 'APP_RESTART_DATE' => $sUnpauseDate, + $threadTitle = Delegation::getDeltitle($appNumber, $index); + $data = [ + 'APP_UID' => $appUid, + 'DEL_INDEX' => $index, + 'USR_UID' => $usrUid, + 'APP_RESTART_DATE' => $unpauseDate, 'APP_TITLE' => $threadTitle, - ); - $data = array_merge($aFields, $data); - - $oListPaused = new ListPaused(); - $oListPaused->create($data); + ]; + $data = array_merge($fields, $data); + $listPaused = new ListPaused(); + $listPaused->create($data); /*----------------------------------********---------------------------------*/ } diff --git a/workflow/engine/classes/Derivation.php b/workflow/engine/classes/Derivation.php index 36b951015..32fa1342d 100644 --- a/workflow/engine/classes/Derivation.php +++ b/workflow/engine/classes/Derivation.php @@ -1482,6 +1482,7 @@ class Derivation // Update the DelThreadStatus, the thread is ready for continue $appDelegation = AppDelegationPeer::retrieveByPK($newCase['APPLICATION'], $newCase['INDEX']); $appDelegation->setDelThreadStatus('OPEN'); + $appDelegation->setDelThreadStatusId(Delegation::$thread_status['OPEN']); $appDelegation->save(); // Create record in table APP_ASSIGN_SELF_SERVICE_VALUE diff --git a/workflow/engine/classes/WorkspaceTools.php b/workflow/engine/classes/WorkspaceTools.php index eed6f091f..d4ac249c0 100644 --- a/workflow/engine/classes/WorkspaceTools.php +++ b/workflow/engine/classes/WorkspaceTools.php @@ -4147,6 +4147,22 @@ class WorkspaceTools WHERE AD.TAS_ID = 0"); $con->commit(); + // Populating APP_DELEGATION.DEL_THREAD_STATUS_ID with paused threads + CLI::logging("-> Populating APP_DELEGATION.DEL_THREAD_STATUS_ID \n"); + $con->begin(); + $stmt = $con->createStatement(); + $rs = $stmt->executeQuery("UPDATE APP_DELEGATION AS AD + INNER JOIN ( + SELECT APP_DELAY.APP_NUMBER, APP_DELAY.APP_DEL_INDEX + FROM APP_DELAY + WHERE APP_TYPE = 'PAUSE' AND APP_DELAY.APP_DISABLE_ACTION_USER = '0' + ) AS DELAY + ON (AD.APP_NUMBER = DELAY.APP_NUMBER AND AD.DEL_INDEX = DELAY.APP_DEL_INDEX) + SET AD.DEL_THREAD_STATUS_ID = 3, + AD.DEL_THREAD_STATUS = 'PAUSED' + WHERE AD.DEL_THREAD_STATUS_ID = 0"); + $con->commit(); + // Populating APPLICATION.APP_STATUS_ID CLI::logging("-> Populating APPLICATION.APP_STATUS_ID \n"); $con->begin(); diff --git a/workflow/engine/classes/model/AppDelegation.php b/workflow/engine/classes/model/AppDelegation.php index 2c3e89910..531066a6f 100644 --- a/workflow/engine/classes/model/AppDelegation.php +++ b/workflow/engine/classes/model/AppDelegation.php @@ -25,6 +25,7 @@ * */ +use ProcessMaker\Model\Delegation; use ProcessMaker\Plugins\PluginRegistry; /** @@ -195,6 +196,7 @@ class AppDelegation extends BaseAppDelegation $this->setDelPriority(($iPriority != '' ? $iPriority : '3')); $this->setDelThread($sAppThread); $this->setDelThreadStatus($theadStatus); + $this->setDelThreadStatusId(Delegation::$thread_status[$theadStatus]); $this->setDelDelegateDate('now'); $this->setAppNumber($appNumber); $this->setTasId($taskId); diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php index 949896e25..2d00d45b0 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php @@ -881,7 +881,7 @@ class Cases public function participation($usrUid, $caseNumber, $index) { $userId = User::getId($usrUid); - $query = Delegation::query()->select(['APP_NUMBER'])->case($caseNumber)->index($index)->isThreadOpen(); + $query = Delegation::query()->select(['APP_NUMBER'])->case($caseNumber)->index($index)->threadOpen(); $query1 = clone $query; $result = $query->userId($userId)->limit(1)->get()->values()->toArray(); $permission = empty($result) ? false : true; @@ -1048,6 +1048,11 @@ class Cases Validator::isDate($date, 'Y-m-d', '$unpaused_date'); } + // Check if the case is unassigned + if ($this->isUnassignedPauseCase($appUid, $index)) { + throw new Exception(G::LoadTranslation("ID_CASE_NOT_PAUSED", [G::LoadTranslation("ID_UNASSIGNED_STATUS")])); + } + /** Pause case */ $case->pauseCase($appUid, $index, $usrUid, $date . ' ' . $time); diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php index 3af2a865c..5886f9265 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php @@ -1262,6 +1262,9 @@ class AbstractCases implements CasesInterface if ($thread['APP_STATUS'] === 'DRAFT') { $status = 'DRAFT'; } + if (isset($thread['DEL_THREAD_STATUS']) && $thread['DEL_THREAD_STATUS'] === 'PAUSED') { + $status = 'PAUSED'; + } if ($thread['APP_STATUS'] === 'COMPLETED') { $finishDate = !empty($thread['APP_FINISH_DATE']) ? $thread['APP_FINISH_DATE'] : date("Y-m-d H:i:s"); $dateToCompare = $finishDate; diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Participated.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Participated.php index cd5130693..951f18cc1 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Participated.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Participated.php @@ -181,7 +181,7 @@ class Participated extends AbstractCases switch ($item['APP_STATUS']) { case 'TO_DO': // Get the pending task - $taskPending = Delegation::getPendingThreads($item['APP_NUMBER']); + $taskPending = Delegation::getPendingThreads($item['APP_NUMBER'], false); foreach ($taskPending as $thread) { $thread['APP_STATUS'] = $item['APP_STATUS']; // Get the thread information diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Supervising.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Supervising.php index 2119faabb..1f7c08c6a 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Supervising.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Supervising.php @@ -192,7 +192,7 @@ class Supervising extends AbstractCases // Only cases in to_do $query->caseTodo(); // Only open threads - $query->isThreadOpen(); + $query->threadOpen(); // For parallel threads the distinct by APP_NUMBER is important $query->distinct(); // Get the list of processes of the supervisor @@ -217,7 +217,7 @@ class Supervising extends AbstractCases // Only cases in to_do $query->caseTodo(); // Only open threads - $query->isThreadOpen(); + $query->threadOpen(); // For parallel threads the distinct by APP_NUMBER is important $query->distinct(); // Get the list of processes of the supervisor diff --git a/workflow/engine/src/ProcessMaker/Model/AppDelay.php b/workflow/engine/src/ProcessMaker/Model/AppDelay.php index bbe11e9e6..aaef99c09 100644 --- a/workflow/engine/src/ProcessMaker/Model/AppDelay.php +++ b/workflow/engine/src/ProcessMaker/Model/AppDelay.php @@ -8,4 +8,26 @@ class AppDelay extends Model { protected $table = 'APP_DELAY'; public $timestamps = false; + + /** + * The attributes that are mass assignable. + * + * @var array + */ + protected $fillable = [ + 'APP_DELAY_UID', + 'PRO_UID', + 'PRO_ID', + 'APP_UID', + 'APP_NUMBER', + 'APP_THREAD_INDEX', + 'APP_DEL_INDEX', + 'APP_TYPE', + 'APP_STATUS', + 'APP_DELEGATION_USER', + 'APP_DELEGATION_USER_ID'. + 'APP_ENABLE_ACTION_USER', + 'APP_ENABLE_ACTION_DATE', + 'APP_DISABLE_ACTION_DATE', + ]; } diff --git a/workflow/engine/src/ProcessMaker/Model/AppThread.php b/workflow/engine/src/ProcessMaker/Model/AppThread.php index 3610cecf2..5762ca151 100644 --- a/workflow/engine/src/ProcessMaker/Model/AppThread.php +++ b/workflow/engine/src/ProcessMaker/Model/AppThread.php @@ -9,4 +9,46 @@ class AppThread extends Model protected $table = 'APP_THREAD'; // We do not have create/update timestamps for this table public $timestamps = false; + + /** + * Scope a query to filter a specific case + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param string $appUid + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeAppUid($query, string $appUid) + { + return $query->where('APP_UID', $appUid); + } + + /** + * Scope a query to filter a specific index + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param int $index + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeIndex($query, int $index) + { + return $query->where('DEL_INDEX', $index); + } + + /** + * Get thread related to the specific case and index + * + * @param string $appUid + * @param int $index + * + * @return array + */ + public static function getThread(string $appUid, int $index) + { + $query = AppThread::query()->select(['APP_THREAD_INDEX']); + $query->appUid($appUid); + $query->index($index); + $results = $query->get()->toArray(); + + return $results; + } } \ No newline at end of file diff --git a/workflow/engine/src/ProcessMaker/Model/Application.php b/workflow/engine/src/ProcessMaker/Model/Application.php index 197742587..bf89d021e 100644 --- a/workflow/engine/src/ProcessMaker/Model/Application.php +++ b/workflow/engine/src/ProcessMaker/Model/Application.php @@ -374,7 +374,7 @@ class Application extends Model } /** - * Get information related to the created case + * Get information related to the case, avoiding to load the APP_DATA * * @param string $appUid * @@ -382,7 +382,13 @@ class Application extends Model */ public static function getCase($appUid) { - $query = Application::query()->select(['APP_STATUS', 'APP_INIT_USER']); + $query = Application::query()->select([ + 'APP_NUMBER', + 'APP_STATUS', + 'PRO_UID', + 'PRO_ID', + 'APP_INIT_USER' + ]); $query->appUid($appUid); $result = $query->get()->toArray(); $firstElement = head($result); diff --git a/workflow/engine/src/ProcessMaker/Model/Delegation.php b/workflow/engine/src/ProcessMaker/Model/Delegation.php index bbf2796b3..0b9a0cc15 100644 --- a/workflow/engine/src/ProcessMaker/Model/Delegation.php +++ b/workflow/engine/src/ProcessMaker/Model/Delegation.php @@ -24,6 +24,8 @@ class Delegation extends Model // Static properties to preserve values public static $usrUid = ''; public static $groups = []; + // Status name and status id + public static $thread_status = ['CLOSED' => 0, 'OPEN' => 1, 'PAUSED' => 3]; /** * Returns the application this delegation belongs to @@ -92,6 +94,34 @@ class Delegation extends Model return $query->where('APP_DELEGATION.DEL_THREAD_STATUS', '=', 'OPEN'); } + /** + * Scope a query to only include pause threads + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeThreadPause($query) + { + return $query->where('APP_DELEGATION.DEL_THREAD_STATUS_ID', '=', 3); + } + + /** + * Scope a query to only include open and pause threads + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeOpenAndPause($query) + { + $query->where(function ($query) { + $query->threadOpen(); + $query->orWhere(function ($query) { + $query->threadPause(); + }); + }); + return $query; + } + /** * Scope to use when the case is IN_PROGRESS like DRAFT or TO_DO * @@ -101,7 +131,7 @@ class Delegation extends Model */ public function scopeCasesInProgress($query, array $ids) { - $query->isThreadOpen()->statusIds($ids); + $query->threadOpen()->statusIds($ids); return $query; } @@ -546,17 +576,6 @@ class Delegation extends Model return $query->where('APP_DELEGATION.APP_UID', '=', $appUid); } - /** - * Scope a query to only include open threads - * - * @param \Illuminate\Database\Eloquent\Builder $query - * @return \Illuminate\Database\Eloquent\Builder - */ - public function scopeIsThreadOpen($query) - { - return $query->where('APP_DELEGATION.DEL_THREAD_STATUS', '=', 'OPEN'); - } - /** * Scope a query to get the last thread * @@ -755,6 +774,19 @@ class Delegation extends Model return $query->whereIn('APP_DELEGATION.PRO_ID', $processes); } + /** + * Scope where in processes + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param array $processes + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeInProcesses($query, array $processes) + { + return $query->whereIn('PROCESS.PRO_ID', $processes); + } + /** * Scope the Inbox cases * @@ -853,6 +885,33 @@ class Delegation extends Model return $query; } + /** + * Scope process category id + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param int $category + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeCategoryId($query, int $category) + { + return $query->where('PROCESS.CATEGORY_ID', $category); + } + + /** + * Scope top ten + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param string $column + * @param string $order + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeTopTen($query, $column, $order) + { + return $query->orderBy($column, $order)->limit(10); + } + /** * Scope join with delegation for get the previous index * @@ -1015,49 +1074,6 @@ class Delegation extends Model return $query; } - /** - * Scope process category id - * - * @param \Illuminate\Database\Eloquent\Builder $query - * @param int $category - * - * @return \Illuminate\Database\Eloquent\Builder - */ - public function scopeCategoryId($query, $category) - { - $query->where('PROCESS.CATEGORY_ID', $category); - return $query; - } - - /** - * Scope top ten - * - * @param \Illuminate\Database\Eloquent\Builder $query - * @param string $column - * @param string $order - * - * @return \Illuminate\Database\Eloquent\Builder - */ - public function scopeTopTen($query, $column, $order) - { - $query->orderBy($column, $order)->limit(10); - return $query; - } - - /** - * Scope where in processes - * - * @param \Illuminate\Database\Eloquent\Builder $query - * @param array $processes - * - * @return \Illuminate\Database\Eloquent\Builder - */ - public function scopeInProcesses($query, $processes) - { - $query->whereIn('PROCESS.PRO_ID', $processes); - return $query; - } - /** * Get specific cases unassigned that the user can view * @@ -1562,7 +1578,7 @@ class Delegation extends Model // Start the second query $query2 = Delegation::query()->select($selectedColumns); $query2->tasksIn($selfServiceTasks); - $query2->isThreadOpen(); + $query2->threadOpen(); $query2->noUserInThread(); // Add join clause with the previous APP_DELEGATION record if required @@ -1856,10 +1872,11 @@ class Delegation extends Model * Return the open thread related to the task * * @param int $appNumber + * @param bool $onlyOpen * * @return array */ - public static function getPendingThreads(int $appNumber) + public static function getPendingThreads(int $appNumber, $onlyOpen = true) { $query = Delegation::query()->select([ 'TASK.TAS_UID', @@ -1869,6 +1886,7 @@ class Delegation extends Model 'APP_DELEGATION.DEL_INDEX', 'APP_DELEGATION.DEL_TITLE', 'APP_DELEGATION.USR_ID', + 'APP_DELEGATION.DEL_THREAD_STATUS', 'APP_DELEGATION.DEL_DELEGATE_DATE', 'APP_DELEGATION.DEL_FINISH_DATE', 'APP_DELEGATION.DEL_INIT_DATE', @@ -1877,7 +1895,11 @@ class Delegation extends Model // Join with task $query->joinTask(); // Get the open threads - $query->threadOpen(); + if ($onlyOpen) { + $query->threadOpen(); + } else { + $query->openAndPause(); + } // Related to the specific case number $query->case($appNumber); // Get the results