You are here

xmlsitemap_node.install in XML sitemap 5.2

Install file for XML sitemap node

File

xmlsitemap_node/xmlsitemap_node.install
View source
<?php

/**
 * @file
 * Install file for XML sitemap node
 */

/*****************************************************************************
 * Drupal hooks.
 ****************************************************************************/

/**
 * Implementation of hook_enable().
 */
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();
}

/**
 * Implementation of hook_disable().
 */
function xmlsitemap_node_disable() {
  xmlsitemap_flag_sitemap();
}

/**
 * Implementation of hook_install().
 */
function xmlsitemap_node_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {xmlsitemap_node} (\n        nid int,\n        last_changed int(11),\n        previously_changed int(11),\n        last_comment int(11),\n        previous_comment int(11),\n        priority_override float,\n        PRIMARY KEY (nid)\n      ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      break;
    case 'pgsql':
      db_query("CREATE TABLE {xmlsitemap_node} (\n        nid integer,\n        last_changed integer,\n        previously_changed integer,\n        last_comment integer,\n        previous_comment integer,\n        priority_override real,\n        PRIMARY KEY (nid)\n      );");
      break;
  }
}

/**
 * Implementation of hook_update_N().
 */
function xmlsitemap_node_update_4() {
  return array();
}

/**
 * Implementation of hook_update_N().
 */
function xmlsitemap_node_update_5() {
  $result = @update_sql("ALTER TABLE {xmlsitemap_node} DROP pid");
  if ($result['success']) {
    $ret[] = $result;
  }
  return $ret;
}

/**
 * Implementation of hook_uninstall().
 */
function xmlsitemap_node_uninstall() {
  db_query("DROP TABLE {xmlsitemap_node}");
  db_query("DELETE FROM {variable} WHERE name LIKE 'xmlsitemap\\_node\\_%'");
}

Functions

Namesort descending Description
xmlsitemap_node_disable Implementation of hook_disable().
xmlsitemap_node_enable Implementation of hook_enable().
xmlsitemap_node_install Implementation of hook_install().
xmlsitemap_node_uninstall Implementation of hook_uninstall().
xmlsitemap_node_update_4 Implementation of hook_update_N().
xmlsitemap_node_update_5 Implementation of hook_update_N().