Skip to content
Snippets Groups Projects
Commit 505dc8be authored by Tim Steiner's avatar Tim Steiner
Browse files

Rewrite a query that MySQL was processing eratically into something that works.

parent ff8b88c2
No related branches found
No related tags found
No related merge requests found
......@@ -180,8 +180,55 @@ class Requests_ApprovalActionModel extends Unl_Model
$select->where('r.requestId = ?', $requestId);
}
$select->order('currentState');
$records = $select->query()->fetchAll();
//$records = $select->query()->fetchAll();
if (Unl_Util::isArray($requestId)) {
$requestIdSql = $db->quoteInto(' r.requestId IN (?) ', $requestId);
} else {
$requestIdSql = $db->quoteInto(' r.requestId = ? ', $requestId);
}
$sql = 'SELECT r.requestId, l.nextAction, currentState '
. 'FROM creqRequests AS r '
. 'INNER JOIN creqRequestStacks AS s '
. ' ON r.stackPointer = s.requestStackId '
. 'INNER JOIN creqApprovalLinks AS l '
. ' ON s.chain = l.chain '
. 'WHERE ( '
. ' s.action = l.currentAction '
. ') AND ( '
. ' r.state = l.currentState '
. ' OR ( '
. ' l.currentState IS NULL '
. ' ) '
. ') AND ( '
. $requestIdSql
. ') '
. 'UNION '
. 'SELECT r.requestId, l.nextAction, currentState '
. 'FROM creqRequests AS r '
. 'INNER JOIN creqRequestStacks AS s '
. ' ON r.stackPointer = s.requestStackId '
. 'INNER JOIN creqApprovalLinks AS l '
. ' ON s.chain = l.chain '
. 'WHERE ( '
. ' s.action IS NULL '
. ' AND '
. ' l.currentAction IS NULL '
. ') AND ( '
. ' r.state = l.currentState '
. ' OR ( '
. ' l.currentState IS NULL '
. ' ) '
. ') AND ( '
. $requestIdSql
. ') '
. 'ORDER BY `currentState` ASC ';
$records = $db->query($sql)->fetchAll();
$approvalActionIds = array();
$requestActions = array();
foreach($records as $record) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment