/** * Enter description here... * [TODO] Move this into a better API holding place * * @param integer $group_id * @param integer $ticket_id * @param integer $only_rule_id * @return Model_GroupInboxFilter[]|false */ public static function runGroupRouting($group_id, $ticket_id, $only_rule_id = 0) { static $moveMap = array(); $dont_move = false; if (false != ($matches = Model_GroupInboxFilter::getMatches($group_id, $ticket_id, $only_rule_id))) { /* @var $match Model_GroupInboxFilter */ if (is_array($matches)) { foreach ($matches as $idx => $match) { /* =============== Prevent recursive assignments ============= * If we ever get into a situation where many rules are sending a ticket * back and forth between them, ignore the last move action in the chain * which is trying to start over. */ if (isset($match->actions['move'])) { if (!isset($moveMap[$ticket_id])) { $moveMap[$ticket_id] = array(); } else { if (isset($moveMap[$ticket_id][$group_id])) { $dont_move = true; } } $moveMap[$ticket_id][$group_id] = $match->id; } // Stop any move actions if we're going to loop again if ($dont_move) { unset($matches[$idx]->actions['move']); } // Run filter actions $match->run(array($ticket_id)); } } } return $matches; }
/** * @param array * @param array * @return boolean * [TODO] Find a better home for this? */ function doBulkUpdate($filter, $filter_param, $data, $do, $ticket_ids = array()) { @set_time_limit(600); // Make sure we have checked items if we want a checked list if (0 == strcasecmp($filter, "checks") && empty($ticket_ids)) { return; } $rule = new Model_GroupInboxFilter(); $rule->actions = $do; $params = $this->params; if (empty($filter)) { $data[] = '*'; // All, just to permit a loop in foreach($data ...) } switch ($filter) { default: case 'subject': case 'sender': case 'header': if (is_array($data)) { foreach ($data as $v) { $new_params = array(); $do_header = null; switch ($filter) { case 'subject': $new_params = array(new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_SUBJECT, DevblocksSearchCriteria::OPER_LIKE, $v)); $do_header = 'subject'; $ticket_ids = array(); break; case 'sender': $new_params = array(new DevblocksSearchCriteria(SearchFields_Ticket::SENDER_ADDRESS, DevblocksSearchCriteria::OPER_LIKE, $v)); $do_header = 'from'; $ticket_ids = array(); break; case 'header': $new_params = array(new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_MESSAGE_HEADER, DevblocksSearchCriteria::OPER_EQ, $filter_param), new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_MESSAGE_HEADER_VALUE, DevblocksSearchCriteria::OPER_EQ, $v)); $ticket_ids = array(); break; } $new_params = array_merge($new_params, $params); $pg = 0; if (empty($ticket_ids)) { do { list($tickets, $null) = DAO_Ticket::search(array(), $new_params, 100, $pg++, SearchFields_Ticket::TICKET_ID, true, false); $ticket_ids = array_merge($ticket_ids, array_keys($tickets)); } while (!empty($tickets)); } $batch_total = count($ticket_ids); for ($x = 0; $x <= $batch_total; $x += 200) { $batch_ids = array_slice($ticket_ids, $x, 200); $rule->run($batch_ids); unset($batch_ids); } } } break; } unset($ticket_ids); }