You are here

function _signup_cron_autoclose in Signup 7

Same name and namespace in other branches
  1. 5.2 signup.module \_signup_cron_autoclose()
  2. 6.2 includes/cron.inc \_signup_cron_autoclose()
  3. 6 includes/cron.inc \_signup_cron_autoclose()

Helper function that handles auto-closing time-based nodes during cron.

Loops over all the node types that are signup-enabled. For each one, it invokes the method for the installed event/date backend module to get the right query fragments, and builds a query to find all nodes of that type where signups should be closed (e.g. events that already started, etc).

See also

signup_cron()

signup_autoclose_sql()

_signup_build_query()

1 call to _signup_cron_autoclose()
signup_cron in ./signup.module
Implements hook_cron().

File

includes/cron.inc, line 95
Code required during regular cron runs.

Code

function _signup_cron_autoclose() {
  $type_autoclose_sql = array();
  foreach (signup_content_types() as $type) {
    $type_sql = signup_autoclose_sql($type);
    if (!empty($type_sql)) {
      $type_autoclose_sql[$type] = $type_sql;
    }
  }
  if (empty($type_autoclose_sql)) {

    // No node types support auto-close, so bail out now.
    return;
  }
  $autoclose_common_sql = array(
    'primary' => '{node} n',
    'fields' => array(
      'n.nid',
      'n.type',
    ),
    'where' => array(
      's.status = 1',
      "n.type = :type",
    ),
    'joins' => array(
      'INNER JOIN {signup} s ON s.nid = n.nid',
    ),
  );
  foreach ($type_autoclose_sql as $type => $autoclose_sql) {
    $sql = _signup_build_query($autoclose_common_sql, $autoclose_sql);

    // TODO Please convert this statement to the D7 database API syntax.
    $result = db_query($sql, array(
      ':type' => $type,
    ));

    // Loop through the results, calling the signup closing function.
    foreach ($result as $signup) {
      signup_close_signup($signup->nid, $cron = 'yes');
      $node = node_load($signup->nid);
      foreach (module_implements('signup_close') as $module) {
        $function = $module . '_signup_close';
        $function($node);
      }
      watchdog('signup', 'Signups closed for %title by cron.', array(
        '%title' => $node->title,
      ), WATCHDOG_NOTICE, l(t('view'), 'node/' . $node->nid));
    }
  }
}