This method correctly looks up the aliases for taxonomy terms. The LEFT JOIN was only working for forum and non-taxonomy module terms.

CommentFileSizeAuthor
xmlsitemap_term.patch2.17 KBnicholasthompson

Comments

marcoBauli’s picture

+1 for this patch

applies and fixes the terms alias issue also here

avpaderno’s picture

Status: Needs review » Reviewed & tested by the community
avpaderno’s picture

Priority: Normal » Critical
Status: Needs review » Needs work

I would rather prefer to use a single database query rather than two queries like in the patch (the second query is made from the function that returns the alias of the path), if that is possible.

I will check on that.

avpaderno’s picture

Priority: Critical » Normal
Status: Reviewed & tested by the community » Needs review
avpaderno’s picture

Priority: Critical » Normal

The following line should be changed:

  if ($alias !== FALSE) {
    $term->alias = $alias;
  }
$url = xmlsitemap_url("forum/$term->tid", $term->alias, NULL, NULL, TRUE);

$term->alias is used in the call to xmlsitemap_url() even it is not set (therefore PHP would report a property doesn't exist message error. Like the code is, there is no even the need to use such object property when it is possible to use the variable $alias.

avpaderno’s picture

Status: Needs work » Fixed

The code has been changed in CVS.
The function _xmlsitemap_term_links() has been rewritten like:

function _xmlsitemap_term_links($excludes = array()) {
  if (empty($excludes)) {
    $excludes = array(0);
  }
  $query_args = array_merge($excludes, array(_xmlsitemap_term_frontpage()));
  $result = db_query(db_rewrite_sql("SELECT t.tid, t.vid, v.module, xt.last_changed, xt.previously_changed, xt.priority_override
    FROM {term_data} t
    LEFT JOIN {vocabulary} v ON t.vid = v.vid
    LEFT JOIN {xmlsitemap_term} xt ON t.tid = xt.tid
    WHERE (t.vid NOT IN (". xmlsitemap_placeholders($excludes, 'int') .") AND xt.priority_override IS NULL OR xt.priority_override >= 0)
    AND t.tid <> %d
    GROUP BY t.tid, t.vid, v.module, xt.last_changed, xt.previously_changed, xt.priority_override", 't', 'tid'), $query_args
  );
  while ($term = db_fetch_object($result)) {
    if ($term->module == 'forum') {
      $path = "forum/$term->tid";
    }
    else {
      $path = taxonomy_term_path($term);
    }
    $alias = drupal_lookup_path('alias', $path);
    if ($alias === FALSE) {
      $alias = NULL;
    }
    $url = xmlsitemap_url($path, $alias, NULL, NULL, TRUE);
    $age = time() - $term->last_changed;
    $interval = empty($term->previously_changed) ? 0 : $term->last_changed - $term->previously_changed;
    db_query("INSERT INTO {xmlsitemap} (loc, lastmod, changefreq, priority) VALUES ('%s', %d, %d, %f)", $url, $term->last_changed, max($age, $interval), _xmlsitemap_term_priority($term));
  }
}

The code of the patch has been corrected, and optimized.

It's not possible to execute a single query, and at the same time get the alias for the taxonomy term for all the cases; the module code like it was before was already executing two separate queries (one was hidden in the call to the drupal function), so there isn't a lost of performance. The difference is that now the code is working like it should, and the alias of the terms are used whenever the term is relative to a forum, or not.

Like the usual, wait 12 hours, and you will get a new download file.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.