function activity_process_queue()
{
    if ($toprocess = get_records_array('activity_queue')) {
        // Hack to avoid duplicate watchlist notifications on the same view
        $watchlist = activity_locate_typerecord('watchlist');
        $viewsnotified = array();
        foreach ($toprocess as $activity) {
            $data = unserialize($activity->data);
            if ($activity->type == $watchlist->id && !empty($data->view)) {
                if (isset($viewsnotified[$data->view])) {
                    continue;
                }
                $viewsnotified[$data->view] = true;
            }
            try {
                $last_processed_userid = handle_activity($activity->type, $data, true, $activity);
            } catch (MaharaException $e) {
                // Exceptions can happen while processing the queue, we just
                // log them and continue
                log_debug($e->getMessage());
            }
            // Update the activity queue
            // or Remove this activity from the queue if all the users get processed
            // to make sure we
            // never send duplicate emails even if part of the
            // activity handler fails for whatever reason
            if (!empty($last_processed_userid)) {
                update_record('activity_queue', array('last_processed_userid' => $last_processed_userid), array('id' => $activity->id));
            } else {
                if (!delete_records('activity_queue', 'id', $activity->id)) {
                    log_warn("Unable to remove activity {$activity->id} from the queue. Skipping it.");
                }
            }
        }
    }
}
Esempio n. 2
0
function activity_process_queue()
{
    db_begin();
    if ($toprocess = get_records_array('activity_queue')) {
        // Hack to avoid duplicate watchlist notifications on the same view
        $watchlist = activity_locate_typerecord('watchlist');
        $viewsnotified = array();
        foreach ($toprocess as $activity) {
            $data = unserialize($activity->data);
            if ($activity->type == $watchlist->id && !empty($data->view)) {
                if (isset($viewsnotified[$data->view])) {
                    continue;
                }
                $viewsnotified[$data->view] = true;
            }
            try {
                handle_activity($activity->type, $data, true);
            } catch (MaharaException $e) {
                // Exceptions can happen while processing the queue, we just
                // log them and continue
                log_debug($e->getMessage());
            }
        }
        delete_records('activity_queue');
    }
    db_commit();
}