You are here

function notify_admin_queue in Notify 7

Menu callback, show admin list of queue status.

2 string references to 'notify_admin_queue'
notify_admin_queue_submit in ./notify.admin.inc
Submit for the notify_admin_queue form.
notify_menu in ./notify.module
Implements hook_menu().

File

./notify.admin.inc, line 179
Administrative pages callbacks for the Notify module.

Code

function notify_admin_queue($form, &$form_state) {
  $period = variable_get('notify_period', 86400);
  $since = variable_get('notify_send_last', REQUEST_TIME - $period);
  $lastdate = format_date($since, 'short');
  $start = variable_get('notify_send_start', 0);
  $startdate = format_date($start, 'short');
  $notify_send_last = variable_get('notify_send_last', 0);
  $next_last = _notify_next_notificaton($notify_send_last);
  if ($next_last == -1) {
    $batch_msg = t('No more notifications scheduled');
  }
  elseif ($next_last == 0) {
    $batch_msg = t('The next notification is scheduled for the next cron run');
  }
  else {
    $next = format_date($next_last, 'short');
    $batch_msg = t('The next notification is scheduled for the first cron run after ') . $next;
  }
  $form = array();
  $form['process'] = array(
    '#type' => 'radios',
    '#title' => t('Notification queue operations'),
    '#default_value' => 0,
    '#options' => array(
      t('Send batch now'),
      t('Truncate queue'),
      t('Override timestamp'),
    ),
    '#description' => t('Select “Send batch now” to send next batch of e-mails queued for notifications. Select “Truncate queue” to empty queue of pending notification <em>without</em> sending e-mails. Select “Override timestamp” to override the last notification timestamp. Press “Submit” to execute.'),
  );
  $send_last = format_date($notify_send_last, 'custom', 'Y-m-d H:i:s');
  $form['lastdate'] = array(
    '#type' => 'textfield',
    '#title' => t('Last notification timestamp'),
    '#default_value' => $send_last,
    '#size' => 19,
    '#maxlength' => 19,
    '#description' => t('To explicitly set the last notification timestamp, change the value of this field and select the “Override timestamp” option above, then press “Submit” to execute.'),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );
  $form['batch'] = array(
    '#type' => 'fieldset',
    '#title' => t('Status'),
    '#collapsible' => TRUE,
  );
  list($np, $cp, $nn, $cn, $nu, $cu) = _notify_count();
  $npcp = $np + $cp;
  if ($npcp) {
    $queue_msg = t('Notifications about at least !item queued', array(
      '!item' => format_plural($npcp, '1 item is', '@count items are'),
    ));
  }
  else {
    $queue_msg = t('No notifications queued');
  }
  $flagcnt = count(variable_get('notify_skip_nodes', array())) + count(variable_get('notify_skip_comments', array()));
  if ($flagcnt) {
    $skip_msg = t('!item flagged for skipping', array(
      '!item' => format_plural($flagcnt, '1 item is', '@count items are'),
    ));
  }
  else {
    $skip_msg = t('No item is flagged for skipping');
  }
  if ($np && $nu || $cp && $cu) {
    $nonew_msg = '';
  }
  else {
    $nonew_msg = t(', no notification about unpublished items are queued');
  }
  if ($nu + $cu) {
    $unpub_msg = t('Unpublished: !nodeup and !commup', array(
      '!nodeup' => format_plural($nu, '1 node', '@count nodes'),
      '!commup' => format_plural($cu, '1 comment', '@count comments'),
    )) . $nonew_msg;
  }
  else {
    $unpub_msg = t('No unpublished items');
  }
  $sent = variable_get('notify_num_sent', 0);
  $fail = variable_get('notify_num_failed', 0);
  $batch_remain = count(variable_get('notify_users', array()));
  $creat_msg = t('There are !nodes and !comms !created', array(
    '!nodes' => format_plural($np, '1 node', '@count nodes'),
    '!comms' => format_plural($cp, '1 comment', '@count comments'),
    '!created' => variable_get('notify_include_updates', 0) ? t('updated') : t('created'),
  ));
  if ($nn + $cn) {
    $publ_msg = t(', and in addition !noderp and !commrp published,', array(
      '!noderp' => format_plural($nn, '1 node', '@count nodes'),
      '!commrp' => format_plural($cn, '1 comment', '@count comments'),
    ));
  }
  else {
    $publ_msg = '';
  }
  if ($batch_remain) {
    $intrv_msg = t('between !last and !start', array(
      '!last' => $lastdate,
      '!start' => $startdate,
    ));
    $sent_msg = t('Batch not yet complete.  So far !sent has been sent (!fail, !remain to go)', array(
      '!sent' => format_plural($sent, '1 e-mail', '@count e-mails'),
      '!fail' => format_plural($fail, '1 failure', '@count failures'),
      '!remain' => format_plural($batch_remain, '1 user', '@count users'),
    ));
  }
  else {
    $intrv_msg = t('since !last', array(
      '!last' => $lastdate,
    ));
    $sent_msg = t('Last batch:') . ' ';
    if ($sent == 0) {
      $sent_msg = t('No e-mails were sent');
    }
    else {
      $sent_msg .= t('sent !sent', array(
        '!sent' => format_plural($sent, '1 e-mail', '@count e-mails'),
      ));
    }
    if ($fail > 0) {
      $sent_msg .= ', ' . t('!fail', array(
        '!fail' => format_plural($fail, '1 failure', '@count failures'),
      ));
    }
    elseif ($sent) {
      $sent_msg .= ', ' . t('no failures');
    }
  }
  $mailsystem = variable_get('mail_system', NULL);
  $ms = isset($mailsystem['default-system']) ? $mailsystem['default-system'] : t('system default');
  $form['batch']['schedule'] = array(
    '#markup' => $creat_msg . $publ_msg . ' ' . $intrv_msg . '.<br>' . $unpub_msg . '.<br>' . $queue_msg . '.<br>' . $skip_msg . '.<br>' . $sent_msg . '.<br>' . $batch_msg . '.<br>' . t('Default MailSystem: !mailsystem.', array(
      '!mailsystem' => $ms,
    )),
  );
  return $form;
}