View source
<?php
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. “XML Sitemap: Term” requires MySQL 4.0.14 or higher.'),
'severity' => REQUIREMENT_ERROR,
);
}
return $requirements;
}
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;
}
}
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();
}
function xmlsitemap_term_disable() {
xmlsitemap_update_sitemap();
}
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);
}
}
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;
}