You are here

function xmlsitemap_node_cron in XML sitemap 5

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

Implementation of hook_cron().

Related topics

File

xmlsitemap_node/xmlsitemap_node.module, line 368
Adds nodes to the site map.

Code

function xmlsitemap_node_cron() {
  if (db_result(db_query_range("SELECT COUNT(*) FROM {node} n LEFT JOIN {xmlsitemap_node} xn ON xn.nid = n.nid WHERE xn.nid IS NULL", 0, 1))) {
    $query = "\n      INSERT INTO {xmlsitemap_node} (nid, last_changed, last_comment, previous_comment)\n      SELECT n.nid, n.changed, s.last_comment_timestamp, MAX(c.timestamp) FROM {node} n\n      LEFT JOIN {node_comment_statistics} s ON s.nid = n.nid\n      LEFT OUTER JOIN {comments} c ON c.nid = n.nid AND c.timestamp < s.last_comment_timestamp\n      LEFT JOIN {xmlsitemap_node} xn ON xn.nid = n.nid\n      WHERE xn.nid IS NULL\n      GROUP BY n.nid, n.changed, s.last_comment_timestamp\n    ";
    db_query($query);
    switch ($GLOBALS['db_type']) {
      case 'mysql':
      case 'mysqli':
        db_query("\n          UPDATE {xmlsitemap_node} xn INNER JOIN {url_alias} ua\n          ON ua.src = CONCAT('node/', CAST(xn.nid AS CHAR))\n          SET xn.pid = ua.pid\n          WHERE xn.pid IS NULL\n        ");
        break;
      case 'pgsql':
        db_query("\n          UPDATE {xmlsitemap_node}\n          SET pid = {url_alias}.pid\n          FROM {url_alias}\n          WHERE {url_alias}.src = CONCAT('node/', CAST(nid AS VARCHAR)) AND {xmlsitemap_node}.pid IS NULL\n        ");
        break;
    }
    xmlsitemap_update_sitemap();
  }
}