function library_cron in Library 7
Same name and namespace in other branches
- 8 library.module \library_cron()
- 5.2 library.module \library_cron()
- 6.2 library.module \library_cron()
- 6 library.module \library_cron()
Implements hook_cron().
1 string reference to 'library_cron'
- library_uninstall in ./library.install 
- Implements hook_uninstall().
File
- ./library.module, line 1210 
Code
function library_cron() {
  $last_update = variable_get('library_cron', 0);
  $next_update = $last_update + 24 * 60 * 60;
  if (REQUEST_TIME > $next_update && library_duedates_enabled() && variable_get('library_send_automatic_email', 0) == 1) {
    $records = library_get_overdue_items();
    if (!empty($records)) {
      $num_emails = 0;
      foreach ($records as $patron_id => $record) {
        foreach ($record['items'] as $id => $item) {
          if ($last_update >= $item['due_date']) {
            unset($record['items'][$id]);
          }
        }
        $params = $record;
        if (count($record['items']) >= 1) {
          drupal_mail('library', 'notify_overdue', $params['patron']['patron_email'], language_default(), $params);
        }
        $num_emails++;
      }
      watchdog('library', '%number overdue email notifications sent successfully.', array(
        '%number' => $num_emails,
      ));
    }
    variable_set('library_cron', REQUEST_TIME);
  }
}