You are here

function poll_cron in Drupal 7

Same name and namespace in other branches
  1. 4 modules/poll.module \poll_cron()
  2. 5 modules/poll/poll.module \poll_cron()
  3. 6 modules/poll/poll.module \poll_cron()

Implements hook_cron().

Closes polls that have exceeded their allowed runtime.

File

modules/poll/poll.module, line 174
Enables your site to capture votes on different topics in the form of multiple choice questions.

Code

function poll_cron() {
  $nids = db_query('SELECT p.nid FROM {poll} p INNER JOIN {node} n ON p.nid = n.nid WHERE (n.created + p.runtime) < :request_time AND p.active = :active AND p.runtime <> :runtime', array(
    ':request_time' => REQUEST_TIME,
    ':active' => 1,
    ':runtime' => 0,
  ))
    ->fetchCol();
  if (!empty($nids)) {
    db_update('poll')
      ->fields(array(
      'active' => 0,
    ))
      ->condition('nid', $nids, 'IN')
      ->execute();
  }
}