You are here

function xmlsitemap_node_enable in XML sitemap 5.2

Same name and namespace in other branches
  1. 5 xmlsitemap_node/xmlsitemap_node.install \xmlsitemap_node_enable()
  2. 6 xmlsitemap_node/xmlsitemap_node.install \xmlsitemap_node_enable()

Implementation of hook_enable().

File

xmlsitemap_node/xmlsitemap_node.install, line 15
Install file for XML sitemap node

Code

function xmlsitemap_node_enable() {
  $weight = db_result(db_query("SELECT weight FROM {system} WHERE type = 'module' AND name = 'pathauto'"));
  if ($weight !== FALSE) {
    db_query("UPDATE {system} SET weight = %d WHERE type = 'module' AND name = 'xmlsitemap_node'", ++$weight);
  }
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("\n        UPDATE {xmlsitemap_node} xn INNER JOIN {node} n ON xn.nid = n.nid LEFT JOIN {node_comment_statistics} s ON xn.nid = s.nid\n        SET xn.previously_changed = xn.last_changed, xn.last_changed = n.changed, xn.last_comment = s.last_comment_timestamp\n        WHERE xn.nid = n.nid AND (xn.last_changed <> n.changed OR xn.last_comment <> s.last_comment_timestamp)\n      ");
      break;
    case 'pgsql':
      db_query("\n        UPDATE {xmlsitemap_node} SET previously_changed = last_changed, last_changed = changed, last_comment = last_comment_timestamp\n        FROM {node} LEFT JOIN {node_comment_statistics} ON {node}.nid = {node_comment_statistics}.nid\n        WHERE {xmlsitemap_node}.nid = {node}.nid AND (last_changed <> changed OR last_comment <> last_comment_timestamp)\n      ");
      break;
  }
  db_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 n.nid = s.nid\n    LEFT OUTER JOIN {comments} c ON n.nid = c.nid AND c.timestamp < s.last_comment_timestamp\n    LEFT JOIN {xmlsitemap_node} xn ON n.nid = xn.nid\n    WHERE xn.nid IS NULL\n    GROUP BY n.nid, n.changed, s.last_comment_timestamp\n  ");
  xmlsitemap_flag_sitemap();
}