You are here

xmlsitemap_user.install in XML sitemap 5

File

xmlsitemap_user/xmlsitemap_user.install
View source
<?php

/**
 * Implementation of hook_requirements().
 */
function xmlsitemap_user_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_user_sql'] = array(
      'title' => $t('XML Sitemap: User'),
      'value' => $t('Your MySQL version is too low. &ldquo;XML Sitemap: User&rdquo; requires MySQL 4.0.14 or higher.'),
      'severity' => REQUIREMENT_ERROR,
    );
  }
  return $requirements;
}

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

/**
 * Implementation of hook_enable().
 */
function xmlsitemap_user_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_user'", ++$weight);
  }
  db_query("\n    INSERT INTO {xmlsitemap_user} (uid, last_changed)\n    SELECT u.uid, u.created FROM {users} u\n    LEFT JOIN {xmlsitemap_user} xu ON xu.uid = u.uid\n    WHERE u.uid <> 0 AND xu.uid IS NULL\n  ");
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("\n        UPDATE {xmlsitemap_user} xu INNER JOIN {url_alias} ua\n        ON ua.src = CONCAT('user/', CAST(xu.uid AS CHAR))\n        SET xu.pid = ua.pid\n        WHERE xu.pid IS NULL\n      ");
      break;
    case 'pgsql':
      db_query("\n        UPDATE {xmlsitemap_user}\n        SET pid = {url_alias}.pid\n        FROM {url_alias}\n        WHERE {url_alias}.src = CONCAT('user/', CAST(uid AS VARCHAR)) AND {xmlsitemap_user}.pid IS NULL\n      ");
      break;
  }
  db_query("\n    INSERT INTO {xmlsitemap_user_role} (rid)\n    SELECT r.rid FROM {role} r\n    LEFT JOIN {xmlsitemap_user_role} xur ON xur.rid = r.rid\n    WHERE r.rid > 2 AND xur.rid IS NULL\n  ");
  xmlsitemap_update_sitemap();
}

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

/**
 * Implementation of hook_uninstall().
 */
function xmlsitemap_user_uninstall() {
  db_query("DROP TABLE {xmlsitemap_user}");
  db_query("DROP TABLE {xmlsitemap_user_role}");
}

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

Functions

Namesort descending Description
xmlsitemap_user_disable Implementation of hook_disable().
xmlsitemap_user_enable Implementation of hook_enable().
xmlsitemap_user_install Implementation of hook_install().
xmlsitemap_user_requirements Implementation of hook_requirements().
xmlsitemap_user_uninstall Implementation of hook_uninstall().
xmlsitemap_user_update_1 Implementation of hook_update_N(). Add missing URL aliases.