From 77a1a17d83c470907db00e470ba0562608b52f5e Mon Sep 17 00:00:00 2001 From: Paula Quispe Date: Thu, 5 Nov 2020 15:01:08 -0400 Subject: [PATCH 1/7] PMCORE-2293 --- .../model/map/AppDelegationMapBuilder.php | 2 + .../classes/model/om/BaseAppDelegation.php | 60 ++++++++++++++++++- .../model/om/BaseAppDelegationPeer.php | 23 ++++--- workflow/engine/config/schema.xml | 1 + workflow/engine/data/mysql/schema.sql | 1 + 5 files changed, 77 insertions(+), 10 deletions(-) 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 e91f90a66..5fcb3f964 100755 --- a/workflow/engine/config/schema.xml +++ b/workflow/engine/config/schema.xml @@ -169,6 +169,7 @@ + diff --git a/workflow/engine/data/mysql/schema.sql b/workflow/engine/data/mysql/schema.sql index 74f04c4cf..b07da70ba 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`), From d7bae0577a2748882793810cbf1f99d82ff9ebfd Mon Sep 17 00:00:00 2001 From: Andrea Adamczyk Date: Tue, 17 Nov 2020 20:07:35 -0400 Subject: [PATCH 2/7] PMCORE-2433 --- .../factories/ElementTaskRelationFactory.php | 13 +++++ .../src/ProcessMaker/Model/TaskTest.php | 48 +++++++++++++++++++ .../BusinessModel/MessageEventDefinition.php | 6 +++ .../ProcessMaker/BusinessModel/TimerEvent.php | 6 +++ .../Model/ElementTaskRelation.php | 14 ++++++ .../engine/src/ProcessMaker/Model/Task.php | 39 +++++++++++++++ .../Api/Project/MessageEventDefinition.php | 9 ++-- .../Services/Api/Project/TimerEvent.php | 7 +-- 8 files changed, 136 insertions(+), 6 deletions(-) create mode 100644 database/factories/ElementTaskRelationFactory.php create mode 100644 workflow/engine/src/ProcessMaker/Model/ElementTaskRelation.php 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/tests/unit/workflow/engine/src/ProcessMaker/Model/TaskTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/TaskTest.php index 49241b89a..b67dfe7a0 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,50 @@ 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); + } } \ No newline at end of file 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/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 @@ +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()); From ea100cbcba42f60525d513ba600490717adf7105 Mon Sep 17 00:00:00 2001 From: Andrea Adamczyk Date: Wed, 18 Nov 2020 16:31:33 -0400 Subject: [PATCH 3/7] PMCORE-2454 --- workflow/engine/config/schema.xml | 9 +++++++++ workflow/engine/data/mysql/schema.sql | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/workflow/engine/config/schema.xml b/workflow/engine/config/schema.xml index 5fcb3f964..6170bbbde 100755 --- a/workflow/engine/config/schema.xml +++ b/workflow/engine/config/schema.xml @@ -201,6 +201,15 @@ + + + + + + + + + diff --git a/workflow/engine/data/mysql/schema.sql b/workflow/engine/data/mysql/schema.sql index b07da70ba..d4cae47a4 100644 --- a/workflow/engine/data/mysql/schema.sql +++ b/workflow/engine/data/mysql/schema.sql @@ -102,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 From b35c2b9bad3f11fd51d80863109dde82c12a0c69 Mon Sep 17 00:00:00 2001 From: Paula Quispe Date: Thu, 19 Nov 2020 17:21:05 -0400 Subject: [PATCH 4/7] PMCORE-2395 --- database/factories/TaskFactory.php | 2 + .../engine/classes/DerivationTest.php | 1 + .../src/ProcessMaker/Cases/CasesTraitTest.php | 6 +- .../src/ProcessMaker/Model/DelegationTest.php | 14 + .../src/ProcessMaker/Model/TaskTest.php | 14 + workflow/engine/classes/Cases.php | 751 ++++++++---------- workflow/engine/classes/Derivation.php | 4 +- .../src/ProcessMaker/Model/Delegation.php | 51 ++ .../engine/src/ProcessMaker/Model/Task.php | 21 + 9 files changed, 435 insertions(+), 429 deletions(-) diff --git a/database/factories/TaskFactory.php b/database/factories/TaskFactory.php index 90bbe13a2..3633ee9c3 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', @@ -44,6 +45,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/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 de9231d22..cc4fb246b 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php @@ -2372,4 +2372,18 @@ 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); + } + } \ 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 b67dfe7a0..871c60ce4 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/TaskTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/TaskTest.php @@ -172,4 +172,18 @@ class TaskTest extends TestCase $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/classes/Cases.php b/workflow/engine/classes/Cases.php index 114d178fb..e2057264c 100644 --- a/workflow/engine/classes/Cases.php +++ b/workflow/engine/classes/Cases.php @@ -9,6 +9,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; @@ -24,6 +25,7 @@ class Cases public $dir = 'ASC'; public $sort = 'APP_MSG_DATE'; public $arrayTriggerExecutionTime = []; + public $caseTitle = ''; private $triggerMessageExecution = ''; public function __construct() @@ -33,6 +35,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 @@ -608,168 +631,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); } /** @@ -905,12 +796,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'])) { @@ -1024,7 +913,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 @@ -1705,14 +1594,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 @@ -1720,22 +1608,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, @@ -1745,12 +1666,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); } } @@ -2102,202 +2023,194 @@ 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 * * @name startCase - * @param string $sTasUid - * @param string $sUsrUid + * @param string $tasUid + * @param string $usrUid + * @param bool $isSubprocess + * @param array $previousInfo + * @param bool $isSelfService + * * @return Fields + * @throw Exception */ - public function startCase($sTasUid, $sUsrUid, $isSubprocess = false, $dataPreviusApplication = array(), $isSelfService = false) + public function startCase(string $tasUid, string $usrUid, $isSubprocess = false, $previousInfo = [], $isSelfService = false) { - if ($sTasUid != '') { + if (!empty($tasUid)) { try { - $task = TaskPeer::retrieveByPK($sTasUid); - $user = UsersPeer::retrieveByPK($sUsrUid); - + $task = TaskPeer::retrieveByPK($tasUid); + $user = UsersPeer::retrieveByPK($usrUid); if (is_null($task)) { - throw new Exception(G::LoadTranslation("ID_TASK_NOT_EXIST", array("TAS_UID", $sTasUid))); + throw new Exception(G::LoadTranslation("ID_TASK_NOT_EXIST", ["TAS_UID", $tasUid])); } - //To allow Self Service as the first task - $arrayTaskTypeToExclude = array("START-TIMER-EVENT"); - - if (!is_null($task) && !in_array($task->getTasType(), $arrayTaskTypeToExclude) && $task->getTasAssignType() != "SELF_SERVICE" && $sUsrUid == "") { + // To allow Self Service as the first task + $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 - $sProUid = $task->getProUid(); + // Load Process + $proUid = $task->getProUid(); $this->Process = new Process; - $proFields = $this->Process->Load($sProUid); + $proFields = $this->Process->Load($proUid); - //application - $Application = new Application; - $sAppUid = $Application->create($sProUid, $sUsrUid); + // Create application + $application = new Application; + $appUid = $application->create($proUid, $usrUid); + $fields = $application->toArray(BasePeer::TYPE_FIELDNAME); - //appDelegation - $AppDelegation = new AppDelegation; - $iAppThreadIndex = 1; // Start Thread - $iAppDelPrio = 3; // Priority - $iDelIndex = $AppDelegation->createAppDelegation( - $sProUid, - $sAppUid, - $sTasUid, - $sUsrUid, - $iAppThreadIndex, - $iAppDelPrio, - $isSubprocess, - -1, - null, - false, - false, - 0, - $Application->getAppNumber(), + // Create appDelegation + $delIndex = $this->newAppDelegation( + $proUid, + $appUid, + $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; - $iAppThreadIndex = $AppThread->createAppThread($sAppUid, $iDelIndex, 0); + // Instance appThread + $thread = new AppThread; + $threadIndex = $thread->createAppThread($appUid, $delIndex, 0); + // Instance Derivation + $routing = new Derivation(); - $oDerivation = new Derivation(); - - //Multiple Instance - $aUserFields = array(); + // Multiple Instance + $aUserFields = []; $taskAssignType = $task->getTasAssignType(); - $nextTaskAssignVariable = $task->getTasAssignVariable(); if ($taskAssignType == "MULTIPLE_INSTANCE" || $taskAssignType == "MULTIPLE_INSTANCE_VALUE_BASED") { switch ($taskAssignType) { case 'MULTIPLE_INSTANCE': - $userFields = $oDerivation->getUsersFullNameFromArray($oDerivation->getAllUsersFromAnyTask($sTasUid)); + $userFields = $routing->getUsersFullNameFromArray($routing->getAllUsersFromAnyTask($tasUid)); break; default: throw (new Exception('Invalid Task Assignment method')); break; } - $userFields = $oDerivation->getUsersFullNameFromArray($oDerivation->getAllUsersFromAnyTask($sTasUid)); + $userFields = $routing->getUsersFullNameFromArray($routing->getAllUsersFromAnyTask($tasUid)); $count = 0; foreach ($userFields as $rowUser) { - if ($rowUser["USR_UID"] != $sUsrUid) { - //appDelegation - $AppDelegation = new AppDelegation; - $iAppThreadIndex ++; // Start Thread - $iAppDelPrio = 3; // Priority + if ($rowUser["USR_UID"] != $usrUid) { + // Create appDelegation + $delegation = new AppDelegation; + $threadIndex ++; // Start Thread + $priority = 3; // Priority $user = UsersPeer::retrieveByPK($rowUser["USR_UID"]); - $iDelIndex1 = $AppDelegation->createAppDelegation( - $sProUid, - $sAppUid, - $sTasUid, + // Create a new delegation + $delIndex1 = $this->newAppDelegation( + $proUid, + $appUid, + $tasUid, $rowUser["USR_UID"], - $iAppThreadIndex, - $iAppDelPrio, - $isSubprocess, - -1, - null, - false, - false, - 0, - $Application->getAppNumber(), + -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; - $iAppThreadIndex = $AppThread->createAppThread($sAppUid, $iDelIndex1, 0); - //Save Information + // Create appThread + $thread = new AppThread; + $threadIndex = $thread->createAppThread($appUid, $delIndex1, 0); + // Save Information $aUserFields[$count] = $rowUser; - $aUserFields[$count]["DEL_INDEX"] = $iDelIndex1; + $aUserFields[$count]["DEL_INDEX"] = $delIndex1; $count++; } } } - //DONE: Al ya existir un delegation, se puede "calcular" el caseTitle. - $Fields = $Application->toArray(BasePeer::TYPE_FIELDNAME); - $aApplicationFields = $Fields['APP_DATA']; - $Fields['DEL_INDEX'] = $iDelIndex; - $newValues = $this->newRefreshCaseTitleAndDescription($sAppUid, $Fields, $aApplicationFields); - if (!isset($newValues['APP_TITLE'])) { - $newValues['APP_TITLE'] = ''; - } - - $caseNumber = $Fields['APP_NUMBER']; - $Application->update($Fields); - - //Update the task last assigned (for web entry and web services) - $oDerivation->setTasLastAssigned($sTasUid, $sUsrUid); + // Update the application + $fields = $application->toArray(BasePeer::TYPE_FIELDNAME); + $fields['DEL_INDEX'] = $delIndex; + $application->update($fields); + // Get current case number + $caseNumber = $fields['APP_NUMBER']; + // Update the task last assigned (for web entry and web services) + $routing->setTasLastAssigned($tasUid, $usrUid); // Execute Events require_once 'classes/model/Event.php'; $event = new Event(); - $event->createAppEvents($sProUid, $sAppUid, $iDelIndex, $sTasUid); + $event->createAppEvents($proUid, $appUid, $delIndex, $tasUid); - //update searchindex + // Update solr if ($this->appSolr != null) { - $this->appSolr->updateApplicationSearchIndex($sAppUid); + $this->appSolr->updateApplicationSearchIndex($appUid); } /*----------------------------------********---------------------------------*/ - $Fields['TAS_UID'] = $sTasUid; - $Fields['USR_UID'] = $sUsrUid; - $Fields['DEL_INDEX'] = $iDelIndex; - $Fields['APP_STATUS'] = 'TO_DO'; - $Fields['DEL_DELEGATE_DATE'] = $Fields['APP_INIT_DATE']; + $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) { - $Fields['APP_STATUS'] = 'DRAFT'; + $fields['APP_STATUS'] = 'DRAFT'; } else { - $Fields['APP_INIT_DATE'] = null; + $fields['APP_INIT_DATE'] = null; } $inbox = new ListInbox(); - $inbox->newRow($Fields, $sUsrUid, $isSelfService); + $inbox->newRow($fields, $usrUid, $isSelfService); - //Multiple Instance + // Multiple Instance foreach ($aUserFields as $rowUser) { - $Fields["USR_UID"] = $rowUser["USR_UID"]; - $Fields["DEL_INDEX"] = $rowUser["DEL_INDEX"]; + $fields["USR_UID"] = $rowUser["USR_UID"]; + $fields["DEL_INDEX"] = $rowUser["DEL_INDEX"]; $inbox = new ListInbox(); - $inbox->newRow($Fields, $sUsrUid, $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 + // Log $message = 'Create case'; $context = $data = [ - "appUid" => $sAppUid, - "usrUid" => $sUsrUid, - "tasUid" => $sTasUid, + "appUid" => $appUid, + "usrUid" => $usrUid, + "tasUid" => $tasUid, "isSubprocess" => $isSubprocess, "appNumber" => $caseNumber, - "delIndex" => $iDelIndex, - "appInitDate" => $Fields['APP_INIT_DATE'] + "delIndex" => $delIndex, + "appInitDate" => $fields['APP_INIT_DATE'] ]; Log::channel(':CreateCase')->info($message, Bootstrap::context($context)); - //call plugin + // Call plugin if (class_exists('folderData')) { - $folderData = new folderData($sProUid, $proFields['PRO_TITLE'], $sAppUid, $newValues['APP_TITLE'], $sUsrUid); + $folderData = new folderData($proUid, $proFields['PRO_TITLE'], $appUid, '', $usrUid); $oPluginRegistry = PluginRegistry::loadSingleton(); $oPluginRegistry->executeTriggers(PM_CREATE_CASE, $folderData); } - $this->getExecuteTriggerProcess($sAppUid, 'CREATE'); + $this->getExecuteTriggerProcess($appUid, 'CREATE'); //end plugin - return array( - 'APPLICATION' => $sAppUid, - 'INDEX' => $iDelIndex, - 'PROCESS' => $sProUid, + return [ + 'APPLICATION' => $appUid, + 'INDEX' => $delIndex, + 'PROCESS' => $proUid, 'CASE_NUMBER' => $caseNumber - ); + ]; } /** @@ -3590,17 +3503,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( @@ -4258,112 +4160,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); /*----------------------------------********---------------------------------*/ } @@ -4505,28 +4408,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 @@ -4658,23 +4559,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 = []; @@ -4698,9 +4605,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/src/ProcessMaker/Model/Delegation.php b/workflow/engine/src/ProcessMaker/Model/Delegation.php index d5a892e9b..09ec1782f 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 { @@ -803,6 +804,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 * @@ -851,4 +871,35 @@ class Delegation extends Model return $thread; } + + /** + * 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; + } } diff --git a/workflow/engine/src/ProcessMaker/Model/Task.php b/workflow/engine/src/ProcessMaker/Model/Task.php index 552eca2a1..cb9125916 100644 --- a/workflow/engine/src/ProcessMaker/Model/Task.php +++ b/workflow/engine/src/ProcessMaker/Model/Task.php @@ -80,6 +80,27 @@ class Task extends Model return $title; } + /** + * Get the title of the task + * + * @param string $tasUid + * + * @return string + */ + public function taskCaseTitle(string $tasUid) + { + $query = Task::query()->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 * From f65454d9b19cc26976759c3fcfbe823f4a193bb0 Mon Sep 17 00:00:00 2001 From: Andrea Adamczyk Date: Wed, 2 Dec 2020 17:15:01 -0400 Subject: [PATCH 5/7] PMCORE-2394 --- database/factories/DelegationFactory.php | 2 + .../engine/classes/WorkspaceToolsTest.php | 84 ++++++ workflow/engine/bin/tasks/cliWorkspaces.php | 140 ++++----- workflow/engine/classes/WorkspaceTools.php | 270 +++++++++++------- 4 files changed, 328 insertions(+), 168 deletions(-) create mode 100644 tests/unit/workflow/engine/classes/WorkspaceToolsTest.php diff --git a/database/factories/DelegationFactory.php b/database/factories/DelegationFactory.php index fffbb43c4..b88f7abc8 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,6 +32,7 @@ $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, 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/workflow/engine/bin/tasks/cliWorkspaces.php b/workflow/engine/bin/tasks/cliWorkspaces.php index 35a2380a2..d18bcfec2 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; @@ -10,8 +11,7 @@ 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/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); + } + } } From 3cc4baff8e8c2f9c131bbccc6dab3879d7d4d905 Mon Sep 17 00:00:00 2001 From: Andrea Adamczyk Date: Mon, 7 Dec 2020 09:21:51 -0400 Subject: [PATCH 6/7] PMCORE-2396 --- database/factories/DelegationFactory.php | 6 ++-- .../src/ProcessMaker/Model/DelegationTest.php | 18 +++++++++-- workflow/engine/classes/Cases.php | 4 ++- .../classes/model/ListParticipatedLast.php | 3 +- .../engine/classes/model/ListUnassigned.php | 4 +-- .../src/ProcessMaker/Model/Delegation.php | 30 +++++++++++++------ 6 files changed, 47 insertions(+), 18 deletions(-) diff --git a/database/factories/DelegationFactory.php b/database/factories/DelegationFactory.php index fffbb43c4..ab181f9f5 100644 --- a/database/factories/DelegationFactory.php +++ b/database/factories/DelegationFactory.php @@ -34,7 +34,8 @@ $factory->define(\ProcessMaker\Model\Delegation::class, function(Faker $faker) { 'USR_ID' => $user->USR_ID, 'PRO_ID' => $process->PRO_ID, 'TAS_ID' => $task->TAS_ID, - 'DEL_DATA' => '' + 'DEL_DATA' => '', + 'DEL_TITLE' => $faker->word() ]; }); @@ -73,7 +74,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/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php index cc4fb246b..4ffdc282b 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php @@ -277,8 +277,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(); @@ -2386,4 +2385,19 @@ class DelegationTest extends TestCase $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/workflow/engine/classes/Cases.php b/workflow/engine/classes/Cases.php index efa07e08b..eca74169c 100644 --- a/workflow/engine/classes/Cases.php +++ b/workflow/engine/classes/Cases.php @@ -4147,14 +4147,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); /*----------------------------------********---------------------------------*/ 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/src/ProcessMaker/Model/Delegation.php b/workflow/engine/src/ProcessMaker/Model/Delegation.php index 09ec1782f..a23638a54 100644 --- a/workflow/engine/src/ProcessMaker/Model/Delegation.php +++ b/workflow/engine/src/ProcessMaker/Model/Delegation.php @@ -187,7 +187,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', @@ -240,12 +240,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 @@ -269,7 +268,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) { @@ -562,7 +560,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'); }); @@ -583,7 +581,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%"); } @@ -618,7 +616,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'); }); @@ -639,7 +637,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%"); } @@ -902,4 +900,18 @@ class Delegation extends Model 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; + } } From adcd0ee41ad91adeb6ee735a637d8c6bd8f61418 Mon Sep 17 00:00:00 2001 From: Paula Quispe Date: Tue, 8 Dec 2020 14:43:40 -0400 Subject: [PATCH 7/7] PMCORE-2292 --- workflow/engine/classes/Cases.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/workflow/engine/classes/Cases.php b/workflow/engine/classes/Cases.php index eca74169c..7ab3b4aad 100644 --- a/workflow/engine/classes/Cases.php +++ b/workflow/engine/classes/Cases.php @@ -2151,7 +2151,6 @@ class Cases $routing->setTasLastAssigned($tasUid, $usrUid); // Execute Events - require_once 'classes/model/Event.php'; $event = new Event(); $event->createAppEvents($proUid, $appUid, $delIndex, $tasUid); @@ -2182,7 +2181,7 @@ class Cases $inbox->newRow($fields, $usrUid, $isSelfService); } /*----------------------------------********---------------------------------*/ - } catch (exception $e) { + } catch (Exception $e) { throw ($e); } } else {