Vestnik system events

Vestnik2 min readPage 11 of 12
On this page 3

Vestnik registers three MODX system events. Subscribe to them with a regular plugin to cancel sending, add data or keep your own statistics without changing the component code.

A plugin returns a signal like this: $modx->event->output('prevent');. In OnVestnikBeforeQueue the values prevent, defer, cancel, false cancel queuing of the whole event. In OnVestnikBeforeSend cancel cancels the email, while prevent, defer, false postpone it.

EventWhenParametersWhat for
OnVestnikBeforeQueueIn trigger(), before the event’s emails are queued — once for the whole event.eventKey, source, data (by reference)Cancel by a condition or add template data.
OnVestnikBeforeSendWhile processing the queue, before each email.queue, queueIdprevent — the email stays in the queue and is checked again after vestnik_retry_delay, no attempt is used (“quiet hours”); cancel — to the log with the “Cancelled” status.
OnVestnikAfterSendAfter a sending attempt (successful or not); not fired for postponed and cancelled emails.queueId, success, result, error, attempts, logId, mailStatistics, logging, webhooks.

Example 1. OnVestnikBeforeQueue

// Do not queue test orders
if ($eventKey === 'shop.order.new' && !empty($data['is_test'])) {
    $modx->event->output('prevent'); // cancel the whole event
    return;
}

// Add template data (data is passed by reference) — the template gets [[+shop_name]]
$modx->event->params['data']['shop_name'] = 'My shop';

Example 2. OnVestnikBeforeSend

$to = $queue->get('to_email');

if (in_array($to, ['blocked@example.com'], true)) {
    $modx->event->output('cancel'); // to the log with the “Cancelled” status
}

// Quiet hours: the email stays in the queue and is checked later
if ((int)date('G') < 8) {
    $modx->event->output('prevent');
}

Example 3. OnVestnikAfterSend

$result — sent, failed or retry; $logId — the log record id (0 on retry); $mail — a copy of the email as an array.

$text = $success ? 'sent' : 'error: ' . $error;
$modx->log($modx::LOG_LEVEL_ERROR, "Vestnik: {$mail['to_email']} — {$text}");

Do not confuse these events with the rule’s event key (shop.order.new): the key decides which email to send, while OnVestnik* decide how Vestnik processes it.