You are here

function votingapi_cron in Voting API 7.2

Same name and namespace in other branches
  1. 8.3 votingapi.module \votingapi_cron()
  2. 5 votingapi.module \votingapi_cron()
  3. 6.2 votingapi.module \votingapi_cron()
  4. 6 votingapi.module \votingapi_cron()
  5. 7.3 votingapi.module \votingapi_cron()

Implements of hook_cron().

Allows db-intensive recalculations to be deferred until cron-time.

File

./votingapi.module, line 119
A generalized voting API for Drupal.

Code

function votingapi_cron() {
  if (variable_get('votingapi_calculation_schedule', 'immediate') == 'cron') {
    $time = REQUEST_TIME;
    $last_cron = variable_get('votingapi_last_cron', 0);
    $result = db_query('SELECT DISTINCT entity_type, entity_id FROM {votingapi_vote} WHERE timestamp > :timestamp', array(
      ':timestamp' => $last_cron,
    ));
    foreach ($result as $content) {
      votingapi_recalculate_results($content->entity_type, $content->entity_id, TRUE);
    }
    variable_set('votingapi_last_cron', $time);
  }
  _votingapi_cron_delete_orphaned();
}