MT-177: migrate counters method refactored.
This commit is contained in:
@@ -2436,16 +2436,77 @@ class workspaceTools
|
||||
public function migrateCounters()
|
||||
{
|
||||
$this->initPropel(true);
|
||||
// Updating the COMPLETE, DRAFT, INBOX, CANCELLED, PARTICIPATED counters
|
||||
$query = '
|
||||
UPDATE '.$this->dbName.'.USERS UA
|
||||
INNER JOIN
|
||||
(SELECT
|
||||
U.USR_UID,
|
||||
IFNULL(APP_INBOX, 0) USR_TOTAL_INBOX,
|
||||
IFNULL(APP_DRAFT, 0) USR_TOTAL_DRAFT,
|
||||
IFNULL(NEW_USR_TOTAL_CANCELED, 0) USR_TOTAL_CANCELLED,
|
||||
IFNULL(NEW_USR_TOTAL_PARTICIPATED_LAST, 0) USR_TOTAL_PARTICIPATED,
|
||||
0 USR_TOTAL_PAUSED,
|
||||
IFNULL(NEW_USR_TOTAL_COMPLETED, 0) USR_TOTAL_COMPLETED,
|
||||
0 USR_TOTAL_UNASSIGNED
|
||||
|
||||
FROM
|
||||
'.$this->dbName.'.USERS U
|
||||
LEFT JOIN
|
||||
(SELECT
|
||||
USR_UID, COUNT(APP_UID) NEW_USR_TOTAL_PARTICIPATED_LAST
|
||||
FROM
|
||||
'.$this->dbName.'.LIST_PARTICIPATED_LAST
|
||||
GROUP BY USR_UID) LPL ON U.USR_UID = LPL.USR_UID
|
||||
LEFT JOIN
|
||||
(SELECT
|
||||
USR_UID, COUNT(APP_UID) NEW_USR_TOTAL_COMPLETED
|
||||
FROM
|
||||
'.$this->dbName.'.LIST_COMPLETED
|
||||
GROUP BY USR_UID) LCO ON U.USR_UID = LCO.USR_UID
|
||||
LEFT JOIN
|
||||
(SELECT
|
||||
USR_UID, COUNT(DISTINCT APP_UID) APP_INBOX
|
||||
FROM
|
||||
'.$this->dbName.'.APP_CACHE_VIEW
|
||||
WHERE
|
||||
APP_STATUS = \'TO_DO\'
|
||||
AND APP_THREAD_STATUS = \'OPEN\'
|
||||
AND DEL_THREAD_STATUS = \'OPEN\'
|
||||
AND DEL_FINISH_DATE IS NULL
|
||||
GROUP BY USR_UID) APP_IN ON U.USR_UID = APP_IN.USR_UID
|
||||
LEFT JOIN
|
||||
(SELECT
|
||||
USR_UID, COUNT(DISTINCT APP_UID) APP_DRAFT
|
||||
FROM
|
||||
'.$this->dbName.'.APP_CACHE_VIEW
|
||||
WHERE
|
||||
APP_STATUS = \'DRAFT\'
|
||||
AND APP_THREAD_STATUS = \'OPEN\'
|
||||
AND DEL_THREAD_STATUS = \'OPEN\'
|
||||
GROUP BY USR_UID) APP_D ON U.USR_UID = APP_D.USR_UID
|
||||
LEFT JOIN
|
||||
(SELECT
|
||||
USR_UID, COUNT(APP_UID) NEW_USR_TOTAL_CANCELED
|
||||
FROM
|
||||
'.$this->dbName.'.LIST_CANCELED
|
||||
GROUP BY USR_UID) LCA ON U.USR_UID = LCA.USR_UID
|
||||
) UC
|
||||
ON UA.USR_UID = UC.USR_UID
|
||||
SET
|
||||
UA.USR_TOTAL_INBOX = UC.USR_TOTAL_INBOX,
|
||||
UA.USR_TOTAL_DRAFT = UC.USR_TOTAL_DRAFT,
|
||||
UA.USR_TOTAL_CANCELLED = UC.USR_TOTAL_CANCELLED,
|
||||
UA.USR_TOTAL_PARTICIPATED = UC.USR_TOTAL_PARTICIPATED,
|
||||
UA.USR_TOTAL_COMPLETED = UC.USR_TOTAL_COMPLETED';
|
||||
$con = Propel::getConnection("workflow");
|
||||
$stmt = $con->createStatement();
|
||||
$stmt->executeQuery($query);
|
||||
// Updating PAUSED and UNASSIGNED Cases
|
||||
$aTypes = array(
|
||||
'to_do',
|
||||
'draft',
|
||||
'cancelled',
|
||||
'sent',
|
||||
'paused',
|
||||
'completed',
|
||||
'selfservice'
|
||||
);
|
||||
|
||||
$users = new Users();
|
||||
$criteria = new Criteria();
|
||||
$criteria->addSelectColumn(UsersPeer::USR_UID);
|
||||
@@ -2456,14 +2517,9 @@ class workspaceTools
|
||||
$oAppCache = new AppCacheView();
|
||||
$aCount = $oAppCache->getAllCounters($aTypes, $aRow['USR_UID'], false);
|
||||
$newData = array(
|
||||
'USR_UID' => $aRow['USR_UID'],
|
||||
'USR_TOTAL_INBOX' => $aCount['to_do'],
|
||||
'USR_TOTAL_DRAFT' => $aCount['draft'],
|
||||
'USR_TOTAL_CANCELLED' => $aCount['cancelled'],
|
||||
'USR_TOTAL_PARTICIPATED' => $aCount['sent'],
|
||||
'USR_TOTAL_PAUSED' => $aCount['paused'],
|
||||
'USR_TOTAL_COMPLETED' => $aCount['completed'],
|
||||
'USR_TOTAL_UNASSIGNED' => $aCount['selfservice']
|
||||
'USR_UID' => $aRow['USR_UID'],
|
||||
'USR_TOTAL_PAUSED' => $aCount['paused'],
|
||||
'USR_TOTAL_UNASSIGNED' => $aCount['selfservice']
|
||||
);
|
||||
$users->update($newData);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user