PMCORE-3092

This commit is contained in:
Paula Quispe
2021-07-26 13:13:26 -04:00
parent a0b9605d92
commit 6d500d78e2
19 changed files with 377 additions and 130 deletions

View File

@@ -11,7 +11,10 @@ use ProcessMaker\Cases\CasesTrait;
use ProcessMaker\ChangeLog\ChangeLog;
/*----------------------------------********---------------------------------*/
use ProcessMaker\Core\System;
use ProcessMaker\Model\AppDelay as Delay;
use ProcessMaker\Model\AppThread as Thread;
use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\User;
use ProcessMaker\Plugins\PluginRegistry;
use ProcessMaker\Util\DateTime;
@@ -1913,6 +1916,7 @@ class Cases
$data = [];
foreach ($rowObj as $appDel) {
$appDel->setDelThreadStatus('CLOSED');
$appDel->setDelThreadStatusId(Delegation::$thread_status['CLOSED']);
$appDel->setDelFinishDate('now');
if ($appDel->Validate()) {
$appDel->Save();
@@ -1952,11 +1956,13 @@ class Cases
*
* @param string $appUid
* @param string $delIndex
* @param string $status
* @param int $statusId
*
* @return void
* @throws Exception
*/
public function CloseCurrentDelegation($appUid, $delIndex)
public function CloseCurrentDelegation($appUid, $delIndex, string $status = 'CLOSED', int $statusId = 0)
{
try {
$criteria = new Criteria();
@@ -1965,7 +1971,8 @@ class Cases
$rowObj = AppDelegationPeer::doSelect($criteria);
$user = '';
foreach ($rowObj as $appDel) {
$appDel->setDelThreadStatus('CLOSED');
$appDel->setDelThreadStatus($status);
$appDel->setDelThreadStatusId($statusId);
$appDel->setDelFinishDate('now');
$user = $appDel->getUsrUid();
if ($appDel->Validate()) {
@@ -1991,7 +1998,7 @@ class Cases
$listParticipatedLast->refresh($data);
/*----------------------------------********---------------------------------*/
/** Update searchindex */
/** Update search index */
if ($this->appSolr != null) {
$this->appSolr->updateApplicationSearchIndex($appUid);
}
@@ -2019,6 +2026,7 @@ class Cases
$rowObj = AppDelegationPeer::doSelect($c);
foreach ($rowObj as $appDel) {
$appDel->setDelThreadStatus('OPEN');
$appDel->setDelThreadStatusId(Delegation::$thread_status['OPEN']);
$appDel->setDelFinishDate(null);
if ($appDel->Validate()) {
$appDel->Save();
@@ -4097,77 +4105,75 @@ class Cases
}
/**
* pause a Case
* Pause a Case
*
* @param string $appUid
* @param int $index
* @param string $usrUid
* @param string $unpauseDate
* @param string $appTitle
*
* @name pauseCase
* @param string $sApplicationUID
* @param string $iDelegation
* @param string $sUserUID
* @param string $sUnpauseDate
* @return object
*/
public function pauseCase($sApplicationUID, $iDelegation, $sUserUID, $sUnpauseDate = null, $appTitle = null)
public function pauseCase($appUid, $index, $usrUid, $unpauseDate = null, $appTitle = null)
{
// Check if the case is unassigned
if ($this->isUnassignedPauseCase($sApplicationUID, $iDelegation)) {
throw new Exception(G::LoadTranslation("ID_CASE_NOT_PAUSED", array(G::LoadTranslation("ID_UNASSIGNED_STATUS"))));
}
$oApplication = new Application();
$aFields = $oApplication->Load($sApplicationUID);
//get the appthread row id ( APP_THREAD_INDEX' )
$oCriteria = new Criteria('workflow');
$oCriteria->clearSelectColumns();
$oCriteria->addSelectColumn(AppThreadPeer::APP_THREAD_INDEX);
$oCriteria->add(AppThreadPeer::APP_UID, $sApplicationUID);
$oCriteria->add(AppThreadPeer::DEL_INDEX, $iDelegation);
$oDataset = AppThreadPeer::doSelectRS($oCriteria);
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
if ($oDataset->next()) {
$aRow = $oDataset->getRow();
} else {
$application = new Application();
$fields = $application->Load($appUid);
$appNumber = $application->getAppNumber();
// Get the index of appThread
$appThread = Thread::getThread($appUid, $index);
$appThread = head($appThread);
$threadIndex = $appThread['APP_THREAD_INDEX'];
if (empty($threadIndex)) {
throw new Exception(G::LoadTranslation("ID_CASE_STOPPED_TRIGGER"));
}
/** Close the index for pause */
$this->CloseCurrentDelegation($appUid, $index, 'PAUSED', Delegation::$thread_status['PAUSED']);
$this->CloseCurrentDelegation($sApplicationUID, $iDelegation);
//now create a row in APP_DELAY with type PAUSE
$aData['PRO_UID'] = $aFields['PRO_UID'];
$aData['APP_UID'] = $sApplicationUID;
$aData['APP_THREAD_INDEX'] = $aRow['APP_THREAD_INDEX'];
$aData['APP_DEL_INDEX'] = $iDelegation;
$aData['APP_TYPE'] = 'PAUSE';
$aData['APP_STATUS'] = $aFields['APP_STATUS'];
$aData['APP_DELEGATION_USER'] = $sUserUID;
$aData['APP_ENABLE_ACTION_USER'] = $sUserUID;
$aData['APP_ENABLE_ACTION_DATE'] = date('Y-m-d H:i:s');
$aData['APP_DISABLE_ACTION_DATE'] = $sUnpauseDate;
$aData['APP_NUMBER'] = $oApplication->getAppNumber();
$oAppDelay = new AppDelay();
$oAppDelay->create($aData);
// Prepare the data for pause
$attributes = [
'APP_DELAY_UID' => G::generateUniqueID(),
'PRO_UID' => $application->getProUid(),
'PRO_ID' => $application->getProId(),
'APP_UID' => $appUid,
'APP_NUMBER' => $appNumber,
'APP_THREAD_INDEX' => $threadIndex,
'APP_DEL_INDEX' => $index,
'APP_TYPE' => 'PAUSE',
'APP_STATUS' => $application->getAppStatus(),
'APP_DELEGATION_USER' => $usrUid,
'APP_DELEGATION_USER_ID' => User::getId($usrUid),
'APP_ENABLE_ACTION_USER' => $usrUid,
'APP_ENABLE_ACTION_DATE' => date('Y-m-d H:i:s'),
'APP_DISABLE_ACTION_DATE' => $unpauseDate,
];
$oApplication->update($aFields);
/** Register the pause case */
Delay::create($attributes);
//update searchindex
/** Update the application case */
$application->update($fields);
/** Update search index */
if ($this->appSolr != null) {
$this->appSolr->updateApplicationSearchIndex($sApplicationUID);
$this->appSolr->updateApplicationSearchIndex($appUid);
}
$this->getExecuteTriggerProcess($sApplicationUID, 'PAUSED');
/** Execute the trigger */
$this->getExecuteTriggerProcess($appUid, 'PAUSED');
/*----------------------------------********---------------------------------*/
$threadTitle = Delegation::getDeltitle($aData['APP_NUMBER'], $aData['APP_DEL_INDEX']);
$data = array(
'APP_UID' => $sApplicationUID,
'DEL_INDEX' => $iDelegation,
'USR_UID' => $sUserUID,
'APP_RESTART_DATE' => $sUnpauseDate,
$threadTitle = Delegation::getDeltitle($appNumber, $index);
$data = [
'APP_UID' => $appUid,
'DEL_INDEX' => $index,
'USR_UID' => $usrUid,
'APP_RESTART_DATE' => $unpauseDate,
'APP_TITLE' => $threadTitle,
);
$data = array_merge($aFields, $data);
$oListPaused = new ListPaused();
$oListPaused->create($data);
];
$data = array_merge($fields, $data);
$listPaused = new ListPaused();
$listPaused->create($data);
/*----------------------------------********---------------------------------*/
}

View File

@@ -1482,6 +1482,7 @@ class Derivation
// Update the DelThreadStatus, the thread is ready for continue
$appDelegation = AppDelegationPeer::retrieveByPK($newCase['APPLICATION'], $newCase['INDEX']);
$appDelegation->setDelThreadStatus('OPEN');
$appDelegation->setDelThreadStatusId(Delegation::$thread_status['OPEN']);
$appDelegation->save();
// Create record in table APP_ASSIGN_SELF_SERVICE_VALUE

View File

@@ -4147,6 +4147,22 @@ class WorkspaceTools
WHERE AD.TAS_ID = 0");
$con->commit();
// Populating APP_DELEGATION.DEL_THREAD_STATUS_ID with paused threads
CLI::logging("-> Populating APP_DELEGATION.DEL_THREAD_STATUS_ID \n");
$con->begin();
$stmt = $con->createStatement();
$rs = $stmt->executeQuery("UPDATE APP_DELEGATION AS AD
INNER JOIN (
SELECT APP_DELAY.APP_NUMBER, APP_DELAY.APP_DEL_INDEX
FROM APP_DELAY
WHERE APP_TYPE = 'PAUSE' AND APP_DELAY.APP_DISABLE_ACTION_USER = '0'
) AS DELAY
ON (AD.APP_NUMBER = DELAY.APP_NUMBER AND AD.DEL_INDEX = DELAY.APP_DEL_INDEX)
SET AD.DEL_THREAD_STATUS_ID = 3,
AD.DEL_THREAD_STATUS = 'PAUSED'
WHERE AD.DEL_THREAD_STATUS_ID = 0");
$con->commit();
// Populating APPLICATION.APP_STATUS_ID
CLI::logging("-> Populating APPLICATION.APP_STATUS_ID \n");
$con->begin();

View File

@@ -25,6 +25,7 @@
*
*/
use ProcessMaker\Model\Delegation;
use ProcessMaker\Plugins\PluginRegistry;
/**
@@ -195,6 +196,7 @@ class AppDelegation extends BaseAppDelegation
$this->setDelPriority(($iPriority != '' ? $iPriority : '3'));
$this->setDelThread($sAppThread);
$this->setDelThreadStatus($theadStatus);
$this->setDelThreadStatusId(Delegation::$thread_status[$theadStatus]);
$this->setDelDelegateDate('now');
$this->setAppNumber($appNumber);
$this->setTasId($taskId);