diff --git a/workflow/engine/bin/tasks/cliWorkspaces.php b/workflow/engine/bin/tasks/cliWorkspaces.php index ee7ff9740..56d47f39e 100644 --- a/workflow/engine/bin/tasks/cliWorkspaces.php +++ b/workflow/engine/bin/tasks/cliWorkspaces.php @@ -276,6 +276,18 @@ CLI::taskArg('workspace', true, true); CLI::taskRun("run_migrate_list_unassigned"); /*----------------------------------********---------------------------------*/ +CLI::taskName('migrate-indexing-acv'); +CLI::taskDescription(<<load($aAppDel['USR_UID']); - //$aFields['CURRENT_USER'] = $oCurUser->getUsrFirstname() . ' ' . $oCurUser->getUsrLastname(); $oCurUser = new Users(); if ($jump != '') { $aCases = $oAppDel->LoadParallel($sAppUid); @@ -1657,16 +1655,38 @@ class Cases * @param string $iPriority * @param string $sDelType * @param string $iAppThreadIndex + * @param string $nextDel + * @param boolean $flagControl + * @param boolean $flagControlMulInstance + * @param int $delPrevious + * @param int $appNumber + * @param int $proId + * @param int $tasId * @return void */ - public function newAppDelegation($sProUid, $sAppUid, $sTasUid, $sUsrUid, $sPrevious, $iPriority, $sDelType, $iAppThreadIndex = 1, $nextDel = null, $flagControl = false, $flagControlMulInstance = false, $delPrevious = 0) + 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) { try { + $user = UsersPeer::retrieveByPK($sUsrUid); $appDel = new AppDelegation(); $result = $appDel->createAppDelegation( - $sProUid, $sAppUid, $sTasUid, $sUsrUid, $iAppThreadIndex, $iPriority, false, $sPrevious, $nextDel, $flagControl, - $flagControlMulInstance, $delPrevious + $sProUid, + $sAppUid, + $sTasUid, + $sUsrUid, + $iAppThreadIndex, + $iPriority, + false, + $sPrevious, + $nextDel, + $flagControl, + $flagControlMulInstance, + $delPrevious, + $appNumber, + $tasId, + $user->getUsrId(), + $proId ); //update searchindex if ($this->appSolr != null) { @@ -1869,14 +1889,15 @@ class Cases * @param string $sAppUid, * @param string $iNewDelIndex * @param string $iAppParent + * @param string $appNumber * @return $iAppThreadIndex $iNewDelIndex, $iAppThreadIndex ); */ - public function newAppThread($sAppUid, $iNewDelIndex, $iAppParent) + public function newAppThread($sAppUid, $iNewDelIndex, $iAppParent, $appNumber = 0) { try { $appThread = new AppThread(); - $result = $appThread->createAppThread($sAppUid, $iNewDelIndex, $iAppParent); + $result = $appThread->createAppThread($sAppUid, $iNewDelIndex, $iAppParent, $appNumber); //update searchindex if ($this->appSolr != null) { $this->appSolr->updateApplicationSearchIndex($sAppUid); @@ -2020,6 +2041,7 @@ class Cases if ($sTasUid != '') { try { $task = TaskPeer::retrieveByPK($sTasUid); + $user = UsersPeer::retrieveByPK($sUsrUid); if (is_null($task)) { throw new Exception(G::LoadTranslation("ID_TASK_NOT_EXIST", array("TAS_UID", $sTasUid))); @@ -2046,12 +2068,28 @@ class Cases $iAppThreadIndex = 1; // Start Thread $iAppDelPrio = 3; // Priority $iDelIndex = $AppDelegation->createAppDelegation( - $sProUid, $sAppUid, $sTasUid, $sUsrUid, $iAppThreadIndex, $iAppDelPrio, $isSubprocess + $sProUid, + $sAppUid, + $sTasUid, + $sUsrUid, + $iAppThreadIndex, + $iAppDelPrio, + $isSubprocess, + -1, + null, + false, + false, + 0, + $Application->getAppNumber(), + $task->getTasId(), + $user->getUsrId(), + $this->Process->getProId() + ); //appThread $AppThread = new AppThread; - $iAppThreadIndex = $AppThread->createAppThread($sAppUid, $iDelIndex, 0); + $iAppThreadIndex = $AppThread->createAppThread($sAppUid, $iDelIndex, 0, $Application->getAppNumber()); G::LoadClass('derivation'); $oDerivation = new Derivation(); @@ -2077,12 +2115,28 @@ class Cases $AppDelegation = new AppDelegation; $iAppThreadIndex ++; // Start Thread $iAppDelPrio = 3; // Priority + $user = UsersPeer::retrieveByPK($rowUser["USR_UID"]); $iDelIndex1 = $AppDelegation->createAppDelegation( - $sProUid, $sAppUid, $sTasUid, $rowUser["USR_UID"], $iAppThreadIndex, $iAppDelPrio, $isSubprocess + $sProUid, + $sAppUid, + $sTasUid, + $rowUser["USR_UID"], + $iAppThreadIndex, + $iAppDelPrio, + $isSubprocess, + -1, + null, + false, + false, + 0, + $Application->getAppNumber(), + $task->getTasId(), + $user->getUsrId(), + $this->Process->getProId() ); //appThread $AppThread = new AppThread; - $iAppThreadIndex = $AppThread->createAppThread($sAppUid, $iDelIndex1, 0); + $iAppThreadIndex = $AppThread->createAppThread($sAppUid, $iDelIndex1, 0, $Application->getAppNumber()); //Save Information $aUserFields[$count] = $rowUser; $aUserFields[$count]["DEL_INDEX"] = $iDelIndex1; @@ -3962,6 +4016,7 @@ class Cases $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); @@ -4017,7 +4072,24 @@ class Cases $tasUid = $aFieldsDel['TAS_UID']; $usrUid = $aFieldsDel['USR_UID']; $delThread = $aFieldsDel['DEL_THREAD']; - $iIndex = $oAppDelegation->createAppDelegation($proUid, $appUid, $tasUid, $usrUid, $delThread); + $iIndex = $oAppDelegation->createAppDelegation( + $proUid, + $appUid, + $tasUid, + $usrUid, + $delThread, + 3, + false, + -1, + null, + false, + false, + 0, + $aFieldsDel['APP_NUMBER'], + $aFieldsDel['TAS_ID'], + $aFieldsDel['USR_ID'], + $aFieldsDel['PRO_ID'] + ); //update other fields in the recent new appDelegation $aData = array(); @@ -4153,6 +4225,7 @@ class Cases $array['APP_DELEGATION_USER'] = $user_logged; $array['APP_ENABLE_ACTION_USER'] = $user_logged; $array['APP_ENABLE_ACTION_DATE'] = date('Y-m-d H:i:s'); + $array['APP_NUMBER'] = $oApplication->getAppNumber(); $delay->create($array); //Before cancel a case verify if is a child case @@ -4369,7 +4442,22 @@ class Cases $oAppDelegation = new AppDelegation(); $aFieldsDel = $oAppDelegation->Load($sApplicationUID, $iDelegation); $iIndex = $oAppDelegation->createAppDelegation( - $aFieldsDel['PRO_UID'], $aFieldsDel['APP_UID'], $aFieldsDel['TAS_UID'], $aFieldsDel['USR_UID'], $aFieldsDel['DEL_THREAD'] + $aFieldsDel['PRO_UID'], + $aFieldsDel['APP_UID'], + $aFieldsDel['TAS_UID'], + $aFieldsDel['USR_UID'], + $aFieldsDel['DEL_THREAD'], + 3, + false, + -1, + null, + false, + false, + 0, + $aFieldsDel['APP_NUMBER'], + $aFieldsDel['TAS_ID'], + $aFieldsDel['USR_ID'], + $aFieldsDel['PRO_ID'] ); $newDelIndex = $iIndex; $aData = array(); @@ -4403,6 +4491,7 @@ class Cases $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_NUMBER'] = $aFieldsDel['APP_NUMBER']; $oAppDelay = new AppDelay(); $oAppDelay->create($aData); diff --git a/workflow/engine/classes/class.derivation.php b/workflow/engine/classes/class.derivation.php index 49791a13e..304f90c3d 100644 --- a/workflow/engine/classes/class.derivation.php +++ b/workflow/engine/classes/class.derivation.php @@ -985,6 +985,7 @@ class Derivation default: //Get all siblingThreads $canDerivate = false; + $nextDel['TAS_ID'] = $taskNextDel->getTasId(); switch ($currentDelegation['TAS_ASSIGN_TYPE']) { case 'CANCEL_MI': @@ -1332,9 +1333,22 @@ class Derivation //Incrementing the Del_thread First so that new delegation has new del_thread $iNewAppThreadIndex += 1; //Creating new delegation according to users in group - $iMIDelIndex = $this->case->newAppDelegation( $appFields['PRO_UID'], $currentDelegation['APP_UID'], $nextDel['TAS_UID'], (isset( $aValue['USR_UID'] ) ? $aValue['USR_UID'] : ''), $currentDelegation['DEL_INDEX'], $nextDel['DEL_PRIORITY'], $delType, $iNewAppThreadIndex, $nextDel ); + $iMIDelIndex = $this->case->newAppDelegation( + $appFields['PRO_UID'], + $currentDelegation['APP_UID'], + $nextDel['TAS_UID'], + (isset( $aValue['USR_UID'] ) ? $aValue['USR_UID'] : ''), + $currentDelegation['DEL_INDEX'], + $nextDel['DEL_PRIORITY'], + $delType, + $iNewAppThreadIndex, + $nextDel, + $appFields['APP_NUMBER'], + $appFields['PRO_ID'], + $nextDel['TAS_ID'] + ); - $iNewThreadIndex = $this->case->newAppThread( $currentDelegation['APP_UID'], $iMIDelIndex, $iAppThreadIndex ); + $iNewThreadIndex = $this->case->newAppThread( $currentDelegation['APP_UID'], $iMIDelIndex, $iAppThreadIndex, $appFields['APP_NUMBER'] ); //Setting the del Index for Updating the AppThread delIndex if ($key == 0) { @@ -1358,7 +1372,23 @@ class Derivation $delPrevious = $row['DEL_PREVIOUS']; } // Create new delegation - $iNewDelIndex = $this->case->newAppDelegation( $appFields['PRO_UID'], $currentDelegation['APP_UID'], $nextDel['TAS_UID'], (isset( $nextDel['USR_UID'] ) ? $nextDel['USR_UID'] : ''), $currentDelegation['DEL_INDEX'], $nextDel['DEL_PRIORITY'], $delType, $iAppThreadIndex, $nextDel, $this->flagControl, $this->flagControlMulInstance, $delPrevious); + $iNewDelIndex = $this->case->newAppDelegation( + $appFields['PRO_UID'], + $currentDelegation['APP_UID'], + $nextDel['TAS_UID'], + (isset( $nextDel['USR_UID'] ) ? $nextDel['USR_UID'] : ''), + $currentDelegation['DEL_INDEX'], + $nextDel['DEL_PRIORITY'], + $delType, + $iAppThreadIndex, + $nextDel, + $this->flagControl, + $this->flagControlMulInstance, + $delPrevious, + $appFields['APP_NUMBER'], + $appFields['PRO_ID'], + $nextDel['TAS_ID'] + ); break; } @@ -1383,7 +1413,7 @@ class Derivation case 'PARALLEL-BY-EVALUATION': $this->case->closeAppThread( $currentDelegation['APP_UID'], $iAppThreadIndex ); $iNewThreadIndex = $this->case->newAppThread( $currentDelegation['APP_UID'], $iNewDelIndex, $iAppThreadIndex ); - $this->case->updateAppDelegation( $currentDelegation['APP_UID'], $iNewDelIndex, $iNewThreadIndex ); + $this->case->updateAppDelegation( $currentDelegation['APP_UID'], $iNewDelIndex, $iNewThreadIndex, $appFields['APP_NUMBER'] ); break; default: $this->case->updateAppThread( $currentDelegation['APP_UID'], $iAppThreadIndex, $iNewDelIndex ); diff --git a/workflow/engine/classes/class.wsTools.php b/workflow/engine/classes/class.wsTools.php index 9578ff25a..c2f3c0691 100644 --- a/workflow/engine/classes/class.wsTools.php +++ b/workflow/engine/classes/class.wsTools.php @@ -111,13 +111,6 @@ class workspaceTools $final = $stop - $start; CLI::logging("<*> Check Mafe Requirements Process took $final seconds.\n"); - $start = microtime(true); - CLI::logging("> Updating cache view...\n"); - $this->upgradeCacheView($buildCacheView, true, $lang); - $stop = microtime(true); - $final = $stop - $start; - CLI::logging("<*> Updating cache view Process took $final seconds.\n"); - $start = microtime(true); CLI::logging("> Backup log files...\n"); $this->backupLogFiles(); @@ -157,6 +150,12 @@ class workspaceTools $this->migrateSelfServiceRecordsRun($workSpace); $stop = microtime(true); CLI::logging("<*> Migrating Self-Service records Process took " . ($stop - $start) . " seconds.\n"); + + $start = microtime(true); + CLI::logging("> Migrating and populating indexing for APP_CACHE_VIEW...\n"); + $this->migratePopulateIndexingACV($workSpace); + $stop = microtime(true); + CLI::logging("<*> Migrating an populating indexing for APP_CACHE_VIEW process took " . ($stop - $start) . " seconds.\n"); } /** @@ -3502,4 +3501,142 @@ class workspaceTools CLI::logging(" Migrating Self-Service by Value Cases Done \n"); } + public function migratePopulateIndexingACV($workspace) { + // Migrating and populating new indexes + CLI::logging("-> Migrating And Populating Indexing for APP_CACHE_VIEW Start \n"); + + // Initializing + $this->initPropel(true); + $con = Propel::getConnection(AppDelegationPeer::DATABASE_NAME); + + // Populating APP_THREAD.APP_NUMBER + CLI::logging("-> Populating APP_THREAD.APP_NUMBER \n"); + $con->begin(); + $stmt = $con->createStatement(); + $rs = $stmt->executeQuery("UPDATE APP_THREAD AS AT + INNER JOIN ( + SELECT APPLICATION.APP_UID, APPLICATION.APP_NUMBER + FROM APPLICATION + ) AS APP + ON (AT.APP_UID = APP.APP_UID) + SET AT.APP_NUMBER = APP.APP_NUMBER + WHERE AT.APP_NUMBER = 0"); + $con->commit(); + + // Populating APP_THREAD.DELEGATION_ID + CLI::logging("-> Populating APP_THREAD.DELEGATION_ID \n"); + $con->begin(); + $stmt = $con->createStatement(); + $rs = $stmt->executeQuery("UPDATE APP_THREAD AS AT + INNER JOIN ( + SELECT APP_DELEGATION.APP_UID, APP_DELEGATION.DEL_INDEX, APP_DELEGATION.DELEGATION_ID + FROM APP_DELEGATION + ) AS APPDEL + ON (AT.APP_UID = APPDEL.APP_UID AND AT.DEL_INDEX = APPDEL.DEL_INDEX) + SET AT.DELEGATION_ID = APPDEL.DELEGATION_ID + WHERE AT.DELEGATION_ID = 0"); + $con->commit(); + + // Populating APP_DELAY.APP_NUMBER + CLI::logging("-> Populating APP_DELAY.APP_NUMBER \n"); + $con->begin(); + $stmt = $con->createStatement(); + $rs = $stmt->executeQuery("UPDATE APP_DELAY AS AD + INNER JOIN ( + SELECT APPLICATION.APP_UID, APPLICATION.APP_NUMBER + FROM APPLICATION + ) AS APP + ON (AD.APP_UID = APP.APP_UID) + SET AD.APP_NUMBER = APP.APP_NUMBER + WHERE AD.APP_NUMBER = 0"); + $con->commit(); + + // Populating APP_DELAY.DELEGATION_ID + CLI::logging("-> Populating APP_DELAY.DELEGATION_ID \n"); + $con->begin(); + $stmt = $con->createStatement(); + $rs = $stmt->executeQuery("UPDATE APP_DELAY AS AD + INNER JOIN ( + SELECT APP_DELEGATION.APP_UID, APP_DELEGATION.DEL_INDEX, APP_DELEGATION.DELEGATION_ID + FROM APP_DELEGATION + ) AS APPDEL + ON (AD.APP_UID = APPDEL.APP_UID AND AD.APP_DEL_INDEX = APPDEL.DEL_INDEX) + SET AD.DELEGATION_ID = APPDEL.DELEGATION_ID + WHERE AD.DELEGATION_ID = 0"); + $con->commit(); + + // Populating APP_DELEGATION.APP_NUMBER + CLI::logging("-> Populating APP_DELEGATION.APP_NUMBER \n"); + $con->begin(); + $stmt = $con->createStatement(); + $rs = $stmt->executeQuery("UPDATE APP_DELEGATION AS AD + INNER JOIN ( + SELECT APPLICATION.APP_UID, APPLICATION.APP_NUMBER + FROM APPLICATION + ) AS APP + ON (AD.APP_UID = APP.APP_UID) + SET AD.APP_NUMBER = APP.APP_NUMBER + WHERE AD.APP_NUMBER = 0"); + $con->commit(); + + // Populating APP_DELEGATION.USR_ID + CLI::logging("-> Populating APP_DELEGATION.USR_ID \n"); + $con->begin(); + $stmt = $con->createStatement(); + $rs = $stmt->executeQuery("UPDATE APP_DELEGATION AS AD + INNER JOIN ( + SELECT USERS.USR_UID, USERS.USR_ID + FROM USERS + ) AS USR + ON (AD.USR_UID = USR.USR_UID) + SET AD.USR_ID = USR.USR_ID + WHERE AD.USR_ID = 0"); + $con->commit(); + + // Populating APP_DELEGATION.PRO_ID + CLI::logging("-> Populating APP_DELEGATION.PRO_ID \n"); + $con->begin(); + $stmt = $con->createStatement(); + $rs = $stmt->executeQuery("UPDATE APP_DELEGATION AS AD + INNER JOIN ( + SELECT PROCESS.PRO_UID, PROCESS.PRO_ID + FROM PROCESS + ) AS PRO + ON (AD.PRO_UID = PRO.PRO_UID) + SET AD.PRO_ID = PRO.PRO_ID + WHERE AD.PRO_ID = 0"); + $con->commit(); + + // Populating APP_DELEGATION.TAS_ID + CLI::logging("-> Populating APP_DELEGATION.TAS_ID \n"); + $con->begin(); + $stmt = $con->createStatement(); + $rs = $stmt->executeQuery("UPDATE APP_DELEGATION AS AD + INNER JOIN ( + SELECT TASK.TAS_UID, TASK.TAS_ID + FROM TASK + ) AS TAS + ON (AD.TAS_UID = TAS.TAS_UID) + SET AD.TAS_ID = TAS.TAS_ID + WHERE AD.TAS_ID = 0"); + $con->commit(); + + // Populating APP_DELEGATION.TAS_ID + CLI::logging("-> Populating APPLICATION.APP_STATUS_ID \n"); + $con->begin(); + $stmt = $con->createStatement(); + $rs = $stmt->executeQuery("UPDATE APPLICATION + SET APP_STATUS_ID = (case + when APP_STATUS = 'DRAFT' then 1 + when APP_STATUS = 'TO_DO' then 2 + when APP_STATUS = 'COMPLETED' then 3 + when APP_STATUS = 'CANCELLED' then 4 + end) + WHERE APP_STATUS in ('DRAFT', 'TO_DO', 'COMPLETED', 'CANCELLED') AND + APP_STATUS_ID = 0"); + $con->commit(); + + CLI::logging("-> Migrating And Populating Indexing for APP_CACHE_VIEW Done \n"); + } + } diff --git a/workflow/engine/classes/model/AppDelegation.php b/workflow/engine/classes/model/AppDelegation.php index 7feeaa1df..21c1083fe 100644 --- a/workflow/engine/classes/model/AppDelegation.php +++ b/workflow/engine/classes/model/AppDelegation.php @@ -104,7 +104,7 @@ class AppDelegation extends BaseAppDelegation * @param $isSubprocess is a subprocess inside a process? * @return delegation index of the application delegation. */ - public function createAppDelegation ($sProUid, $sAppUid, $sTasUid, $sUsrUid, $sAppThread, $iPriority = 3, $isSubprocess = false, $sPrevious = -1, $sNextTasParam = null, $flagControl = false, $flagControlMulInstance = false, $delPrevious = 0) + public function createAppDelegation ($sProUid, $sAppUid, $sTasUid, $sUsrUid, $sAppThread, $iPriority = 3, $isSubprocess = false, $sPrevious = -1, $sNextTasParam = null, $flagControl = false, $flagControlMulInstance = false, $delPrevious = 0, $appNumber = 0, $taskId = 0, $userId = 0, $proId = 0) { if (! isset( $sProUid ) || strlen( $sProUid ) == 0) { throw (new Exception( 'Column "PRO_UID" cannot be null.' )); @@ -126,6 +126,7 @@ class AppDelegation extends BaseAppDelegation throw (new Exception( 'Column "APP_THREAD" cannot be null.' )); } + $this->delegation_id = null; //Get max DEL_INDEX $criteria = new Criteria("workflow"); $criteria->add(AppDelegationPeer::APP_UID, $sAppUid); @@ -196,6 +197,10 @@ class AppDelegation extends BaseAppDelegation $this->setDelThread( $sAppThread ); $this->setDelThreadStatus( 'OPEN' ); $this->setDelDelegateDate( 'now' ); + $this->setAppNumber($appNumber); + $this->setTasId($taskId); + $this->setUsrId($userId); + $this->setProId($proId); //The function return an array now. By JHL $delTaskDueDate = $this->calculateDueDate($sNextTasParam); diff --git a/workflow/engine/classes/model/AppThread.php b/workflow/engine/classes/model/AppThread.php index fe9cf57ae..ccae54598 100644 --- a/workflow/engine/classes/model/AppThread.php +++ b/workflow/engine/classes/model/AppThread.php @@ -40,7 +40,7 @@ */ class AppThread extends BaseAppThread { - public function createAppThread ($sAppUid, $iDelIndex, $iParent) + public function createAppThread ($sAppUid, $iDelIndex, $iParent, $appNumber = 0) { if (!isset($sAppUid) || strlen($sAppUid ) == 0 ) { throw ( new Exception ( 'Column "APP_UID" cannot be null.' ) ); @@ -68,6 +68,7 @@ class AppThread extends BaseAppThread $this->setAppThreadParent ( $iParent ); $this->setAppThreadStatus ( 'OPEN' ); $this->setDelIndex ( $iDelIndex ); + $this->setAppNumber($appNumber); if ($this->validate() ) { try {