/** * Sends notifications already stored in the DB by send_later() * @access public * @return bool */ function send_stored() { global $db; // First we get the messages in chronological order... $sql = $db->x->getAll('SELECT message_id, message_data FROM {notification_messages} ORDER BY time_created DESC'); if (!count($sql)) { return true; } $stmt_rec = $db->prepare('SELECT nr.user_id, u.notify_type, u.notify_own, u.email_address, u.jabber_id, u.notify_blacklist FROM {notification_recipients} nr LEFT JOIN {users} u ON nr.user_id = u.user_id WHERE message_id = ?', array('integer'), MDB2_PREPARE_RESULT); $stmt_del_rec = $db->x->autoPrepare('{notification_recipients}', null, MDB2_AUTOQUERY_DELETE, 'message_id = ?'); $stmt_del_messages = $db->x->autoPrepare('{notification_messages}', null, MDB2_AUTOQUERY_DELETE, 'message_id = ?'); foreach ($sql as $row) { $data = unserialize($row['message_data']); $result_rec = $stmt_rec->execute($row['message_id']); $emails = array(); $jids = array(); foreach ($result_rec->fetchAll() as $msg) { Notifications::add_to_list($emails, $jids, $msg, $data['notify_type']); } if (Notifications::send_now(array($emails, $jids), ADDRESS_DONE, 0, $row)) { $stmt_del_rec->execute($row['message_id']); $stmt_del_messages->execute($row['message_id']); } } foreach (array('stmt_rec', 'stmt_del_rec', 'stmt_del_messages') as $stmt) { ${$stmt}->free(); } }
$closed[] = sprintf("%s#%d: %s (%s)\n-> %s %s (%s)", $project['project_prefix'], $row['prefix_id'], $row['item_summary'], $row['resolution_name'], L('openedby'), $row['real_name'], $row['user_name']); break; case '13': $reopened[] = sprintf("%s#%d: %s\n-> %s %s (%s)", $project['project_prefix'], $row['prefix_id'], $row['item_summary'], L('reopenedby'), $row['real_name'], $row['user_name']); break; case '19': $assigned[] = sprintf("%s#%d: %s\n-> %s %s (%s)", $project['project_prefix'], $row['prefix_id'], $row['item_summary'], L('assignedto'), $row['real_name'], $row['user_name']); break; } } foreach (array('opened', 'closed', 'reopened', 'assigned') as $type) { if (count(${$type})) { $message .= L($type . 'tasks') . ':' . "\n" . implode("\n", ${$type}) . "\n\n"; } } if (Notifications::send_now($pms, ADDRESS_USER, NOTIFY_DIGEST, array('message' => $message))) { $db->x->execParam('UPDATE {projects} SET last_digest = ? WHERE project_id = ?', array(time(), $project['project_id'])); } } ############ Task four: Close tasks ############ $tasks = $db->query('SELECT t.*, c.date_added, max(c.date_added) FROM {tasks} t LEFT JOIN {comments} c ON t.task_id = c.task_id WHERE is_closed = 0 AND close_after > 0 GROUP BY t.task_id'); while ($row = $tasks->FetchRow()) { if (max($row['date_added'], $row['last_edited_time']) + $row['close_after'] < time()) { Backend::close_task($row['task_id'], $row['resolution_reason'], $row['closure_comment'], false); $db->x->execParam('UPDATE {tasks} SET close_after = 0 WHERE task_id = ?', $row['task_id']); } } //wait 10 minutes for the next loop.