You are here

function notify_cron in Notify 8

Same name and namespace in other branches
  1. 5.2 notify.module \notify_cron()
  2. 5 notify.module \notify_cron()
  3. 6 notify.module \notify_cron()
  4. 7 notify.module \notify_cron()
  5. 2.0.x notify.module \notify_cron()
  6. 1.0.x notify.module \notify_cron()

Implements hook_cron().

File

./notify.module, line 51
Notify module sends e-mail digests of new content and comments.

Code

function notify_cron() {
  $config = \Drupal::config('notify.settings');
  $period = $config
    ->get("notify_period");
  if (-2 == $period) {
    return;
  }
  if (-1 == $period) {

    // Never notify.
    return;
  }
  $send_last = $config
    ->get('notify_send_last');
  $cron_next = $config
    ->get('notify_cron_next');
  $doitp = $config
    ->get('notify_users');
  if ($period >= 86400) {
    if ($doitp || $cron_next < \Drupal::time()
      ->getRequestTime()) {
      $doitp = TRUE;
    }
    else {
      return;
    }
  }
  $next = _notify_next_notificaton($send_last);
  if (\Drupal::time()
    ->getRequestTime() > $next || $doitp) {
    list($num_sent, $num_fail) = _notify_send();
    $num_sent += $config
      ->get('notify_num_sent');
    $num_fail += $config
      ->get('notify_num_failed');
    $next = _notify_next_notificaton(\Drupal::time()
      ->getRequestTime());
    \Drupal::configFactory()
      ->getEditable('notify.settings')
      ->set('notify_num_sent', $num_sent)
      ->set('notify_num_failed', $num_fail)
      ->set('notify_cron_next', $next)
      ->save();
  }
}