You are here

function xmlsitemap_term_cron in XML sitemap 5

Implementation of hook_cron().

Related topics

File

xmlsitemap_term/xmlsitemap_term.module, line 235
Adds terms to the site map.

Code

function xmlsitemap_term_cron() {
  if (db_result(db_query_range("SELECT COUNT(*) FROM {term_data} td LEFT JOIN {xmlsitemap_term} xt ON xt.tid = td.tid WHERE xt.tid IS NULL", 0, 1))) {
    $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':
        $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':
        $query = "\n          UPDATE {xmlsitemap_term}\n          SET pid = {url_alias}.pid\n          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;
    }
    db_query($query);
    xmlsitemap_update_sitemap();
  }
}