You are here

xmlsitemap_term.install in XML sitemap 5

Same filename and directory in other branches
  1. 5.2 xmlsitemap_term/xmlsitemap_term.install

File

xmlsitemap_term/xmlsitemap_term.install
View source
<?php

/**
 * Implementation of hook_requirements().
 */
function xmlsitemap_term_requirements($phase) {
  $t = get_t();
  $requirements = array();
  if (in_array($GLOBALS['db_type'], array(
    'mysql',
    'mysqli',
  )) && version_compare(db_version(), '4.0.14') < 0) {
    $requirements['xmlsitemap_term_sql'] = array(
      'title' => $t('XML Sitemap: Term'),
      'value' => $t('Your MySQL version is too low. &ldquo;XML Sitemap: Term&rdquo; requires MySQL 4.0.14 or higher.'),
      'severity' => REQUIREMENT_ERROR,
    );
  }
  return $requirements;
}

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

/**
 * Implementation of hook_enable().
 */
function xmlsitemap_term_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_term'", ++$weight);
  }
  $query = "\n    INSERT INTO {xmlsitemap_term} (tid, last_changed)\n    SELECT td.tid, %d FROM {term_data} td\n    LEFT JOIN {xmlsitemap_term} xt ON xt.tid = td.tid\n    WHERE xt.tid IS NULL\n  ";
  db_query($query, time());
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("\n        UPDATE {xmlsitemap_term} xt INNER JOIN {url_alias} ua\n        ON ua.src = CONCAT('taxonomy/term/', CAST(xt.tid AS CHAR))\n        OR ua.src = CONCAT('forum/', CAST(xt.tid AS CHAR))\n        SET xt.pid = ua.pid\n        WHERE xt.pid IS NULL\n      ");
      break;
    case 'pgsql':
      db_query("\n        UPDATE {xmlsitemap_term}\n        SET pid = {url_alias}.pid\n        FROM {url_alias}\n        WHERE {url_alias}.src = CONCAT('taxonomy/term/', CAST(tid AS VARCHAR))\n        OR {url_alias}.src = CONCAT('forum/', CAST(tid AS VARCHAR))\n        AND {xmlsitemap_term}.pid IS NULL\n      ");
      break;
  }
  xmlsitemap_update_sitemap();
}

/**
 * Implementation of hook_disable().
 */
function xmlsitemap_term_disable() {
  xmlsitemap_update_sitemap();
}

/**
 * Implementation of hook_uninstall().
 */
function xmlsitemap_term_uninstall() {
  db_query("DROP TABLE {xmlsitemap_term}");
  $settings = db_query("SELECT name FROM {variable} WHERE name LIKE 'xmlsitemap\\_term\\_%'");
  while ($variable = db_fetch_object($settings)) {
    variable_del($variable->name);
  }
}

/**
 * Implementation of hook_update_N().
 * Add missing URL aliases.
 */
function xmlsitemap_term_update_1() {
  $ret = array(
    update_sql("UPDATE {xmlsitemap_term} SET pid = NULL WHERE pid = 0"),
  );
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("\n        UPDATE {xmlsitemap_term} xt, {url_alias} ua SET xt.pid = ua.pid\n        WHERE xt.pid IS NULL AND (\n          ua.src = CONCAT('taxonomy/term/', CAST(xt.tid AS CHAR))\n          OR ua.src = CONCAT('forum/', CAST(xt.tid AS CHAR))\n        )\n      ");
      break;
    case 'pgsql':
      $ret[] = update_sql("\n        UPDATE {xmlsitemap_term} SET pid = {url_alias}.pid FROM {url_alias}\n        WHERE {xmlsitemap_term}.pid IS NULL AND (\n          {url_alias}.src = CONCAT('taxonomy/term/', CAST(tid AS VARCHAR))\n          OR {url_alias}.src = CONCAT('forum/', CAST(tid AS VARCHAR))\n        )\n      ");
      break;
  }
  return $ret;
}

Functions

Namesort descending Description
xmlsitemap_term_disable Implementation of hook_disable().
xmlsitemap_term_enable Implementation of hook_enable().
xmlsitemap_term_install Implementation of hook_install().
xmlsitemap_term_requirements Implementation of hook_requirements().
xmlsitemap_term_uninstall Implementation of hook_uninstall().
xmlsitemap_term_update_1 Implementation of hook_update_N(). Add missing URL aliases.