You are here

function _notify_next_notificaton in Notify 8

Same name and namespace in other branches
  1. 7 notify.module \_notify_next_notificaton()
  2. 2.0.x notify.module \_notify_next_notificaton()
  3. 1.0.x notify.module \_notify_next_notificaton()

Compute the next time a notification should be sent.

Parameters

int $send_last: timestamp of last notification

Return value

int -1 never, 0 send instantly, else next time to notify.

2 calls to _notify_next_notificaton()
notify_cron in ./notify.module
Implements hook_cron().
QueueForm::buildForm in src/Form/QueueForm.php
Form constructor.

File

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

Code

function _notify_next_notificaton($send_last) {
  $config = \Drupal::config('notify.settings');
  $period = $config
    ->get('notify_period');

  // Two special cases: Never and instantly.
  if ($period < 0) {
    return -1;
  }
  elseif (!$period) {
    return 0;
  }
  $next_time_to_send = $send_last + $period;
  if ($period < 86400) {
    if (\Drupal::time()
      ->getRequestTime() >= $next_time_to_send) {
      return 0;
    }
    else {
      return $next_time_to_send;
    }
  }

  // Interval >= 1 day.
  $cron_next = $config
    ->get('notify_cron_next');
  if (!$cron_next) {
    $cron_next = _notify_cron_next($next_time_to_send);

    //    $config->set('notify_cron_next', $cron_next);
    \Drupal::configFactory()
      ->getEditable('notify.settings')
      ->set('notify_cron_next', $cron_next)
      ->save();
  }
  return $cron_next;
}