You are here

function xmlsitemap_node_cron in XML sitemap 6

Same name and namespace in other branches
  1. 5 xmlsitemap_node/xmlsitemap_node.module \xmlsitemap_node_cron()
  2. 6.2 xmlsitemap_node/xmlsitemap_node.module \xmlsitemap_node_cron()
  3. 7.2 xmlsitemap_node/xmlsitemap_node.module \xmlsitemap_node_cron()

Implementation of hook_cron().

File

xmlsitemap_node/xmlsitemap_node.module, line 64
Adds nodes to the sitemap.

Code

function xmlsitemap_node_cron() {
  if (($limit = variable_get('xmlsitemap_cron_limit', 100)) != -1) {
    $sql = "SELECT n.* FROM {node} n\n      LEFT JOIN {xmlsitemap_node} xn ON xn.nid = n.nid\n      WHERE xn.nid IS NULL\n        AND n.status = 1";
    $result = db_query_range($sql, 0, $limit);
    $sitemap_changed = FALSE;
    while ($node = db_fetch_object($result)) {
      if (module_exists('comment')) {
        $maxcomments = (int) db_result(db_query('SELECT MAX(comment_count) FROM {node_comment_statistics}'));
        $comments = (int) db_result(db_query('SELECT comment_count
          FROM {node_comment_statistics}
          WHERE nid = %d', $node->nid));
      }
      else {
        $maxcomments = 0;
      }
      $row = new stdClass();
      $row->nid = $node->nid;
      $row->changed = $node->changed;
      $row->previously_changed = $node->created;
      if ($maxcomments > 1) {
        $row->comment_ratio = $comments / $maxcomments;
      }
      drupal_write_record('xmlsitemap_node', $row);
      $sitemap_changed = TRUE;
    }
    if ($sitemap_changed) {
      xmlsitemap_flag_sitemap();
    }
  }
}