diff --git a/database/factories/DelegationFactory.php b/database/factories/DelegationFactory.php index 29721a4df..5636e93f7 100644 --- a/database/factories/DelegationFactory.php +++ b/database/factories/DelegationFactory.php @@ -18,6 +18,7 @@ $factory->define(\ProcessMaker\Model\Delegation::class, function(Faker $faker) { return [ 'APP_UID' => $application->APP_UID, 'DEL_INDEX' => 1, + 'DELEGATION_ID' => $faker->unique()->randomNumber, 'APP_NUMBER' => $application->APP_NUMBER, 'DEL_PREVIOUS' => 0, 'PRO_UID' => $process->PRO_UID, @@ -31,10 +32,12 @@ $factory->define(\ProcessMaker\Model\Delegation::class, function(Faker $faker) { 'DEL_INIT_DATE' => $faker->dateTime(), 'DEL_TASK_DUE_DATE' => $faker->dateTime(), 'DEL_RISK_DATE' => $faker->dateTime(), + 'DEL_LAST_INDEX' => 0, 'USR_ID' => $user->USR_ID, 'PRO_ID' => $process->PRO_ID, 'TAS_ID' => $task->TAS_ID, - 'DEL_DATA' => '' + 'DEL_DATA' => '', + 'DEL_TITLE' => $faker->word() ]; }); @@ -77,7 +80,8 @@ $factory->state(\ProcessMaker\Model\Delegation::class, 'foreign_keys', function 'USR_ID' => $user->USR_ID, 'PRO_ID' => $process->PRO_ID, 'TAS_ID' => $task->TAS_ID, - 'DEL_DATA' => '' + 'DEL_DATA' => '', + 'DEL_TITLE' => $faker->word() ]; }); diff --git a/database/factories/ElementTaskRelationFactory.php b/database/factories/ElementTaskRelationFactory.php new file mode 100644 index 000000000..67a53f9b7 --- /dev/null +++ b/database/factories/ElementTaskRelationFactory.php @@ -0,0 +1,13 @@ +define(\ProcessMaker\Model\ElementTaskRelation::class, function(Faker $faker) { + return [ + 'ETR_UID' => G::generateUniqueID(), + 'PRJ_UID' => G::generateUniqueID(), + 'ELEMENT_UID' => G::generateUniqueID(), + 'ELEMENT_TYPE' => 'bpmnEvent', + 'TAS_UID' => G::generateUniqueID(), + ]; +}); diff --git a/database/factories/TaskFactory.php b/database/factories/TaskFactory.php index d585bd3b9..25584e9a9 100644 --- a/database/factories/TaskFactory.php +++ b/database/factories/TaskFactory.php @@ -16,6 +16,7 @@ $factory->define(\ProcessMaker\Model\Task::class, function(Faker $faker) { 'TAS_TYPE_DAY' => 1, 'TAS_DURATION' => 1, 'TAS_ASSIGN_TYPE' => 'BALANCED', + 'TAS_DEF_TITLE' => $faker->sentence(2), 'TAS_ASSIGN_VARIABLE' => '@@SYS_NEXT_USER_TO_BE_ASSIGNED', 'TAS_MI_INSTANCE_VARIABLE' => '@@SYS_VAR_TOTAL_INSTANCE', 'TAS_MI_COMPLETE_VARIABLE' => '@@SYS_VAR_TOTAL_INSTANCES_COMPLETE', @@ -45,6 +46,7 @@ $factory->state(\ProcessMaker\Model\Task::class, 'foreign_keys', function (Faker 'TAS_TYPE_DAY' => 1, 'TAS_DURATION' => 1, 'TAS_ASSIGN_TYPE' => 'BALANCED', + 'TAS_DEF_TITLE' => $faker->sentence(2), 'TAS_ASSIGN_VARIABLE' => '@@SYS_NEXT_USER_TO_BE_ASSIGNED', 'TAS_MI_INSTANCE_VARIABLE' => '@@SYS_VAR_TOTAL_INSTANCE', 'TAS_MI_COMPLETE_VARIABLE' => '@@SYS_VAR_TOTAL_INSTANCES_COMPLETE', diff --git a/tests/unit/workflow/engine/classes/DerivationTest.php b/tests/unit/workflow/engine/classes/DerivationTest.php index 17fe95730..2a24c49b8 100644 --- a/tests/unit/workflow/engine/classes/DerivationTest.php +++ b/tests/unit/workflow/engine/classes/DerivationTest.php @@ -144,6 +144,7 @@ class DerivationTest extends TestCase ]; $appFields = [ 'APP_NUMBER' => $application->APP_NUMBER, + 'DEL_INDEX' => $appDelegation->DEL_INDEX, 'DEL_THREAD' => $appDelegation->DEL_THREAD, 'PRO_UID' => $process->PRO_UID, 'PRO_ID' => $process->PRO_ID, diff --git a/tests/unit/workflow/engine/classes/WorkspaceToolsTest.php b/tests/unit/workflow/engine/classes/WorkspaceToolsTest.php new file mode 100644 index 000000000..0b1d9d75a --- /dev/null +++ b/tests/unit/workflow/engine/classes/WorkspaceToolsTest.php @@ -0,0 +1,84 @@ +create([ + 'APP_STATUS' => 'TO_DO', + 'APP_STATUS_ID' => 2, + ]); + $application2 = factory(Application::class)->create([ + 'APP_STATUS' => 'COMPLETED', + 'APP_STATUS_ID' => 3, + ]); + $application3 = factory(Application::class)->create([ + 'APP_STATUS' => 'CANCELED', + 'APP_STATUS_ID' => 4, + ]); + + factory(Delegation::class)->create([ + 'APP_UID' => $application1->APP_UID, + 'APP_NUMBER' => $application1->APP_NUMBER, + 'DEL_INDEX' => 1 + ]); + factory(Delegation::class)->create([ + 'APP_UID' => $application1->APP_UID, + 'APP_NUMBER' => $application1->APP_NUMBER, + 'DEL_INDEX' => 2 + ]); + $delegation1 = factory(Delegation::class)->create([ + 'APP_UID' => $application1->APP_UID, + 'APP_NUMBER' => $application1->APP_NUMBER, + 'DEL_INDEX' => 3, + ]); + + factory(Delegation::class)->create([ + 'APP_UID' => $application2->APP_UID, + 'APP_NUMBER' => $application2->APP_NUMBER, + 'DEL_INDEX' => 1 + ]); + $delegation2 = factory(Delegation::class)->create([ + 'APP_UID' => $application2->APP_UID, + 'APP_NUMBER' => $application2->APP_NUMBER, + 'DEL_INDEX' => 2, + 'DEL_LAST_INDEX' => 1 + ]); + + factory(Delegation::class)->create([ + 'APP_UID' => $application3->APP_UID, + 'APP_NUMBER' => $application3->APP_NUMBER, + 'DEL_INDEX' => 1 + ]); + $delegation3 = factory(Delegation::class)->create([ + 'APP_UID' => $application3->APP_UID, + 'APP_NUMBER' => $application3->APP_NUMBER, + 'DEL_INDEX' => 2, + 'DEL_LAST_INDEX' => 1 + ]); + + $workspaceTools = new WorkspaceTools(''); + $workspaceTools->migrateCaseTitleToThreads(['testexternal']); + $result = ob_get_contents(); + $this->assertRegExp("/The Case Title has been updated successfully in APP_DELEGATION table./", $result); + + $r = Delegation::select('DEL_TITLE')->where('DELEGATION_ID', $delegation1->DELEGATION_ID)->get()->values()->toArray(); + $this->assertEquals($r[0]['DEL_TITLE'], $application1->APP_TITLE); + + $r = Delegation::select('DEL_TITLE')->where('DELEGATION_ID', $delegation2->DELEGATION_ID)->get()->values()->toArray(); + $this->assertEquals($r[0]['DEL_TITLE'], $application2->APP_TITLE); + + $r = Delegation::select('DEL_TITLE')->where('DELEGATION_ID', $delegation3->DELEGATION_ID)->get()->values()->toArray(); + $this->assertEquals($r[0]['DEL_TITLE'], $application3->APP_TITLE); + } +} diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Cases/CasesTraitTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Cases/CasesTraitTest.php index e1fbb3d90..4f27c3fd8 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Cases/CasesTraitTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Cases/CasesTraitTest.php @@ -196,7 +196,7 @@ class CasesTraitTest extends TestCase $task2 = $result->task2; $processUid = $application->PRO_UID; - $application = $application->APP_UID; + $appUid = $application->APP_UID; $postForm = [ 'ROU_TYPE' => 'SEQUENTIAL', 'TASKS' => [ @@ -229,9 +229,9 @@ class CasesTraitTest extends TestCase $userLogged = $user->USR_UID; $cases = new Cases(); - $cases->routeCase($processUid, $application, $postForm, $status, $flagGmail, $tasUid, $index, $userLogged); + $cases->routeCase($processUid, $appUid, $postForm, $status, $flagGmail, $tasUid, $index, $userLogged); - $result = Delegation::where('APP_UID', '=', $application)->where('DEL_INDEX', '=', $index)->get()->first(); + $result = Delegation::where('APP_UID', '=', $appUid)->where('DEL_INDEX', '=', $index)->get()->first(); $this->assertEquals('CLOSED', $result->DEL_THREAD_STATUS); } diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php index 5adb15588..722f237db 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php @@ -415,8 +415,7 @@ class DelegationTest extends TestCase ->states('foreign_keys') ->create(); $title = $delegations->last() - ->application - ->APP_TITLE; + ->DEL_TITLE; // We need to commit the records inserted because is needed for the "fulltext" index DB::commit(); @@ -2510,4 +2509,33 @@ class DelegationTest extends TestCase $result = Delegation::participation($application->APP_UID, $user->USR_UID); $this->assertFalse($result); } + + /** + * This check the return of thread title + * + * @covers \ProcessMaker\Model\Delegation::getThreadTitle() + * @test + */ + public function it_get_thread_title() + { + $delegation = factory(Delegation::class)->states('foreign_keys')->create(); + $result = Delegation::getThreadTitle($delegation->TAS_UID, $delegation->APP_NUMBER, $delegation->DEL_INDEX, []); + $this->assertNotEmpty($result); + } + + /** + * This tests the getDeltitle() method + * + * @covers \ProcessMaker\Model\Delegation::getDeltitle() + * @test + */ + public function it_should_test_the_get_del_title_method() + { + $delegation = factory(Delegation::class)->create([ + 'DEL_TITLE' => "test" + ]); + $result = Delegation::getDeltitle($delegation->APP_NUMBER, $delegation->DEL_INDEX); + $this->assertNotEmpty($result); + $this->assertEquals($result, $delegation->DEL_TITLE); + } } \ No newline at end of file diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/TaskTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/TaskTest.php index 49241b89a..871c60ce4 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/TaskTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/TaskTest.php @@ -5,6 +5,8 @@ namespace Tests\unit\workflow\engine\src\ProcessMaker\Model; use G; use Illuminate\Foundation\Testing\DatabaseTransactions; use ProcessMaker\Model\Delegation; +use ProcessMaker\Model\ElementTaskRelation; +use ProcessMaker\Model\Process; use ProcessMaker\Model\Task; use Tests\TestCase; @@ -124,4 +126,64 @@ class TaskTest extends TestCase $result .= ' 01 '. G::LoadTranslation('ID_SECOND_ABBREVIATE'); $this->assertEquals($taskInfo['DURATION'], $result); } + + /** + * It tests the setTaskDefTitle() method + * + * @covers \ProcessMaker\Model\Task::setTaskDefTitle() + * @test + */ + public function it_should_test_set_task_title_method() + { + $project = factory(Process::class)->create(); + $task = factory(Task::class)->create([ + 'TAS_DEF_TITLE' => 'something' + ]); + $elementTask = factory(ElementTaskRelation::class)->create([ + 'PRJ_UID' => $project->PRO_UID, + 'TAS_UID' => $task->TAS_UID, + ]); + + Task::setTaskDefTitle($elementTask->ELEMENT_UID, "Task title new"); + $query = Task::query(); + $query->select()->where('TASK.TAS_UID', $task->TAS_UID); + $res = $query->get()->values()->toArray(); + $this->assertEquals($res[0]['TAS_DEF_TITLE'], 'Task title new'); + } + + /** + * It tests the getTaskDefTitle() method + * + * @covers \ProcessMaker\Model\Task::getTaskDefTitle() + * @test + */ + public function it_should_test_get_task_def_title_method() + { + $project = factory(Process::class)->create(); + $task = factory(Task::class)->create([ + 'TAS_DEF_TITLE' => 'something' + ]); + $elementTask = factory(ElementTaskRelation::class)->create([ + 'PRJ_UID' => $project->PRO_UID, + 'TAS_UID' => $task->TAS_UID, + ]); + + $res = Task::getTaskDefTitle($elementTask->ELEMENT_UID); + + $this->assertEquals($res, $task->TAS_DEF_TITLE); + } + + /** + * It tests the get case title defined in the task + * + * @covers \ProcessMaker\Model\Task::taskCaseTitle() + * @test + */ + public function it_get_case_title() + { + $task = factory(Task::class)->create(); + $tas = new Task(); + $result = $tas->taskCaseTitle($task->TAS_UID); + $this->assertNotEmpty($result); + } } \ No newline at end of file diff --git a/workflow/engine/bin/tasks/cliWorkspaces.php b/workflow/engine/bin/tasks/cliWorkspaces.php index 35a2380a2..7fd9c9d63 100644 --- a/workflow/engine/bin/tasks/cliWorkspaces.php +++ b/workflow/engine/bin/tasks/cliWorkspaces.php @@ -2,6 +2,7 @@ use ProcessMaker\BusinessModel\WebEntry; use ProcessMaker\Core\JobsManager; +use ProcessMaker\Model\Delegation; use ProcessMaker\Model\Process; use ProcessMaker\Validation\MySQL57; @@ -450,6 +451,19 @@ EOT ); CLI::taskRun('convert_old_web_entries'); +/** + * Populate the column APP_DELEGATION.DEL_TITLE with the case title APPLICATION.APP_TITLE + */ +CLI::taskName('migrate-case-title-to-threads'); +CLI::taskDescription(<<getMessage() . PHP_EOL . PHP_EOL); } } + +/** + * Populate the new column APPLICATION.APP_TITLE into the APP_DELEGATION table + * + * @param array $args + */ +function migrate_case_title_to_threads($args) +{ + //The constructor requires an argument, so we send an empty value in order to use the class. + $workspaceTools = new WorkspaceTools(''); + $workspaceTools->migrateCaseTitleToThreads($args); +} diff --git a/workflow/engine/classes/Cases.php b/workflow/engine/classes/Cases.php index 4795ee6bc..7ab3b4aad 100644 --- a/workflow/engine/classes/Cases.php +++ b/workflow/engine/classes/Cases.php @@ -10,6 +10,7 @@ use ProcessMaker\Cases\CasesTrait; use ProcessMaker\ChangeLog\ChangeLog; /*----------------------------------********---------------------------------*/ use ProcessMaker\Core\System; +use ProcessMaker\Model\Delegation; use ProcessMaker\Plugins\PluginRegistry; use ProcessMaker\Util\DateTime; @@ -25,6 +26,7 @@ class Cases public $dir = 'ASC'; public $sort = 'APP_MSG_DATE'; public $arrayTriggerExecutionTime = []; + public $caseTitle = ''; private $triggerMessageExecution = ''; public function __construct() @@ -34,6 +36,27 @@ class Cases $this->appSolr = new AppSolr($solrConf['solr_enabled'], $solrConf['solr_host'], $solrConf['solr_instance']); } } + /** + * Get the caseTitle + * + * @return string + */ + public function getCaseTitle() + { + return $this->caseTitle; + } + + /** + * Set the caseTitle + * + * @param string $v + * + * @return void + */ + public function setCaseTitle(string $v) + { + $this->caseTitle = $v; + } /** * Get the triggerMessageExecution @@ -609,168 +632,36 @@ class Cases } /** - * This function loads the label case - * PROCESO: - * If there is a label then it is loaded - * To get APP_DELEGATIONS that they are opened in the case - * To look for APP_DELEGATIONS wich TASK in it, It has a label defined(CASE_TITLE) - * We need to read the last APP_DELEGATION->TASK - * @param string $sAppUid - * @param string $aAppData - * @param string $sLabel - * @return $appLabel - */ - public function refreshCaseLabel($sAppUid, $aAppData, $sLabel) - { - $getAppLabel = "getApp$sLabel"; - $getTasDef = "getTasDef$sLabel"; - $oApplication = new Application; - if (!$oApplication->exists($sAppUid)) { - return null; - } else { - $oApplication->load($sAppUid); - $appLabel = $oApplication->$getAppLabel(); - } - $cri = new Criteria; - $cri->add(AppDelegationPeer::APP_UID, $sAppUid); - $cri->add(AppDelegationPeer::DEL_THREAD_STATUS, "OPEN"); - $currentDelegations = AppDelegationPeer::doSelect($cri); - for ($r = count($currentDelegations) - 1; $r >= 0; $r--) { - $task = TaskPeer::retrieveByPk($currentDelegations[$r]->getTasUid()); - $caseLabel = $task->$getTasDef(); - if ($caseLabel != '') { - $appLabel = G::replaceDataField($caseLabel, $aAppData, 'mysql', false); - break; - } - } - return $appLabel; - } - - /** - * Optimized for speed. This function loads the title and description label in a case - * If there is a label then it is loaded - * Get Open APP_DELEGATIONS in the case - * To look for APP_DELEGATIONS which TASK in it, It has a label defined(CASE_TITLE) - * We need to read the last APP_DELEGATION->TASK + * Update the thread title * * @param string $appUid - * @param array $fields - * @param array $lastFieldsCase + * @param int $appNumber + * @param int $delIndex + * @param array $caseData * - * @return array + * @return void * - * @see classes/Cases->startCase() - * @see classes/Cases->updateCase() + * @see Cases::updateCase() */ - public function newRefreshCaseTitleAndDescription($appUid, $fields, $lastFieldsCase = []) + public function updateThreadTitle(string $appUid, int $appNumber, int $delIndex, $caseData = []) { - $res = []; - - $flagTitle = false; - $flagDescription = false; - - $cri = new Criteria; - $cri->clearSelectColumns(); - $cri->addSelectColumn(AppDelegationPeer::TAS_UID); - $cri->add(AppDelegationPeer::APP_UID, $appUid); - $cri->add(AppDelegationPeer::DEL_THREAD_STATUS, "OPEN"); - if (isset($fields['DEL_INDEX'])) { - $cri->add(AppDelegationPeer::DEL_INDEX, $fields['DEL_INDEX']); - } - $rsCri = AppDelegationPeer::doSelectRS($cri); - $rsCri->setFetchmode(ResultSet::FETCHMODE_ASSOC); - $rsCri->next(); - $rowCri = $rsCri->getRow(); - - //load only the tas_def fields, because these three or two values are needed - while (is_array($rowCri)) { - $c = new Criteria(); - $c->clearSelectColumns(); - $c->addSelectColumn(TaskPeer::TAS_DEF_TITLE); - $c->addSelectColumn(TaskPeer::TAS_DEF_DESCRIPTION); - $c->add(TaskPeer::TAS_UID, $rowCri['TAS_UID']); - $rs = TaskPeer::doSelectRS($c); - $rs->setFetchmode(ResultSet::FETCHMODE_ASSOC); - while ($rs->next()) { - $row = $rs->getRow(); - $newValues = []; - //Get the case title - $tasDefTitle = trim($row['TAS_DEF_TITLE']); - if (!empty($tasDefTitle) && !$flagTitle) { - $newAppProperty = G::replaceDataField($tasDefTitle, $lastFieldsCase, 'mysql', false); - $res['APP_TITLE'] = $newAppProperty; - if (!(isset($currentValue) && ($currentValue == $tasDefTitle))) { - $newValues['APP_TITLE'] = $newAppProperty; - $flagTitle = true; - } - } - //Get the case description - $tasDefDescription = trim($row['TAS_DEF_DESCRIPTION']); - if (!empty($tasDefDescription) && !$flagDescription) { - $newAppProperty = G::replaceDataField($tasDefDescription, $lastFieldsCase, 'mysql', false); - $res['APP_DESCRIPTION'] = $newAppProperty; - if (!(isset($currentValue) && ($currentValue == $tasDefDescription))) { - $newValues['APP_DESCRIPTION'] = $newAppProperty; - $flagDescription = true; - } - } - - if (!empty($newValues)) { - $application = new Application(); - $newValues['APP_UID'] = $appUid; - $application->update($newValues); - } + $threadTitle = $this->getCaseTitle(); + if (empty($threadTitle) && !empty($appNumber) && !empty($delIndex)) { + $thread = Delegation::getThreadInfo($appNumber, $delIndex); + $previous = $thread['DEL_PREVIOUS']; + $appNumber = $thread['APP_NUMBER']; + $tasUid = $thread['TAS_UID']; + if (!empty($tasUid)) { + $threadTitle = Delegation::getThreadTitle($tasUid, $appNumber, $previous, $caseData); } - $rsCri->next(); - $rowCri = $rsCri->getRow(); } - - return $res; - } - - /** - * Small function, it uses to return the title from a case - * - * - * @name refreshCaseTitle - * @param string $sAppUid - * @param array $aAppData - * @access public - * @return $appLabel - */ - public function refreshCaseTitle($sAppUid, $aAppData) - { - return $this->refreshCaseLabel($sAppUid, $aAppData, "Title"); - } - - /** - * Small function, it uses to return the description from a case - * - * - * @name refreshCaseDescription - * @param string $sAppUid - * @param array $aAppData - * @access public - * @return $appLabel - */ - public function refreshCaseDescription($sAppUid, $aAppData) - { - return $this->refreshCaseLabel($sAppUid, $aAppData, "Description"); - } - - /** - * Small function, it uses to return the code process from a case - * - * - * @name refreshCaseDescription - * @param string $sAppUid - * @param array $aAppData - * @access public - * @return $appLabel - */ - public function refreshCaseStatusCode($sAppUid, $aAppData) - { - return $this->refreshCaseLabel($sAppUid, $aAppData, "ProcCode"); + // Update thread title + $rows = []; + $rows['APP_UID'] = $appUid; + $rows['DEL_INDEX'] = $delIndex; + $rows['DEL_TITLE'] = $threadTitle; + $delegation = new AppDelegation(); + $delegation->update($rows); } /** @@ -906,12 +797,10 @@ class Cases $appFields['DEL_INDEX'] = $Fields['DEL_INDEX']; } - //Get the appTitle and appDescription - $newTitleOrDescription = $this->newRefreshCaseTitleAndDescription( - $appUid, - $appFields, - $appData - ); + // Update case title + if (!empty($appUid) && !empty($appFields['APP_NUMBER']) && !empty($appFields['DEL_INDEX'])) { + $this->updateThreadTitle($appUid, $appFields['APP_NUMBER'], $appFields['DEL_INDEX'], $appFields['APP_DATA']); + } //Start: Save History --By JHL if (isset($Fields['CURRENT_DYNAFORM'])) { @@ -1027,7 +916,7 @@ class Cases $inbox = new ListInbox(); unset($Fields['DEL_INIT_DATE']); unset($Fields['DEL_DELEGATE_DATE']); - $inbox->update(array_merge($Fields, $newTitleOrDescription)); + $inbox->update($Fields); /*----------------------------------********---------------------------------*/ //Return @@ -1708,14 +1597,13 @@ class Cases * This function creates a new row into APP_DELEGATION * * @name newAppDelegation - * @param string $sProUid, - * @param string $sAppUid, - * @param string $sTasUid, - * @param string $sUsrUid - * @param string $sPrevious - * @param string $iPriority - * @param string $sDelType - * @param string $iAppThreadIndex + * @param string $proUid + * @param string $appUid + * @param string $tasUid + * @param string $usrUid + * @param string $previous + * @param string $priority + * @param int $threadIndex * @param string $nextDel * @param boolean $flagControl * @param boolean $flagControlMulInstance @@ -1723,22 +1611,55 @@ class Cases * @param int $appNumber * @param int $proId * @param int $tasId - * @return void + * @param array $caseData + * + * @see Cases::reassignCase() + * @see Cases::startCase() + * @see Cases::unpauseCase() + * @see Cases::unCancelCase() + * @see Derivation::doDerivation() + * @see Derivation::doDerivationStaticMi() + * + * @return int + * @throw Exception */ - public function newAppDelegation($sProUid, $sAppUid, $sTasUid, $sUsrUid, $sPrevious, $iPriority, $sDelType, $iAppThreadIndex = 1, $nextDel = null, $flagControl = false, $flagControlMulInstance = false, $delPrevious = 0, $appNumber = 0, $proId = 0, $tasId = 0) - { + public function newAppDelegation( + $proUid, + $appUid, + $tasUid, + $usrUid, + $previous, + $priority, + $threadIndex = 1, + $nextDel = null, + $flagControl = false, + $flagControlMulInstance = false, + $delPrevious = 0, + $appNumber = 0, + $proId = 0, + $tasId = 0, + $caseData = [] + ){ try { - $user = UsersPeer::retrieveByPK($sUsrUid); - $appDel = new AppDelegation(); - $result = $appDel->createAppDelegation( - $sProUid, - $sAppUid, - $sTasUid, - $sUsrUid, - $iAppThreadIndex, - $iPriority, + // Get case title + $threadTitle = $this->getCaseTitle(); + if (empty($threadTitle)) { + $threadTitle = Delegation::getThreadTitle($tasUid, $appNumber, $previous, $caseData); + } + + $user = UsersPeer::retrieveByPK($usrUid); + // Create new delegation + $delegation = new AppDelegation(); + $delegation->setDelTitle($threadTitle); + $result = $delegation->createAppDelegation( + $proUid, + $appUid, + $tasUid, + $usrUid, + $threadIndex, + $priority, false, - $sPrevious, + $previous, $nextDel, $flagControl, $flagControlMulInstance, @@ -1748,12 +1669,12 @@ class Cases (empty($user)) ? 0 : $user->getUsrId(), $proId ); - //update searchindex + // Update search index if ($this->appSolr != null) { - $this->appSolr->updateApplicationSearchIndex($sAppUid); + $this->appSolr->updateApplicationSearchIndex($appUid); } return $result; - } catch (exception $e) { + } catch (Exception $e) { throw ($e); } } @@ -2105,185 +2026,175 @@ class Cases } /** - * This function start a case using the task for the user $sUsrUid + * This function start a case using the task for the user $usrUid * With this function we can Start a case * - * @param string $taskUid - * @param string $userUid - * @param bool $isSubProcess - * @param array $dataPreviousApplication + * @name startCase + * @param string $tasUid + * @param string $usrUid + * @param bool $isSubprocess + * @param array $previousInfo * @param bool $isSelfService - * @param string $sequenceType - * @return array - * @throws Exception + * @param string $sequenceType + * + * @return Fields + * @throw Exception */ - public function startCase($taskUid, $userUid, $isSubProcess = false, $dataPreviousApplication = [], $isSelfService = false, $sequenceType = AppSequence::APP_TYPE_NORMAL) + public function startCase(string $tasUid, string $usrUid, $isSubprocess = false, $previousInfo = [], $isSelfService = false, $sequenceType = AppSequence::APP_TYPE_NORMAL) { - if ($taskUid != '') { + if (!empty($tasUid)) { try { - $task = TaskPeer::retrieveByPK($taskUid); - $user = UsersPeer::retrieveByPK($userUid); - + $task = TaskPeer::retrieveByPK($tasUid); + $user = UsersPeer::retrieveByPK($usrUid); if (is_null($task)) { - throw new Exception(G::LoadTranslation("ID_TASK_NOT_EXIST", ["TAS_UID", $taskUid])); + throw new Exception(G::LoadTranslation("ID_TASK_NOT_EXIST", ["TAS_UID", $tasUid])); } // To allow Self Service as the first task - $arrayTaskTypeToExclude = ["START-TIMER-EVENT"]; - - if (!is_null($task) && !in_array($task->getTasType(), $arrayTaskTypeToExclude) && $task->getTasAssignType() != "SELF_SERVICE" && $userUid == "") { + $tasksTypeToExclude = ["START-TIMER-EVENT"]; + if (!is_null($task) && !in_array($task->getTasType(), $tasksTypeToExclude) && $task->getTasAssignType() != "SELF_SERVICE" && $usrUid == "") { throw (new Exception('You tried to start a new case without send the USER UID!')); } - // Process - $processUid = $task->getProUid(); + // Load Process + $proUid = $task->getProUid(); $this->Process = new Process; - $proFields = $this->Process->Load($processUid); + $proFields = $this->Process->Load($proUid); - // Application + // Create application $application = new Application; - $appUid = $application->create($processUid, $userUid, $sequenceType); + $appUid = $application->create($proUid, $usrUid, $sequenceType); + $fields = $application->toArray(BasePeer::TYPE_FIELDNAME); - // AppDelegation - $appDelegation = new AppDelegation; - $appThreadIndex = 1; // Start Thread - $appDelPriority = 3; // Priority - $delIndex = $appDelegation->createAppDelegation( - $processUid, + // Create appDelegation + $delIndex = $this->newAppDelegation( + $proUid, $appUid, - $taskUid, - $userUid, - $appThreadIndex, - $appDelPriority, - $isSubProcess, - -1, - null, - false, - false, - 0, + $tasUid, + $usrUid, + -1, // previous + 3, // Priority + 1, // Start Thread + null, // Next delegation + false, // Flag control + false, // Flag control multi-instance + 0, // Thread previous $application->getAppNumber(), + $this->Process->getProId(), $task->getTasId(), - (empty($user)) ? 0 : $user->getUsrId(), - $this->Process->getProId() - + $fields['APP_DATA'] ); - // AppThread - $appThread = new AppThread; - $appThreadIndex = $appThread->createAppThread($appUid, $delIndex, 0); - - $derivation = new Derivation(); + // Instance appThread + $thread = new AppThread; + $threadIndex = $thread->createAppThread($appUid, $delIndex, 0); + // Instance Derivation + $routing = new Derivation(); // Multiple Instance - $usersFields = []; + $userFields = []; $taskAssignType = $task->getTasAssignType(); - $nextTaskAssignVariable = $task->getTasAssignVariable(); if ($taskAssignType == "MULTIPLE_INSTANCE" || $taskAssignType == "MULTIPLE_INSTANCE_VALUE_BASED") { switch ($taskAssignType) { case 'MULTIPLE_INSTANCE': - $userFields = $derivation->getUsersFullNameFromArray($derivation->getAllUsersFromAnyTask($taskUid)); + $userFields = $routing->getUsersFullNameFromArray($routing->getAllUsersFromAnyTask($tasUid)); break; default: throw (new Exception('Invalid Task Assignment method')); break; } - $userFields = $derivation->getUsersFullNameFromArray($derivation->getAllUsersFromAnyTask($taskUid)); + $userFields = $routing->getUsersFullNameFromArray($routing->getAllUsersFromAnyTask($tasUid)); $count = 0; foreach ($userFields as $rowUser) { - if ($rowUser["USR_UID"] != $userUid) { - // AppDelegation - $appDelegation = new AppDelegation; - $appThreadIndex ++; // Start Thread - $appDelPriority = 3; // Priority + if ($rowUser["USR_UID"] != $usrUid) { + // Create appDelegation + $delegation = new AppDelegation; + $threadIndex ++; // Start Thread + $priority = 3; // Priority $user = UsersPeer::retrieveByPK($rowUser["USR_UID"]); - $delIndex1 = $appDelegation->createAppDelegation( - $processUid, + // Create a new delegation + $delIndex1 = $this->newAppDelegation( + $proUid, $appUid, - $taskUid, + $tasUid, $rowUser["USR_UID"], - $appThreadIndex, - $appDelPriority, - $isSubProcess, - -1, - null, - false, - false, - 0, + -1, // previous + $priority, // Priority + $threadIndex, // Start Thread + null, // Next delegation + false, // Flag control + false, // Flag control multi-instance + 0, // Thread previous $application->getAppNumber(), + $this->Process->getProId(), $task->getTasId(), - (empty($user)) ? 0 : $user->getUsrId(), - $this->Process->getProId() + $fields['APP_DATA'] ); - // AppThread - $appThread = new AppThread; - $appThreadIndex = $appThread->createAppThread($appUid, $delIndex1, 0); + // Create appThread + $thread = new AppThread; + $threadIndex = $thread->createAppThread($appUid, $delIndex1, 0); // Save Information - $usersFields[$count] = $rowUser; - $usersFields[$count]["DEL_INDEX"] = $delIndex1; + $userFields[$count] = $rowUser; + $userFields[$count]["DEL_INDEX"] = $delIndex1; $count++; } } } + // Update the application $fields = $application->toArray(BasePeer::TYPE_FIELDNAME); - $applicationFields = $fields['APP_DATA']; $fields['DEL_INDEX'] = $delIndex; - $newValues = $this->newRefreshCaseTitleAndDescription($appUid, $fields, $applicationFields); - if (!isset($newValues['APP_TITLE'])) { - $newValues['APP_TITLE'] = ''; - } - - $caseNumber = $fields['APP_NUMBER']; $application->update($fields); - + // Get current case number + $caseNumber = $fields['APP_NUMBER']; // Update the task last assigned (for web entry and web services) - $derivation->setTasLastAssigned($taskUid, $userUid); + $routing->setTasLastAssigned($tasUid, $usrUid); // Execute Events $event = new Event(); - $event->createAppEvents($processUid, $appUid, $delIndex, $taskUid); + $event->createAppEvents($proUid, $appUid, $delIndex, $tasUid); - // Update search index + // Update solr if ($this->appSolr != null) { $this->appSolr->updateApplicationSearchIndex($appUid); } /*----------------------------------********---------------------------------*/ - $fields['TAS_UID'] = $taskUid; - $fields['USR_UID'] = $userUid; + $fields['TAS_UID'] = $tasUid; + $fields['USR_UID'] = $usrUid; $fields['DEL_INDEX'] = $delIndex; $fields['APP_STATUS'] = 'TO_DO'; $fields['DEL_DELEGATE_DATE'] = $fields['APP_INIT_DATE']; - if (!$isSubProcess) { + if (!$isSubprocess) { $fields['APP_STATUS'] = 'DRAFT'; } else { $fields['APP_INIT_DATE'] = null; } $inbox = new ListInbox(); - $inbox->newRow($fields, $userUid, $isSelfService); + $inbox->newRow($fields, $usrUid, $isSelfService); // Multiple Instance - foreach ($usersFields as $rowUser) { + foreach ($userFields as $rowUser) { $fields["USR_UID"] = $rowUser["USR_UID"]; $fields["DEL_INDEX"] = $rowUser["DEL_INDEX"]; $inbox = new ListInbox(); - $inbox->newRow($fields, $userUid, $isSelfService); + $inbox->newRow($fields, $usrUid, $isSelfService); } /*----------------------------------********---------------------------------*/ } catch (Exception $e) { throw ($e); } } else { - throw (new Exception('You tried to start a new case without send the USER UID or TASK UID!')); + throw new Exception('You tried to start a new case without send the USER UID or TASK UID!'); } // Log $message = 'Create case'; $context = $data = [ "appUid" => $appUid, - "usrUid" => $userUid, - "tasUid" => $taskUid, - "isSubProcess" => $isSubProcess, + "usrUid" => $usrUid, + "tasUid" => $tasUid, + "isSubprocess" => $isSubprocess, "appNumber" => $caseNumber, "delIndex" => $delIndex, "appInitDate" => $fields['APP_INIT_DATE'] @@ -2291,16 +2202,16 @@ class Cases Log::channel(':CreateCase')->info($message, Bootstrap::context($context)); // Call plugin if (class_exists('folderData')) { - $folderData = new folderData($processUid, $proFields['PRO_TITLE'], $appUid, $newValues['APP_TITLE'], $userUid); - $pluginRegistry = PluginRegistry::loadSingleton(); - $pluginRegistry->executeTriggers(PM_CREATE_CASE, $folderData); + $folderData = new folderData($proUid, $proFields['PRO_TITLE'], $appUid, '', $usrUid); + $oPluginRegistry = PluginRegistry::loadSingleton(); + $oPluginRegistry->executeTriggers(PM_CREATE_CASE, $folderData); } $this->getExecuteTriggerProcess($appUid, 'CREATE'); - // End plugin + //end plugin return [ 'APPLICATION' => $appUid, 'INDEX' => $delIndex, - 'PROCESS' => $processUid, + 'PROCESS' => $proUid, 'CASE_NUMBER' => $caseNumber ]; } @@ -3595,17 +3506,6 @@ class Cases } } - /** - * Get the caseTitle from the nextTask and update the caseTitle - */ - if ($varInAfterRouting) { - $this->newRefreshCaseTitleAndDescription( - $appUid, - ['DEL_INDEX' => 0], - $fieldsCase - ); - } - /*----------------------------------********---------------------------------*/ if (!empty($foundDisabledCode)) { G::SendTemporalMessage( @@ -4246,14 +4146,16 @@ class Cases $this->getExecuteTriggerProcess($sApplicationUID, '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, - 'APP_TITLE' => ($appTitle != null) ? $appTitle : $aFields['APP_TITLE'] + 'APP_TITLE' => $threadTitle, ); $data = array_merge($aFields, $data); + $oListPaused = new ListPaused(); $oListPaused->create($data); /*----------------------------------********---------------------------------*/ @@ -4263,112 +4165,113 @@ class Cases * unpause a case * * @name unpauseCase - * @param string $sApplicationUID - * @param string $iDelegation - * @param string $sUserUID + * @param string $appUid + * @param int $index + * @param string $usrUid * @return object */ - public function unpauseCase($sApplicationUID, $iDelegation, $sUserUID) + public function unpauseCase($appUid, $index, $usrUid) { - //Verify status of the case - $oDelay = new AppDelay(); - if (method_exists($oDelay, 'isPaused')) { - if ($oDelay->isPaused($sApplicationUID, $iDelegation) === false) { + // Verify status of the case + $delay = new AppDelay(); + if (method_exists($delay, 'isPaused')) { + if ($delay->isPaused($appUid, $index) === false) { return false; } } - //get information about current $iDelegation row - $oAppDelegation = new AppDelegation(); - $user = UsersPeer::retrieveByPK($sUserUID); - $aFieldsDel = $oAppDelegation->Load($sApplicationUID, $iDelegation); + // Get information about current $index row + $delegation = new AppDelegation(); + $delRow = $delegation->Load($appUid, $index); //and creates a new AppDelegation row with the same user, task, process, etc. - $proUid = $aFieldsDel['PRO_UID']; - $appUid = $aFieldsDel['APP_UID']; - $tasUid = $aFieldsDel['TAS_UID']; - $usrUid = $aFieldsDel['USR_UID']; - $delThread = $aFieldsDel['DEL_THREAD']; - $iIndex = $oAppDelegation->createAppDelegation( + $proUid = $delRow['PRO_UID']; + $appUid = $delRow['APP_UID']; + $tasUid = $delRow['TAS_UID']; + $usrUid = $delRow['USR_UID']; + // Load Application + $application = new Application(); + $caseFields = $application->Load($appUid); + $caseData = unserialize($caseFields['APP_DATA']); + + // Create a new delegation + $newIndex = $this->newAppDelegation( $proUid, $appUid, $tasUid, $usrUid, - $delThread, - 3, - false, - -1, - null, - false, - false, - 0, - $aFieldsDel['APP_NUMBER'], - $aFieldsDel['TAS_ID'], - (empty($user)) ? 0 : $user->getUsrId(), - $aFieldsDel['PRO_ID'] + -1, // previous + 3, // Priority + 1, // Start Thread + null, // Next delegation + false, // Flag control + false, // Flag control multi-instance + 0, // Thread previous + $delRow['APP_NUMBER'], + $delRow['PRO_ID'], + $delRow['TAS_ID'], + $caseData ); - //update other fields in the recent new appDelegation - $aData = array(); - $aData['APP_UID'] = $aFieldsDel['APP_UID']; - $aData['DEL_INDEX'] = $iIndex; - $aData['DEL_PREVIOUS'] = $aFieldsDel['DEL_PREVIOUS']; - $aData['DEL_TYPE'] = $aFieldsDel['DEL_TYPE']; - $aData['DEL_PRIORITY'] = $aFieldsDel['DEL_PRIORITY']; - $aData['DEL_DELEGATE_DATE'] = $aFieldsDel['DEL_DELEGATE_DATE']; - $aData['DEL_INIT_DATE'] = date('Y-m-d H:i:s'); - $aData['DEL_FINISH_DATE'] = null; - $oAppDelegation->update($aData); + // Update other fields in the recent new appDelegation + $row = []; + $row['APP_UID'] = $delRow['APP_UID']; + $row['DEL_INDEX'] = $newIndex; + $row['DEL_PREVIOUS'] = $delRow['DEL_PREVIOUS']; + $row['DEL_TYPE'] = $delRow['DEL_TYPE']; + $row['DEL_PRIORITY'] = $delRow['DEL_PRIORITY']; + $row['DEL_DELEGATE_DATE'] = $delRow['DEL_DELEGATE_DATE']; + $row['DEL_INIT_DATE'] = date('Y-m-d H:i:s'); + $row['DEL_FINISH_DATE'] = null; + $delegation->update($row); - //get the APP_DELAY row ( with app_uid, del_index and app_type=pause - $oCriteria = new Criteria('workflow'); - $oCriteria->clearSelectColumns(); - $oCriteria->addSelectColumn(AppDelayPeer::APP_DELAY_UID); - $oCriteria->addSelectColumn(AppDelayPeer::APP_THREAD_INDEX); - $oCriteria->addSelectColumn(AppDelayPeer::APP_STATUS); - $oCriteria->add(AppDelayPeer::APP_UID, $sApplicationUID); - $oCriteria->add(AppDelayPeer::APP_DEL_INDEX, $iDelegation); - $oCriteria->add(AppDelayPeer::APP_TYPE, 'PAUSE'); - $oCriteria->add( - $oCriteria->getNewCriterion(AppDelayPeer::APP_DISABLE_ACTION_USER, 0, Criteria::EQUAL)->addOr( - $oCriteria->getNewCriterion(AppDelayPeer::APP_DISABLE_ACTION_USER, null, Criteria::ISNULL)) + // Get the APP_DELAY row with app_uid, del_index and app_type=pause + $criteria = new Criteria('workflow'); + $criteria->clearSelectColumns(); + $criteria->addSelectColumn(AppDelayPeer::APP_DELAY_UID); + $criteria->addSelectColumn(AppDelayPeer::APP_THREAD_INDEX); + $criteria->addSelectColumn(AppDelayPeer::APP_STATUS); + $criteria->add(AppDelayPeer::APP_UID, $appUid); + $criteria->add(AppDelayPeer::APP_DEL_INDEX, $index); + $criteria->add(AppDelayPeer::APP_TYPE, 'PAUSE'); + $criteria->add( + $criteria->getNewCriterion(AppDelayPeer::APP_DISABLE_ACTION_USER, 0, Criteria::EQUAL)->addOr( + $criteria->getNewCriterion(AppDelayPeer::APP_DISABLE_ACTION_USER, null, Criteria::ISNULL)) ); + $dataset = AppDelayPeer::doSelectRS($criteria); + $dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); + $dataset->next(); + $rowPaused = $dataset->getRow(); - $oDataset = AppDelayPeer::doSelectRS($oCriteria); - $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); - $oDataset->next(); - $aRow = $oDataset->getRow(); - $oApplication = new Application(); - $aFields = $oApplication->Load($sApplicationUID); - $aFields['APP_STATUS'] = $aRow['APP_STATUS']; - $oApplication->update($aFields); + $caseFields['APP_STATUS'] = $rowPaused['APP_STATUS']; + $application->update($caseFields); - //update the DEL_INDEX ? in APP_THREAD table? - $aUpdate = array( - 'APP_UID' => $sApplicationUID, - 'APP_THREAD_INDEX' => $aRow['APP_THREAD_INDEX'], - 'DEL_INDEX' => $iIndex - ); - $oAppThread = new AppThread(); - $oAppThread->update($aUpdate); + // Update the DEL_INDEX ? in APP_THREAD table? + $rowUpdate = [ + 'APP_UID' => $appUid, + 'APP_THREAD_INDEX' => $rowPaused['APP_THREAD_INDEX'], + 'DEL_INDEX' => $newIndex + ]; + $thread = new AppThread(); + $thread->update($rowUpdate); - $aData['APP_DELAY_UID'] = $aRow['APP_DELAY_UID']; - $aData['APP_DISABLE_ACTION_USER'] = $sUserUID; - $aData['APP_DISABLE_ACTION_DATE'] = date('Y-m-d H:i:s'); - $oAppDelay = new AppDelay(); - $aFieldsDelay = $oAppDelay->update($aData); + $row['APP_DELAY_UID'] = $rowPaused['APP_DELAY_UID']; + $row['APP_DISABLE_ACTION_USER'] = $usrUid; + $row['APP_DISABLE_ACTION_DATE'] = date('Y-m-d H:i:s'); + $delay = new AppDelay(); + $rowDelay = $delay->update($row); - //update searchindex + // Update searchindex if ($this->appSolr != null) { - $this->appSolr->updateApplicationSearchIndex($sApplicationUID); + $this->appSolr->updateApplicationSearchIndex($appUid); } - $this->getExecuteTriggerProcess($sApplicationUID, "UNPAUSE"); + $this->getExecuteTriggerProcess($appUid, "UNPAUSE"); /*----------------------------------********---------------------------------*/ - $aData = array_merge($aFieldsDel, $aData); - $oListPaused = new ListPaused(); - $oListPaused->remove($sApplicationUID, $iDelegation, $aData); + $row = array_merge($delRow, $row); + $listPaused = new ListPaused(); + $listPaused->remove($appUid, $index, $row); /*----------------------------------********---------------------------------*/ } @@ -4510,28 +4413,26 @@ class Cases //Get all the threads in the AppDelay foreach ($threadsCanceled as $row){ - //Load the thread CLOSED + // Load the thread CLOSED $appDelegation = new AppDelegation(); $delegationClosed = $appDelegation->Load($appUid, $row['APP_DEL_INDEX']); - //Create an appDelegation for each thread - $appDelegation = new AppDelegation(); - $delIndex = $appDelegation->createAppDelegation( + // Create an appDelegation for each thread + $delIndex = $this->newAppDelegation( $delegationClosed['PRO_UID'], $delegationClosed['APP_UID'], $delegationClosed['TAS_UID'], $usrUid, - $delegationClosed['DEL_THREAD'], - 3, - false, - $delegationClosed['DEL_PREVIOUS'], - null, - false, - false, - 0, + $delegationClosed['DEL_PREVIOUS'], // previous + 3, // Priority + $delegationClosed['DEL_THREAD'], // Start Thread + null, // Next delegation + false, // Flag control + false, // Flag control multi-instance + 0, // Thread previous $delegationClosed['APP_NUMBER'], + $delegationClosed['PRO_ID'], $delegationClosed['TAS_ID'], - $userId, - $delegationClosed['PRO_ID'] + $caseFields['APP_DATA'] ); //Update the appThread @@ -4663,23 +4564,29 @@ class Cases $user = UsersPeer::retrieveByPK($newUserUid); $appDelegation = new AppDelegation(); $fieldsDel = $appDelegation->Load($appUid, $delIndex); - $newDelIndex = $appDelegation->createAppDelegation( + + // Load application + $application = new Application(); + $dataFields = $application->Load($appUid); + $caseData = unserialize($dataFields['APP_DATA']); + + // Create a new delegation + $newDelIndex = $this->newAppDelegation( $fieldsDel['PRO_UID'], $fieldsDel['APP_UID'], $fieldsDel['TAS_UID'], $newUserUid, - $fieldsDel['DEL_THREAD'], - 3, - false, - -1, - null, - false, - false, - 0, + -1, // previous + 3, // Priority + $fieldsDel['DEL_THREAD'], // Start Thread + null, // Next delegation + false, // Flag control + false, // Flag control multi-instance + 0, // Thread previous $fieldsDel['APP_NUMBER'], + $fieldsDel['PRO_ID'], $fieldsDel['TAS_ID'], - (empty($user)) ? 0 : $user->getUsrId(), - $fieldsDel['PRO_ID'] + $caseData ); $newData = []; @@ -4703,9 +4610,7 @@ class Cases ] ); - //Save in APP_DELAY - $application = new Application(); - $dataFields = $application->Load($appUid); + $newData['PRO_UID'] = $fieldsDel['PRO_UID']; $newData['APP_UID'] = $appUid; $newData['APP_THREAD_INDEX'] = $fieldsDel['DEL_THREAD']; diff --git a/workflow/engine/classes/Derivation.php b/workflow/engine/classes/Derivation.php index 0111dcf27..b88e46afd 100644 --- a/workflow/engine/classes/Derivation.php +++ b/workflow/engine/classes/Derivation.php @@ -1070,7 +1070,7 @@ class Derivation break; default: $iNewDelIndex = $this->doDerivation($currentDelegation, $nextDel, $appFields, $aSP); - //Load Case Data again because the information could be change in method "doDerivation" + // Load Case Data again because the information could be change in method "doDerivation" $verifyApplication = $this->case->loadCase($currentDelegation['APP_UID']); $appFields['APP_DATA'] = $verifyApplication['APP_DATA']; //When the users route the case in the same time @@ -1286,7 +1286,6 @@ class Derivation $newDelegationUser, $currentDelegation['DEL_INDEX'], $nextDel['DEL_PRIORITY'], - $delType, $iAppThreadIndex, $nextDel, $this->flagControl, @@ -2365,7 +2364,6 @@ class Derivation (isset( $aValue['USR_UID'] ) ? $aValue['USR_UID'] : ''), $currentDelegation['DEL_INDEX'], $nextDel['DEL_PRIORITY'], - $delType, $iNewAppThreadIndex, $nextDel, $appFields['APP_NUMBER'], diff --git a/workflow/engine/classes/WorkspaceTools.php b/workflow/engine/classes/WorkspaceTools.php index d0d2045d1..17f07b6f4 100644 --- a/workflow/engine/classes/WorkspaceTools.php +++ b/workflow/engine/classes/WorkspaceTools.php @@ -12,6 +12,7 @@ use ProcessMaker\Core\Installer; use ProcessMaker\Core\ProcessesManager; use ProcessMaker\Core\System; use ProcessMaker\Model\Application; +use ProcessMaker\Model\Delegation; use ProcessMaker\Model\Fields; use ProcessMaker\Plugins\Adapters\PluginAdapter; use ProcessMaker\Project\Adapter\BpmnWorkflow; @@ -365,7 +366,7 @@ class WorkspaceTools $start = microtime(true); $this->updateTriggers(true, $lang); CLI::logging("* End updating MySQL triggers...(" . (microtime(true) - $start) . " seconds)\n"); - + CLI::logging("* Start adding +async option to scheduler commands...\n"); $start = microtime(true); $this->addAsyncOptionToSchedulerCommands(true); @@ -377,6 +378,11 @@ class WorkspaceTools Propel::init(PATH_CONFIG . 'databases.php'); WebEntry::convertFromV1ToV2(); CLI::logging("* End converting Web Entries v1.0 to v2.0 for BPMN processes...(" . (microtime(true) - $start) . " seconds)\n"); + + CLI::logging("* Start migrating case title...\n"); + $start = microtime(true); + $this->migrateCaseTitleToThreads([$workspace]); + CLI::logging("* End migrating case title...(Completed on " . (microtime(true) - $start) . " seconds)\n"); } /** @@ -593,11 +599,21 @@ class WorkspaceTools $rbDetails = $this->getDBCredentials("rb"); $rpDetails = $this->getDBCredentials("rp"); - $config = array('datasources' => array('workflow' => array('connection' => $wfDetails["dsn"], 'adapter' => $wfDetails["adapter"] - ), 'rbac' => array('connection' => $rbDetails["dsn"], 'adapter' => $rbDetails["adapter"] - ), 'rp' => array('connection' => $rpDetails["dsn"], 'adapter' => $rpDetails["adapter"] - ) - ) + $config = array( + 'datasources' => array( + 'workflow' => array( + 'connection' => $wfDetails["dsn"], + 'adapter' => $wfDetails["adapter"] + ), + 'rbac' => array( + 'connection' => $rbDetails["dsn"], + 'adapter' => $rbDetails["adapter"] + ), + 'rp' => array( + 'connection' => $rpDetails["dsn"], + 'adapter' => $rpDetails["adapter"] + ) + ) ); if ($root) { @@ -1039,12 +1055,14 @@ class WorkspaceTools $this->initPropel(true); $conf = new Configurations(); if (!$conf->exists("ENVIRONMENT_SETTINGS")) { - $conf->aConfig = array("format" => '@userName (@firstName @lastName)', + $conf->aConfig = array( + "format" => '@userName (@firstName @lastName)', "dateFormat" => 'd/m/Y', "startCaseHideProcessInf" => false, "casesListDateFormat" => 'Y-m-d H:i:s', "casesListRowNumber" => 25, - "casesListRefreshTime" => 120); + "casesListRefreshTime" => 120 + ); $conf->saveConfig('ENVIRONMENT_SETTINGS', ''); } $conf->setDirectoryStructureVer(2); @@ -1076,12 +1094,12 @@ class WorkspaceTools P11835::$dbAdapter = $this->dbAdapter; P11835::isApplicable(); $systemSchema = System::getSystemSchema($this->dbAdapter); - $systemSchemaRbac = System::getSystemSchemaRbac($this->dbAdapter);// Get the RBAC Schema + $systemSchemaRbac = System::getSystemSchemaRbac($this->dbAdapter); // Get the RBAC Schema $this->registerSystemTables(array_merge($systemSchema, $systemSchemaRbac)); $this->upgradeSchema($systemSchema, false, false, $includeIndexes); $this->upgradeSchema($systemSchemaRbac, false, true); // Perform upgrade to RBAC $this->upgradeData(); - $this->checkRbacPermissions();//check or add new permissions + $this->checkRbacPermissions(); //check or add new permissions $this->checkSequenceNumber(); $this->migrateIteeToDummytask($this->name); /*----------------------------------********---------------------------------*/ @@ -1215,8 +1233,8 @@ class WorkspaceTools $changes = System::compareSchema($workspaceSchema, $schema); $changed = (count($changes['tablesToAdd']) > 0 || count($changes['tablesToAlter']) > 0 || - count($changes['tablesWithNewIndex']) > 0 || count($changes['tablesToAlterIndex']) > 0 || - count($changes['tablesWithNewFulltext']) > 0 || count($changes['tablesToAlterFulltext']) > 0); + count($changes['tablesWithNewIndex']) > 0 || count($changes['tablesToAlterIndex']) > 0 || + count($changes['tablesWithNewFulltext']) > 0 || count($changes['tablesToAlterFulltext']) > 0); if ($checkOnly || (!$changed)) { if ($changed) { @@ -1299,8 +1317,12 @@ class WorkspaceTools } // Instantiate the class to execute the query in background - $upgradeQueries[] = new RunProcessUpgradeQuery($this->name, $database->generateAddColumnsSql($tableName, - $tableColumn, $indexes, $fulltextIndexes), $rbac); + $upgradeQueries[] = new RunProcessUpgradeQuery($this->name, $database->generateAddColumnsSql( + $tableName, + $tableColumn, + $indexes, + $fulltextIndexes + ), $rbac); } // Run queries in multiple threads @@ -1510,7 +1532,8 @@ class WorkspaceTools if ($fields['DB_NAME'] == $fields['DB_RBAC_NAME']) { $info = array('Workspace Name' => $fields['WORKSPACE_NAME'], 'Workflow Database' => sprintf("%s://%s:%s@%s/%s", $fields['DB_ADAPTER'], $fields['DB_USER'], $fields['DB_PASS'], $fields['DB_HOST'], $fields['DB_NAME']), 'MySql Version' => $fields['DATABASE']); } else { - $info = array('Workspace Name' => $fields['WORKSPACE_NAME'], + $info = array( + 'Workspace Name' => $fields['WORKSPACE_NAME'], //'Available Databases' => $fields['AVAILABLE_DB'], 'Workflow Database' => sprintf("%s://%s:%s@%s/%s", $fields['DB_ADAPTER'], $fields['DB_USER'], $fields['DB_PASS'], $fields['DB_HOST'], $fields['DB_NAME']), 'RBAC Database' => sprintf("%s://%s:%s@%s/%s", $fields['DB_ADAPTER'], $fields['DB_RBAC_USER'], $fields['DB_RBAC_PASS'], $fields['DB_RBAC_HOST'], $fields['DB_RBAC_NAME']), 'Report Database' => sprintf("%s://%s:%s@%s/%s", $fields['DB_ADAPTER'], $fields['DB_REPORT_USER'], $fields['DB_REPORT_PASS'], $fields['DB_REPORT_HOST'], $fields['DB_REPORT_NAME']), 'MySql Version' => $fields['DATABASE'] ); @@ -1648,9 +1671,7 @@ class WorkspaceTools /* Write metadata to file, but make it prettier before. The metadata is just * a JSON codified array. */ - if (!file_put_contents($metaFilename, str_replace(array(",", "{", "}" - ), array(",\n ", "{\n ", "\n}\n" - ), G::json_encode($metadata)))) { + if (!file_put_contents($metaFilename, str_replace(array(",", "{", "}"), array(",\n ", "{\n ", "\n}\n"), G::json_encode($metadata)))) { throw new Exception("Could not create backup metadata"); } CLI::logging("Copying database to backup...\n"); @@ -2120,11 +2141,10 @@ class WorkspaceTools } if (!empty($pmVersionWorkspaceToRestore) && (version_compare( - $pmVersionWorkspaceToRestore . "", - $pmVersion . "", - "<" - ) || empty($pmVersion)) || $pmVersion == "dev-version-backup" - ) { + $pmVersionWorkspaceToRestore . "", + $pmVersion . "", + "<" + ) || empty($pmVersion)) || $pmVersion == "dev-version-backup") { // Upgrade the database schema and data CLI::logging("* Start updating database schema...\n"); $start = microtime(true); @@ -2234,6 +2254,11 @@ class WorkspaceTools Propel::init(PATH_CONFIG . 'databases.php'); WebEntry::convertFromV1ToV2(); CLI::logging("* End converting Web Entries v1.0 to v2.0 for BPMN processes...(" . (microtime(true) - $start) . " seconds)\n"); + + CLI::logging("* Start migrating case title...\n"); + $start = microtime(true); + $workspace->migrateCaseTitleToThreads([$workspaceName]); + CLI::logging("* End migrating case title...(Completed on " . (microtime(true) - $start) . " seconds)\n"); } CLI::logging("> Start To Verify License Enterprise...\n"); @@ -3017,7 +3042,8 @@ class WorkspaceTools * * @throws Exception */ - public function runUpdateListField(array $listTables, $methodName) { + public function runUpdateListField(array $listTables, $methodName) + { // Clean the queries array $listQueries = []; @@ -3049,7 +3075,8 @@ class WorkspaceTools * * @see \WorkspaceTools->migrateList() */ - public function updateListProId($list) { + public function updateListProId($list) + { $query = 'UPDATE ' . $list . ' AS LT INNER JOIN ( SELECT PROCESS.PRO_UID, PROCESS.PRO_ID @@ -3070,7 +3097,8 @@ class WorkspaceTools * * @see \WorkspaceTools->migrateList() */ - public function updateListUsrId($list) { + public function updateListUsrId($list) + { $query = 'UPDATE ' . $list . ' AS LT INNER JOIN ( SELECT USERS.USR_UID, USERS.USR_ID @@ -3091,7 +3119,8 @@ class WorkspaceTools * * @see \WorkspaceTools->migrateList() */ - public function updateListTasId($list) { + public function updateListTasId($list) + { $query = 'UPDATE ' . $list . ' AS LT INNER JOIN ( SELECT TASK.TAS_UID, TASK.TAS_ID @@ -3112,7 +3141,8 @@ class WorkspaceTools * * @see \WorkspaceTools->migrateList() */ - public function updateListAppStatusId($list) { + public function updateListAppStatusId($list) + { $query = "UPDATE " . $list . " SET APP_STATUS_ID = (case when APP_STATUS = 'DRAFT' then 1 @@ -3384,8 +3414,8 @@ class WorkspaceTools file_put_contents( PATH_DATA . "/missing-users-" . $this->name . ".txt", "APP_UID:[" . $item['APP_UID'] . "] - DEL_INDEX[" . $item['DEL_INDEX'] . "] have relation " . - "with invalid or non-existent user user with " . - "id [" . $item['USR_UID'] . "]" + "with invalid or non-existent user user with " . + "id [" . $item['USR_UID'] . "]" ); } CLI::logging("> Number of user related inconsistencies for workspace " . CLI::info($this->name) . ": " . CLI::info($counter) . "\n"); @@ -3420,8 +3450,8 @@ class WorkspaceTools file_put_contents( PATH_DATA . "/missing-tasks-" . $this->name . ".txt", "APP_UID:[" . $item['APP_UID'] . "] - DEL_INDEX[" . $item['DEL_INDEX'] . "] have relation " . - "with invalid or non-existent task with " . - "id [" . $item['TAS_UID'] . "]" + "with invalid or non-existent task with " . + "id [" . $item['TAS_UID'] . "]" ); } @@ -3457,8 +3487,8 @@ class WorkspaceTools file_put_contents( PATH_DATA . "/missing-processes-" . $this->name . ".txt", "APP_UID:[" . $item['APP_UID'] . "] - DEL_INDEX[" . $item['DEL_INDEX'] . "] have relation " . - "with invalid or non-existent process with " . - "id [" . $item['PRO_UID'] . "]" + "with invalid or non-existent process with " . + "id [" . $item['PRO_UID'] . "]" ); } CLI::logging("> Number of processes related data inconsistencies for workspace " . CLI::info($this->name) . ": " . CLI::info($counter) . "\n"); @@ -3493,8 +3523,8 @@ class WorkspaceTools file_put_contents( PATH_DATA . "/missing-app-delegation-" . $this->name . ".txt", "APP_UID:[" . $item['APP_UID'] . "] - DEL_INDEX[" . $item['DEL_INDEX'] . "] have relation " . - "with invalid or non-existent process with " . - "id [" . $item['PRO_UID'] . "]" + "with invalid or non-existent process with " . + "id [" . $item['PRO_UID'] . "]" ); } CLI::logging("> Number of delegations related data inconsistencies for workspace " . CLI::info($this->name) . ": " . CLI::info($counter) . "\n"); @@ -4414,8 +4444,7 @@ class WorkspaceTools if (is_dir($path)) { $dir = opendir($path); while ($fileName = readdir($dir)) { - if ($fileName !== "." && $fileName !== ".." && strpos($fileName, "wsClient.php") === false && strpos($fileName, "Post.php") === false - ) { + if ($fileName !== "." && $fileName !== ".." && strpos($fileName, "wsClient.php") === false && strpos($fileName, "Post.php") === false) { CLI::logging("Verifying if file: " . $fileName . " is a web entry\n"); $step = new Criteria("workflow"); $step->addSelectColumn(StepPeer::PRO_UID); @@ -4568,7 +4597,7 @@ class WorkspaceTools * @param boolean $keepDynContent * * @return void - */ + */ public function clearDynContentHistoryData($force = false, $keepDynContent = false) { $this->initPropel(true); @@ -4724,27 +4753,27 @@ class WorkspaceTools . "LEFT JOIN " . $this->dbName . ".INPUT_DOCUMENT AS H ON (H.INP_DOC_UID=A.DYN_UID) "; $delete = "DELETE FROM " . $this->dbName . ".APP_DATA_CHANGE_LOG " - . "WHERE " - . "ROW_MIGRATION=1"; + . "WHERE " + . "ROW_MIGRATION=1"; $insert = "INSERT INTO " . $this->dbName . ".APP_DATA_CHANGE_LOG ( " - . " DATE, " - . " APP_NUMBER, " - . " DEL_INDEX, " - . " PRO_ID, " - . " TAS_ID, " - . " USR_ID, " - . " OBJECT_TYPE, " - . " OBJECT_ID, " - . " OBJECT_UID, " - . " EXECUTED_AT, " - . " SOURCE_ID, " - . " DATA, " - . " SKIN, " - . " LANGUAGE, " - . " ROW_MIGRATION " - . ") " - . $select; + . " DATE, " + . " APP_NUMBER, " + . " DEL_INDEX, " + . " PRO_ID, " + . " TAS_ID, " + . " USR_ID, " + . " OBJECT_TYPE, " + . " OBJECT_ID, " + . " OBJECT_UID, " + . " EXECUTED_AT, " + . " SOURCE_ID, " + . " DATA, " + . " SKIN, " + . " LANGUAGE, " + . " ROW_MIGRATION " + . ") " + . $select; $con = Propel::getConnection("workflow"); $stmt = $con->createStatement(); @@ -4780,49 +4809,50 @@ class WorkspaceTools $con->begin(); $stmt = $con->createStatement(); $stmt->executeQuery("" - . "UPDATE GROUPWF AS GW " - . "INNER JOIN GROUP_USER AS GU ON " - . " GW.GRP_UID=GU.GRP_UID " - . "SET GU.GRP_ID=GW.GRP_ID " - . "WHERE GU.GRP_ID = 0"); + . "UPDATE GROUPWF AS GW " + . "INNER JOIN GROUP_USER AS GU ON " + . " GW.GRP_UID=GU.GRP_UID " + . "SET GU.GRP_ID=GW.GRP_ID " + . "WHERE GU.GRP_ID = 0"); $con->commit(); CLI::logging("-> Update table APP_ASSIGN_SELF_SERVICE_VALUE_GROUP\n"); $con->begin(); $stmt = $con->createStatement(); $stmt->executeQuery("" - . "UPDATE GROUPWF AS GW " - . "INNER JOIN APP_ASSIGN_SELF_SERVICE_VALUE_GROUP AS GU ON " - . " GW.GRP_UID=GU.GRP_UID " - . "SET " - . "GU.ASSIGNEE_ID=GW.GRP_ID, " - . "GU.ASSIGNEE_TYPE=2 " - . "WHERE GU.ASSIGNEE_ID = 0"); + . "UPDATE GROUPWF AS GW " + . "INNER JOIN APP_ASSIGN_SELF_SERVICE_VALUE_GROUP AS GU ON " + . " GW.GRP_UID=GU.GRP_UID " + . "SET " + . "GU.ASSIGNEE_ID=GW.GRP_ID, " + . "GU.ASSIGNEE_TYPE=2 " + . "WHERE GU.ASSIGNEE_ID = 0"); $con->commit(); $con->begin(); $stmt = $con->createStatement(); $stmt->executeQuery("" - . "UPDATE USERS AS U " - . "INNER JOIN APP_ASSIGN_SELF_SERVICE_VALUE_GROUP AS GU ON " - . " U.USR_UID=GU.GRP_UID " - . "SET " - . "GU.ASSIGNEE_ID=U.USR_ID, " - . "GU.ASSIGNEE_TYPE=1 " - . "WHERE GU.ASSIGNEE_ID = 0"); + . "UPDATE USERS AS U " + . "INNER JOIN APP_ASSIGN_SELF_SERVICE_VALUE_GROUP AS GU ON " + . " U.USR_UID=GU.GRP_UID " + . "SET " + . "GU.ASSIGNEE_ID=U.USR_ID, " + . "GU.ASSIGNEE_TYPE=1 " + . "WHERE GU.ASSIGNEE_ID = 0"); $con->commit(); $con->begin(); $stmt = $con->createStatement(); $stmt->executeQuery("" - . "UPDATE APP_ASSIGN_SELF_SERVICE_VALUE_GROUP " - . "SET " - . "ASSIGNEE_ID=-1, " - . "ASSIGNEE_TYPE=-1 " - . "WHERE ASSIGNEE_ID = 0"); + . "UPDATE APP_ASSIGN_SELF_SERVICE_VALUE_GROUP " + . "SET " + . "ASSIGNEE_ID=-1, " + . "ASSIGNEE_TYPE=-1 " + . "WHERE ASSIGNEE_ID = 0"); $con->commit(); + } - + /** * Remove deprecated files and directory. */ @@ -4850,7 +4880,8 @@ class WorkspaceTools /** * Sync JSON definition of the Forms with Input Documents information */ - public function syncFormsWithInputDocumentInfo() { + public function syncFormsWithInputDocumentInfo() + { // Initialize Propel and instance the required classes $this->initPropel(true); $processInstance = new Process(); @@ -4942,16 +4973,16 @@ class WorkspaceTools * @throws Exception */ public function generateDataReport( - $tableName, - $type = 'NORMAL', - $processUid = '', - $gridKey = '', - $addTabUid = '', - $className = '', - $pathWorkspace, - int $start = 0, - int $limit = 10) - { + $tableName, + $type = 'NORMAL', + $processUid = '', + $gridKey = '', + $addTabUid = '', + $className = '', + $pathWorkspace, + int $start = 0, + int $limit = 10 + ) { $this->initPropel(); $dbHost = explode(':', $this->dbHost); config(['database.connections.workflow.host' => $dbHost[0]]); @@ -4992,12 +5023,12 @@ class WorkspaceTools //select cases for this Process, ordered by APP_NUMBER $applications = Application::query() - ->where('PRO_UID', '=', $processUid) - ->where('APP_NUMBER', '>', 0) - ->orderBy('APP_NUMBER', 'asc') - ->offset($start) - ->limit($limit) - ->get(); + ->where('PRO_UID', '=', $processUid) + ->where('APP_NUMBER', '>', 0) + ->orderBy('APP_NUMBER', 'asc') + ->offset($start) + ->limit($limit) + ->get(); foreach ($applications as $application) { //getting the case data $appData = $case->unserializeData($application->APP_DATA); @@ -5127,4 +5158,43 @@ class WorkspaceTools $conf->aConfig = ['updated' => true]; $conf->saveConfig('ADDED_ASYNC_OPTION_TO_SCHEDULER', 'scheduler'); } + + /** + * Populate the column APP_DELEGATION.DEL_TITLE with the case title APPLICATION.APP_TITLE + * @param array $args + */ + public function migrateCaseTitleToThreads($args) + { + try { + if (!empty($args)) { + // Set workspace constants and initialize DB connection + Bootstrap::setConstantsRelatedWs($args[0]); + Propel::init(PATH_CONFIG . 'databases.php'); + $query = Delegation::leftJoin('APPLICATION', function ($leftJoin) { + $leftJoin->on('APP_DELEGATION.APP_NUMBER', '=', 'APPLICATION.APP_NUMBER'); + }); + $query->where(function ($query) { + $query->whereIn('APPLICATION.APP_STATUS_ID', [2]); + $query->orWhere(function ($query) { + $query->whereIn('APPLICATION.APP_STATUS_ID', [3, 4]); + $query->where('APP_DELEGATION.DEL_LAST_INDEX', '=', 1); + }); + }); + if (!empty($args[1]) && is_numeric($args[1])) { + $query->where('APP_DELEGATION.APP_NUMBER', '>=', $args[1]); + } + if (!empty($args[2]) && is_numeric($args[2])) { + $query->where('APP_DELEGATION.APP_NUMBER', '<=', $args[2]); + } + $query->update(['APP_DELEGATION.DEL_TITLE' => DB::raw('APPLICATION.APP_TITLE')]); + + CLI::logging("The Case Title has been updated successfully in APP_DELEGATION table." . PHP_EOL); + } else { + CLI::logging("The workspace is required." . PHP_EOL . PHP_EOL); + } + } catch (Exception $e) { + // Display the error message + CLI::logging($e->getMessage() . PHP_EOL . PHP_EOL); + } + } } diff --git a/workflow/engine/classes/model/ListParticipatedLast.php b/workflow/engine/classes/model/ListParticipatedLast.php index 9c76cba3c..9467bac9a 100644 --- a/workflow/engine/classes/model/ListParticipatedLast.php +++ b/workflow/engine/classes/model/ListParticipatedLast.php @@ -387,7 +387,7 @@ class ListParticipatedLast extends BaseListParticipatedLast implements ListInter $criteria->addSelectColumn(ListParticipatedLastPeer::TAS_UID); $criteria->addSelectColumn(ListParticipatedLastPeer::PRO_UID); $criteria->addSelectColumn(ListParticipatedLastPeer::APP_NUMBER); - $criteria->addSelectColumn(ApplicationPeer::APP_TITLE); + $criteria->addSelectColumn(ListParticipatedLastPeer::APP_TITLE); $criteria->addSelectColumn(ListParticipatedLastPeer::APP_PRO_TITLE); $criteria->addSelectColumn(ListParticipatedLastPeer::APP_TAS_TITLE); $criteria->addSelectColumn(ListParticipatedLastPeer::APP_STATUS); @@ -405,7 +405,6 @@ class ListParticipatedLast extends BaseListParticipatedLast implements ListInter $criteria->addSelectColumn(ListParticipatedLastPeer::DEL_PRIORITY); $criteria->addSelectColumn(ListParticipatedLastPeer::DEL_THREAD_STATUS); $criteria->add(ListParticipatedLastPeer::USR_UID, $usr_uid, Criteria::EQUAL); - //Check if the user was participated in a specific case if ($appUid != '') { $criteria->add(ListParticipatedLastPeer::APP_UID, $appUid, Criteria::EQUAL); diff --git a/workflow/engine/classes/model/ListUnassigned.php b/workflow/engine/classes/model/ListUnassigned.php index cd4795919..390ed0e5e 100644 --- a/workflow/engine/classes/model/ListUnassigned.php +++ b/workflow/engine/classes/model/ListUnassigned.php @@ -262,10 +262,10 @@ class ListUnassigned extends BaseListUnassigned implements ListInterface 'APP_DELEGATION.DEL_TASK_DUE_DATE', 'APP_DELEGATION.DEL_PRIORITY', 'APP_DELEGATION.DEL_PREVIOUS', + 'APP_DELEGATION.DEL_TITLE AS APP_TITLE', // TASK table 'TASK.TAS_TITLE', // APPLICATION table - 'APPLICATION.APP_TITLE', 'APPLICATION.APP_UPDATE_DATE', // PROCESS table 'PROCESS.PRO_TITLE' @@ -274,7 +274,7 @@ class ListUnassigned extends BaseListUnassigned implements ListInterface 'APP_NUMBER' => 'APP_NUMBER', 'DEL_DUE_DATE' => 'DEL_TASK_DUE_DATE', 'DEL_DELEGATE_DATE' => 'DEL_DELEGATE_DATE', - 'APP_TITLE' => 'APP_TITLE', + 'APP_DELEGATION.DEL_TITLE AS APP_TITLE', 'APP_PRO_TITLE' => 'PRO_TITLE', 'APP_TAS_TITLE' => 'TAS_TITLE', 'DEL_PREVIOUS_USR_UID' => 'USR_ID' diff --git a/workflow/engine/classes/model/map/AppDelegationMapBuilder.php b/workflow/engine/classes/model/map/AppDelegationMapBuilder.php index cb623af83..bf7fda579 100644 --- a/workflow/engine/classes/model/map/AppDelegationMapBuilder.php +++ b/workflow/engine/classes/model/map/AppDelegationMapBuilder.php @@ -123,6 +123,8 @@ class AppDelegationMapBuilder $tMap->addColumn('TAS_ID', 'TasId', 'int', CreoleTypes::INTEGER, false, null); + $tMap->addColumn('DEL_TITLE', 'DelTitle', 'string', CreoleTypes::VARCHAR, true, 999); + $tMap->addValidator('DEL_TYPE', 'validValues', 'propel.validator.ValidValuesValidator', 'NORMAL|PARALLEL', 'Please select a valid status.'); $tMap->addValidator('DEL_PRIORITY', 'validValues', 'propel.validator.ValidValuesValidator', '1|2|3|4|5', 'Please select a valid Priority.'); diff --git a/workflow/engine/classes/model/om/BaseAppDelegation.php b/workflow/engine/classes/model/om/BaseAppDelegation.php index f0fdb6b22..03b069d2b 100644 --- a/workflow/engine/classes/model/om/BaseAppDelegation.php +++ b/workflow/engine/classes/model/om/BaseAppDelegation.php @@ -201,6 +201,12 @@ abstract class BaseAppDelegation extends BaseObject implements Persistent */ protected $tas_id = 0; + /** + * The value for the del_title field. + * @var string + */ + protected $del_title; + /** * Flag to prevent endless save loop, if this object is referenced * by another object which falls in this transaction. @@ -639,6 +645,17 @@ abstract class BaseAppDelegation extends BaseObject implements Persistent return $this->tas_id; } + /** + * Get the [del_title] column value. + * + * @return string + */ + public function getDelTitle() + { + + return $this->del_title; + } + /** * Set the value of [app_uid] column. * @@ -1288,6 +1305,28 @@ abstract class BaseAppDelegation extends BaseObject implements Persistent } // setTasId() + /** + * Set the value of [del_title] column. + * + * @param string $v new value + * @return void + */ + public function setDelTitle($v) + { + + // Since the native PHP type for this column is string, + // we will cast the input to a string (if it is not). + if ($v !== null && !is_string($v)) { + $v = (string) $v; + } + + if ($this->del_title !== $v) { + $this->del_title = $v; + $this->modifiedColumns[] = AppDelegationPeer::DEL_TITLE; + } + + } // setDelTitle() + /** * Hydrates (populates) the object variables with values from the database resultset. * @@ -1363,12 +1402,14 @@ abstract class BaseAppDelegation extends BaseObject implements Persistent $this->tas_id = $rs->getInt($startcol + 28); + $this->del_title = $rs->getString($startcol + 29); + $this->resetModified(); $this->setNew(false); // FIXME - using NUM_COLUMNS may be clearer. - return $startcol + 29; // 29 = AppDelegationPeer::NUM_COLUMNS - AppDelegationPeer::NUM_LAZY_LOAD_COLUMNS). + return $startcol + 30; // 30 = AppDelegationPeer::NUM_COLUMNS - AppDelegationPeer::NUM_LAZY_LOAD_COLUMNS). } catch (Exception $e) { throw new PropelException("Error populating AppDelegation object", $e); @@ -1659,6 +1700,9 @@ abstract class BaseAppDelegation extends BaseObject implements Persistent case 28: return $this->getTasId(); break; + case 29: + return $this->getDelTitle(); + break; default: return null; break; @@ -1708,6 +1752,7 @@ abstract class BaseAppDelegation extends BaseObject implements Persistent $keys[26] => $this->getUsrId(), $keys[27] => $this->getProId(), $keys[28] => $this->getTasId(), + $keys[29] => $this->getDelTitle(), ); return $result; } @@ -1826,6 +1871,9 @@ abstract class BaseAppDelegation extends BaseObject implements Persistent case 28: $this->setTasId($value); break; + case 29: + $this->setDelTitle($value); + break; } // switch() } @@ -1965,6 +2013,10 @@ abstract class BaseAppDelegation extends BaseObject implements Persistent $this->setTasId($arr[$keys[28]]); } + if (array_key_exists($keys[29], $arr)) { + $this->setDelTitle($arr[$keys[29]]); + } + } /** @@ -2092,6 +2144,10 @@ abstract class BaseAppDelegation extends BaseObject implements Persistent $criteria->add(AppDelegationPeer::TAS_ID, $this->tas_id); } + if ($this->isColumnModified(AppDelegationPeer::DEL_TITLE)) { + $criteria->add(AppDelegationPeer::DEL_TITLE, $this->del_title); + } + return $criteria; } @@ -2212,6 +2268,8 @@ abstract class BaseAppDelegation extends BaseObject implements Persistent $copyObj->setTasId($this->tas_id); + $copyObj->setDelTitle($this->del_title); + $copyObj->setNew(true); diff --git a/workflow/engine/classes/model/om/BaseAppDelegationPeer.php b/workflow/engine/classes/model/om/BaseAppDelegationPeer.php index 0caea1fbc..c7c76a240 100644 --- a/workflow/engine/classes/model/om/BaseAppDelegationPeer.php +++ b/workflow/engine/classes/model/om/BaseAppDelegationPeer.php @@ -25,7 +25,7 @@ abstract class BaseAppDelegationPeer const CLASS_DEFAULT = 'classes.model.AppDelegation'; /** The total number of columns. */ - const NUM_COLUMNS = 29; + const NUM_COLUMNS = 30; /** The number of lazy-loaded columns. */ const NUM_LAZY_LOAD_COLUMNS = 0; @@ -118,6 +118,9 @@ abstract class BaseAppDelegationPeer /** the column name for the TAS_ID field */ const TAS_ID = 'APP_DELEGATION.TAS_ID'; + /** the column name for the DEL_TITLE field */ + const DEL_TITLE = 'APP_DELEGATION.DEL_TITLE'; + /** The PHP to DB Name Mapping */ private static $phpNameMap = null; @@ -129,10 +132,10 @@ abstract class BaseAppDelegationPeer * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ private static $fieldNames = array ( - BasePeer::TYPE_PHPNAME => array ('AppUid', 'DelIndex', 'DelegationId', 'AppNumber', 'DelPrevious', 'DelLastIndex', 'ProUid', 'TasUid', 'UsrUid', 'DelType', 'DelThread', 'DelThreadStatus', 'DelPriority', 'DelDelegateDate', 'DelInitDate', 'DelFinishDate', 'DelTaskDueDate', 'DelRiskDate', 'DelDuration', 'DelQueueDuration', 'DelDelayDuration', 'DelStarted', 'DelFinished', 'DelDelayed', 'DelData', 'AppOverduePercentage', 'UsrId', 'ProId', 'TasId', ), - BasePeer::TYPE_COLNAME => array (AppDelegationPeer::APP_UID, AppDelegationPeer::DEL_INDEX, AppDelegationPeer::DELEGATION_ID, AppDelegationPeer::APP_NUMBER, AppDelegationPeer::DEL_PREVIOUS, AppDelegationPeer::DEL_LAST_INDEX, AppDelegationPeer::PRO_UID, AppDelegationPeer::TAS_UID, AppDelegationPeer::USR_UID, AppDelegationPeer::DEL_TYPE, AppDelegationPeer::DEL_THREAD, AppDelegationPeer::DEL_THREAD_STATUS, AppDelegationPeer::DEL_PRIORITY, AppDelegationPeer::DEL_DELEGATE_DATE, AppDelegationPeer::DEL_INIT_DATE, AppDelegationPeer::DEL_FINISH_DATE, AppDelegationPeer::DEL_TASK_DUE_DATE, AppDelegationPeer::DEL_RISK_DATE, AppDelegationPeer::DEL_DURATION, AppDelegationPeer::DEL_QUEUE_DURATION, AppDelegationPeer::DEL_DELAY_DURATION, AppDelegationPeer::DEL_STARTED, AppDelegationPeer::DEL_FINISHED, AppDelegationPeer::DEL_DELAYED, AppDelegationPeer::DEL_DATA, AppDelegationPeer::APP_OVERDUE_PERCENTAGE, AppDelegationPeer::USR_ID, AppDelegationPeer::PRO_ID, AppDelegationPeer::TAS_ID, ), - BasePeer::TYPE_FIELDNAME => array ('APP_UID', 'DEL_INDEX', 'DELEGATION_ID', 'APP_NUMBER', 'DEL_PREVIOUS', 'DEL_LAST_INDEX', 'PRO_UID', 'TAS_UID', 'USR_UID', 'DEL_TYPE', 'DEL_THREAD', 'DEL_THREAD_STATUS', 'DEL_PRIORITY', 'DEL_DELEGATE_DATE', 'DEL_INIT_DATE', 'DEL_FINISH_DATE', 'DEL_TASK_DUE_DATE', 'DEL_RISK_DATE', 'DEL_DURATION', 'DEL_QUEUE_DURATION', 'DEL_DELAY_DURATION', 'DEL_STARTED', 'DEL_FINISHED', 'DEL_DELAYED', 'DEL_DATA', 'APP_OVERDUE_PERCENTAGE', 'USR_ID', 'PRO_ID', 'TAS_ID', ), - BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, ) + BasePeer::TYPE_PHPNAME => array ('AppUid', 'DelIndex', 'DelegationId', 'AppNumber', 'DelPrevious', 'DelLastIndex', 'ProUid', 'TasUid', 'UsrUid', 'DelType', 'DelThread', 'DelThreadStatus', 'DelPriority', 'DelDelegateDate', 'DelInitDate', 'DelFinishDate', 'DelTaskDueDate', 'DelRiskDate', 'DelDuration', 'DelQueueDuration', 'DelDelayDuration', 'DelStarted', 'DelFinished', 'DelDelayed', 'DelData', 'AppOverduePercentage', 'UsrId', 'ProId', 'TasId', 'DelTitle', ), + BasePeer::TYPE_COLNAME => array (AppDelegationPeer::APP_UID, AppDelegationPeer::DEL_INDEX, AppDelegationPeer::DELEGATION_ID, AppDelegationPeer::APP_NUMBER, AppDelegationPeer::DEL_PREVIOUS, AppDelegationPeer::DEL_LAST_INDEX, AppDelegationPeer::PRO_UID, AppDelegationPeer::TAS_UID, AppDelegationPeer::USR_UID, AppDelegationPeer::DEL_TYPE, AppDelegationPeer::DEL_THREAD, AppDelegationPeer::DEL_THREAD_STATUS, AppDelegationPeer::DEL_PRIORITY, AppDelegationPeer::DEL_DELEGATE_DATE, AppDelegationPeer::DEL_INIT_DATE, AppDelegationPeer::DEL_FINISH_DATE, AppDelegationPeer::DEL_TASK_DUE_DATE, AppDelegationPeer::DEL_RISK_DATE, AppDelegationPeer::DEL_DURATION, AppDelegationPeer::DEL_QUEUE_DURATION, AppDelegationPeer::DEL_DELAY_DURATION, AppDelegationPeer::DEL_STARTED, AppDelegationPeer::DEL_FINISHED, AppDelegationPeer::DEL_DELAYED, AppDelegationPeer::DEL_DATA, AppDelegationPeer::APP_OVERDUE_PERCENTAGE, AppDelegationPeer::USR_ID, AppDelegationPeer::PRO_ID, AppDelegationPeer::TAS_ID, AppDelegationPeer::DEL_TITLE, ), + BasePeer::TYPE_FIELDNAME => array ('APP_UID', 'DEL_INDEX', 'DELEGATION_ID', 'APP_NUMBER', 'DEL_PREVIOUS', 'DEL_LAST_INDEX', 'PRO_UID', 'TAS_UID', 'USR_UID', 'DEL_TYPE', 'DEL_THREAD', 'DEL_THREAD_STATUS', 'DEL_PRIORITY', 'DEL_DELEGATE_DATE', 'DEL_INIT_DATE', 'DEL_FINISH_DATE', 'DEL_TASK_DUE_DATE', 'DEL_RISK_DATE', 'DEL_DURATION', 'DEL_QUEUE_DURATION', 'DEL_DELAY_DURATION', 'DEL_STARTED', 'DEL_FINISHED', 'DEL_DELAYED', 'DEL_DATA', 'APP_OVERDUE_PERCENTAGE', 'USR_ID', 'PRO_ID', 'TAS_ID', 'DEL_TITLE', ), + BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, ) ); /** @@ -142,10 +145,10 @@ abstract class BaseAppDelegationPeer * e.g. self::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0 */ private static $fieldKeys = array ( - BasePeer::TYPE_PHPNAME => array ('AppUid' => 0, 'DelIndex' => 1, 'DelegationId' => 2, 'AppNumber' => 3, 'DelPrevious' => 4, 'DelLastIndex' => 5, 'ProUid' => 6, 'TasUid' => 7, 'UsrUid' => 8, 'DelType' => 9, 'DelThread' => 10, 'DelThreadStatus' => 11, 'DelPriority' => 12, 'DelDelegateDate' => 13, 'DelInitDate' => 14, 'DelFinishDate' => 15, 'DelTaskDueDate' => 16, 'DelRiskDate' => 17, 'DelDuration' => 18, 'DelQueueDuration' => 19, 'DelDelayDuration' => 20, 'DelStarted' => 21, 'DelFinished' => 22, 'DelDelayed' => 23, 'DelData' => 24, 'AppOverduePercentage' => 25, 'UsrId' => 26, 'ProId' => 27, 'TasId' => 28, ), - BasePeer::TYPE_COLNAME => array (AppDelegationPeer::APP_UID => 0, AppDelegationPeer::DEL_INDEX => 1, AppDelegationPeer::DELEGATION_ID => 2, AppDelegationPeer::APP_NUMBER => 3, AppDelegationPeer::DEL_PREVIOUS => 4, AppDelegationPeer::DEL_LAST_INDEX => 5, AppDelegationPeer::PRO_UID => 6, AppDelegationPeer::TAS_UID => 7, AppDelegationPeer::USR_UID => 8, AppDelegationPeer::DEL_TYPE => 9, AppDelegationPeer::DEL_THREAD => 10, AppDelegationPeer::DEL_THREAD_STATUS => 11, AppDelegationPeer::DEL_PRIORITY => 12, AppDelegationPeer::DEL_DELEGATE_DATE => 13, AppDelegationPeer::DEL_INIT_DATE => 14, AppDelegationPeer::DEL_FINISH_DATE => 15, AppDelegationPeer::DEL_TASK_DUE_DATE => 16, AppDelegationPeer::DEL_RISK_DATE => 17, AppDelegationPeer::DEL_DURATION => 18, AppDelegationPeer::DEL_QUEUE_DURATION => 19, AppDelegationPeer::DEL_DELAY_DURATION => 20, AppDelegationPeer::DEL_STARTED => 21, AppDelegationPeer::DEL_FINISHED => 22, AppDelegationPeer::DEL_DELAYED => 23, AppDelegationPeer::DEL_DATA => 24, AppDelegationPeer::APP_OVERDUE_PERCENTAGE => 25, AppDelegationPeer::USR_ID => 26, AppDelegationPeer::PRO_ID => 27, AppDelegationPeer::TAS_ID => 28, ), - BasePeer::TYPE_FIELDNAME => array ('APP_UID' => 0, 'DEL_INDEX' => 1, 'DELEGATION_ID' => 2, 'APP_NUMBER' => 3, 'DEL_PREVIOUS' => 4, 'DEL_LAST_INDEX' => 5, 'PRO_UID' => 6, 'TAS_UID' => 7, 'USR_UID' => 8, 'DEL_TYPE' => 9, 'DEL_THREAD' => 10, 'DEL_THREAD_STATUS' => 11, 'DEL_PRIORITY' => 12, 'DEL_DELEGATE_DATE' => 13, 'DEL_INIT_DATE' => 14, 'DEL_FINISH_DATE' => 15, 'DEL_TASK_DUE_DATE' => 16, 'DEL_RISK_DATE' => 17, 'DEL_DURATION' => 18, 'DEL_QUEUE_DURATION' => 19, 'DEL_DELAY_DURATION' => 20, 'DEL_STARTED' => 21, 'DEL_FINISHED' => 22, 'DEL_DELAYED' => 23, 'DEL_DATA' => 24, 'APP_OVERDUE_PERCENTAGE' => 25, 'USR_ID' => 26, 'PRO_ID' => 27, 'TAS_ID' => 28, ), - BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, ) + BasePeer::TYPE_PHPNAME => array ('AppUid' => 0, 'DelIndex' => 1, 'DelegationId' => 2, 'AppNumber' => 3, 'DelPrevious' => 4, 'DelLastIndex' => 5, 'ProUid' => 6, 'TasUid' => 7, 'UsrUid' => 8, 'DelType' => 9, 'DelThread' => 10, 'DelThreadStatus' => 11, 'DelPriority' => 12, 'DelDelegateDate' => 13, 'DelInitDate' => 14, 'DelFinishDate' => 15, 'DelTaskDueDate' => 16, 'DelRiskDate' => 17, 'DelDuration' => 18, 'DelQueueDuration' => 19, 'DelDelayDuration' => 20, 'DelStarted' => 21, 'DelFinished' => 22, 'DelDelayed' => 23, 'DelData' => 24, 'AppOverduePercentage' => 25, 'UsrId' => 26, 'ProId' => 27, 'TasId' => 28, 'DelTitle' => 29, ), + BasePeer::TYPE_COLNAME => array (AppDelegationPeer::APP_UID => 0, AppDelegationPeer::DEL_INDEX => 1, AppDelegationPeer::DELEGATION_ID => 2, AppDelegationPeer::APP_NUMBER => 3, AppDelegationPeer::DEL_PREVIOUS => 4, AppDelegationPeer::DEL_LAST_INDEX => 5, AppDelegationPeer::PRO_UID => 6, AppDelegationPeer::TAS_UID => 7, AppDelegationPeer::USR_UID => 8, AppDelegationPeer::DEL_TYPE => 9, AppDelegationPeer::DEL_THREAD => 10, AppDelegationPeer::DEL_THREAD_STATUS => 11, AppDelegationPeer::DEL_PRIORITY => 12, AppDelegationPeer::DEL_DELEGATE_DATE => 13, AppDelegationPeer::DEL_INIT_DATE => 14, AppDelegationPeer::DEL_FINISH_DATE => 15, AppDelegationPeer::DEL_TASK_DUE_DATE => 16, AppDelegationPeer::DEL_RISK_DATE => 17, AppDelegationPeer::DEL_DURATION => 18, AppDelegationPeer::DEL_QUEUE_DURATION => 19, AppDelegationPeer::DEL_DELAY_DURATION => 20, AppDelegationPeer::DEL_STARTED => 21, AppDelegationPeer::DEL_FINISHED => 22, AppDelegationPeer::DEL_DELAYED => 23, AppDelegationPeer::DEL_DATA => 24, AppDelegationPeer::APP_OVERDUE_PERCENTAGE => 25, AppDelegationPeer::USR_ID => 26, AppDelegationPeer::PRO_ID => 27, AppDelegationPeer::TAS_ID => 28, AppDelegationPeer::DEL_TITLE => 29, ), + BasePeer::TYPE_FIELDNAME => array ('APP_UID' => 0, 'DEL_INDEX' => 1, 'DELEGATION_ID' => 2, 'APP_NUMBER' => 3, 'DEL_PREVIOUS' => 4, 'DEL_LAST_INDEX' => 5, 'PRO_UID' => 6, 'TAS_UID' => 7, 'USR_UID' => 8, 'DEL_TYPE' => 9, 'DEL_THREAD' => 10, 'DEL_THREAD_STATUS' => 11, 'DEL_PRIORITY' => 12, 'DEL_DELEGATE_DATE' => 13, 'DEL_INIT_DATE' => 14, 'DEL_FINISH_DATE' => 15, 'DEL_TASK_DUE_DATE' => 16, 'DEL_RISK_DATE' => 17, 'DEL_DURATION' => 18, 'DEL_QUEUE_DURATION' => 19, 'DEL_DELAY_DURATION' => 20, 'DEL_STARTED' => 21, 'DEL_FINISHED' => 22, 'DEL_DELAYED' => 23, 'DEL_DATA' => 24, 'APP_OVERDUE_PERCENTAGE' => 25, 'USR_ID' => 26, 'PRO_ID' => 27, 'TAS_ID' => 28, 'DEL_TITLE' => 29, ), + BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, ) ); /** @@ -304,6 +307,8 @@ abstract class BaseAppDelegationPeer $criteria->addSelectColumn(AppDelegationPeer::TAS_ID); + $criteria->addSelectColumn(AppDelegationPeer::DEL_TITLE); + } const COUNT = 'COUNT(APP_DELEGATION.APP_UID)'; diff --git a/workflow/engine/config/schema.xml b/workflow/engine/config/schema.xml index 1d7715bcb..485caeea9 100755 --- a/workflow/engine/config/schema.xml +++ b/workflow/engine/config/schema.xml @@ -170,6 +170,7 @@ + @@ -201,6 +202,15 @@ + + + + + + + + + diff --git a/workflow/engine/data/mysql/schema.sql b/workflow/engine/data/mysql/schema.sql index 96d5cd944..cb86f5edc 100644 --- a/workflow/engine/data/mysql/schema.sql +++ b/workflow/engine/data/mysql/schema.sql @@ -94,6 +94,7 @@ CREATE TABLE `APP_DELEGATION` `USR_ID` INTEGER default 0, `PRO_ID` INTEGER default 0, `TAS_ID` INTEGER default 0, + `DEL_TITLE` VARCHAR(999) NOT NULL, PRIMARY KEY (`APP_UID`,`DEL_INDEX`), UNIQUE KEY `DELEGATION_ID` (`DELEGATION_ID`), KEY `INDEX_APP_NUMBER`(`APP_NUMBER`), @@ -101,7 +102,8 @@ CREATE TABLE `APP_DELEGATION` KEY `INDEX_PRO_ID`(`PRO_ID`), KEY `INDEX_TAS_ID`(`TAS_ID`), KEY `INDEX_USR_UID`(`USR_UID`), - KEY `INDEX_THREAD_STATUS_APP_NUMBER`(`DEL_THREAD_STATUS`, `APP_NUMBER`) + KEY `INDEX_THREAD_STATUS_APP_NUMBER`(`DEL_THREAD_STATUS`, `APP_NUMBER`), + FULLTEXT `indexDelTitle`(`DEL_TITLE`) )ENGINE=InnoDB DEFAULT CHARSET='utf8' COMMENT='Delegation a task to user'; #----------------------------------------------------------------------------- #-- APP_DOCUMENT diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/MessageEventDefinition.php b/workflow/engine/src/ProcessMaker/BusinessModel/MessageEventDefinition.php index 5899b59b0..2571d081f 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/MessageEventDefinition.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/MessageEventDefinition.php @@ -1,6 +1,8 @@ unsetFields($arrayData); try { @@ -851,6 +856,7 @@ class TimerEvent throw new \Exception(\G::LoadTranslation("ID_REGISTRY_CANNOT_BE_UPDATED") . (($msg != "")? "\n" . $msg : "")); } + } catch (\Exception $e) { $cnn->rollback(); diff --git a/workflow/engine/src/ProcessMaker/Model/Delegation.php b/workflow/engine/src/ProcessMaker/Model/Delegation.php index ddbcfcc8f..64babc6f0 100644 --- a/workflow/engine/src/ProcessMaker/Model/Delegation.php +++ b/workflow/engine/src/ProcessMaker/Model/Delegation.php @@ -7,6 +7,7 @@ use G; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\DB; use ProcessMaker\Core\System; +use ProcessMaker\Model\Task; class Delegation extends Model { @@ -1026,7 +1027,7 @@ class Delegation extends Model 'APPLICATION.APP_CREATE_DATE', 'APPLICATION.APP_FINISH_DATE', 'APPLICATION.APP_UPDATE_DATE', - 'APPLICATION.APP_TITLE', + 'APP_DELEGATION.DEL_TITLE AS APP_TITLE', 'APP_DELEGATION.USR_UID', 'APP_DELEGATION.TAS_UID', 'APP_DELEGATION.USR_ID', @@ -1082,12 +1083,11 @@ class Delegation extends Model // Build the "fulltext" expression $search = '+"' . preg_replace('/\s+/', '" +"', addslashes($search)) . '"'; - // Searching using "fulltext" index - $join->whereRaw("MATCH(APPLICATION.APP_TITLE) AGAINST('{$search}' IN BOOLEAN MODE)"); + $join->whereRaw("MATCH(APP_DELEGATION.DEL_TITLE) AGAINST('{$search}' IN BOOLEAN MODE)"); } else { // Searching using "like" operator - $join->where('APPLICATION.APP_TITLE', 'LIKE', "%${search}%"); + $join->where('APP_DELEGATION.DEL_TITLE', 'LIKE', "%${search}%"); } } // Based on the below, we can further limit the join so that we have a smaller data set based on join criteria @@ -1111,7 +1111,6 @@ class Delegation extends Model // Don't do anything here, we'll need to do the more advanced where below } }); - // Add join for process, but only for certain scenarios such as category or process if ($category || $process || $sort == 'APP_PRO_TITLE') { $query->join('PROCESS', function ($join) use ($category) { @@ -1412,7 +1411,7 @@ class Delegation extends Model }); // Add join clause with APPLICATION table if required - if (array_search('APPLICATION.APP_TITLE', $selectedColumns) !== false || !empty($textToSearch) || $sort == 'APP_TITLE') { + if (array_search('APP_DELEGATION.DEL_TITLE AS APP_TITLE', $selectedColumns) !== false || array_search('APPLICATION.APP_TITLE', $selectedColumns) !== false || !empty($textToSearch) || $sort == 'APP_TITLE') { $query1->join('APPLICATION', function ($join) { $join->on('APP_DELEGATION.APP_NUMBER', '=', 'APPLICATION.APP_NUMBER'); }); @@ -1433,7 +1432,7 @@ class Delegation extends Model // Build where clause for the text to search if (!empty($textToSearch)) { - $query1->where('APPLICATION.APP_TITLE', 'LIKE', "%$textToSearch%") + $query1->where('APP_DELEGATION.DEL_TITLE', 'LIKE', "%$textToSearch%") ->orWhere('TASK.TAS_TITLE', 'LIKE', "%$textToSearch%") ->orWhere('PROCESS.PRO_TITLE', 'LIKE', "%$textToSearch%"); } @@ -1467,7 +1466,7 @@ class Delegation extends Model }); } // Add join clause with APPLICATION table if required - if (array_search('APPLICATION.APP_TITLE', $selectedColumns) !== false || !empty($textToSearch) || $sort == 'APP_TITLE') { + if (array_search('APP_DELEGATION.DEL_TITLE AS APP_TITLE', $selectedColumns) !== false || !empty($textToSearch) || $sort == 'APP_TITLE') { $query2->join('APPLICATION', function ($join) { $join->on('APP_DELEGATION.APP_NUMBER', '=', 'APPLICATION.APP_NUMBER'); }); @@ -1488,7 +1487,7 @@ class Delegation extends Model // Build where clause for the text to search if (!empty($textToSearch)) { - $query2->where('APPLICATION.APP_TITLE', 'LIKE', "%$textToSearch%") + $query2->where('APP_DELEGATION.DEL_TITLE', 'LIKE', "%$textToSearch%") ->orWhere('TASK.TAS_TITLE', 'LIKE', "%$textToSearch%") ->orWhere('PROCESS.PRO_TITLE', 'LIKE', "%$textToSearch%"); } @@ -1671,6 +1670,25 @@ class Delegation extends Model return ($query->count() > 0); } + /** + * Return the task related to the thread + * + * @param int $appNumber + * @param int $index + * + * @return array + */ + public static function getThreadInfo(int $appNumber, int $index) + { + $query = Delegation::query()->select(['APP_NUMBER', 'TAS_UID', 'TAS_ID', 'DEL_PREVIOUS', 'DEL_TITLE']); + $query->where('APP_NUMBER', $appNumber); + $query->where('DEL_INDEX', $index); + $query->limit(1); + $result = $query->get()->toArray(); + + return head($result); + } + /** * Return the thread related to the specific task-index * @@ -1720,7 +1738,6 @@ class Delegation extends Model return $thread; } - /** * Return the open thread related to the task * @@ -1746,4 +1763,49 @@ class Delegation extends Model return $results; } + + /** + * Get the thread title related to the delegation + * + * @param string $tasUid + * @param int $appNumber + * @param int $delIndexPrevious + * @param array $caseData + * + * @return string + */ + public static function getThreadTitle(string $tasUid, int $appNumber, int $delIndexPrevious, $caseData = []) + { + // Get task title defined + $task = new Task(); + $taskTitle = $task->taskCaseTitle($tasUid); + // If exist we will to replace the variables data + if (!empty($taskTitle)) { + $threadTitle = G::replaceDataField($taskTitle, $caseData, 'mysql', false); + } else { + // If is empty get the previous title + if ($delIndexPrevious > 0) { + $thread = self::getThreadInfo($appNumber, $delIndexPrevious); + $threadTitle = $thread['DEL_TITLE']; + } else { + $threadTitle = '# '. $appNumber; + } + } + + return $threadTitle; + } + + /** + * Get the DEL_TITLE related to DELEGATION table + * + * @param int $appNumber + * @param int $delIndex + * @return string + */ + public static function getDeltitle($appNumber, $delIndex) + { + $query = Delegation::select(['DEL_TITLE'])->where('APP_NUMBER', $appNumber)->where('DEL_INDEX', $delIndex); + $res = $query->first(); + return $res->DEL_TITLE; + } } diff --git a/workflow/engine/src/ProcessMaker/Model/ElementTaskRelation.php b/workflow/engine/src/ProcessMaker/Model/ElementTaskRelation.php new file mode 100644 index 000000000..18fc35a26 --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Model/ElementTaskRelation.php @@ -0,0 +1,14 @@ +select(['TAS_DEF_TITLE']); + $query->where('TAS_UID', $tasUid); + $query->limit(1); + $results = $query->get(); + $title = ''; + $results->each(function ($item) use (&$title) { + $title = $item->TAS_DEF_TITLE; + }); + + return $title; + } + /** * Get task data * @@ -131,4 +152,43 @@ class Task extends Model return $taskInfo; } + + /** + * Set the TAS_DEF_TITLE value + * + * @param string $evnUid + * @param string $caseTitle + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public static function setTaskDefTitle($evnUid, $caseTitle) + { + $query = Task::select(['TASK.TAS_UID']); + $query->join('ELEMENT_TASK_RELATION', function ($join) use ($evnUid) { + $join->on('ELEMENT_TASK_RELATION.TAS_UID', '=', 'TASK.TAS_UID') + ->where('ELEMENT_TASK_RELATION.ELEMENT_UID', '=', $evnUid); + }); + + $query->update(['TASK.TAS_DEF_TITLE' => $caseTitle]); + + return $query; + } + + /** + * Get the TAS_DEF_TITLE value + * + * @param string $evnUid + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public static function getTaskDefTitle($evnUid) + { + $query = Task::select(['TASK.TAS_DEF_TITLE']); + $query->join('ELEMENT_TASK_RELATION', function ($join) use ($evnUid) { + $join->on('ELEMENT_TASK_RELATION.TAS_UID', '=', 'TASK.TAS_UID') + ->where('ELEMENT_TASK_RELATION.ELEMENT_UID', '=', $evnUid); + }); + + return $query->get()->values()->toArray()['0']['TAS_DEF_TITLE']; + } } diff --git a/workflow/engine/src/ProcessMaker/Services/Api/Project/MessageEventDefinition.php b/workflow/engine/src/ProcessMaker/Services/Api/Project/MessageEventDefinition.php index bf1c11b56..268637155 100644 --- a/workflow/engine/src/ProcessMaker/Services/Api/Project/MessageEventDefinition.php +++ b/workflow/engine/src/ProcessMaker/Services/Api/Project/MessageEventDefinition.php @@ -1,8 +1,9 @@ messageEventDefinition->getMessageEventDefinitions($prj_uid); - + foreach ($response as $index => $val){ + $response[$index]['tas_def_title'] = Task::getTaskDefTitle($response[$index]['evn_uid']); + } return $response; } catch (\Exception $e) { throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()); diff --git a/workflow/engine/src/ProcessMaker/Services/Api/Project/TimerEvent.php b/workflow/engine/src/ProcessMaker/Services/Api/Project/TimerEvent.php index a00d5a1c2..b496097c4 100644 --- a/workflow/engine/src/ProcessMaker/Services/Api/Project/TimerEvent.php +++ b/workflow/engine/src/ProcessMaker/Services/Api/Project/TimerEvent.php @@ -1,8 +1,9 @@ timerEvent->getTimerEventByEvent($prj_uid, $evn_uid); - + $response["tas_def_title"] =Task::getTaskDefTitle($evn_uid); return \ProcessMaker\Util\DateTime::convertUtcToIso8601($response, $this->arrayFieldIso8601); } catch (\Exception $e) { throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());