Hello, i believe there is mistake in drupal_lookup_path() function, because if i have 2 aliases for the same node in different languages - in my lang and in LANGUAGE_NONE, then this function will first time after cache clear return an alias for my lang, but after that it will always return an alias of LANGUAGE_NONE.

You can reproduse this, by creating 2 aliases for same node - first in language 'en', second in language LANGUAGE_NONE. You need to clear cache, and then call drupal_lookup_path('alias', 'node/[your_node_id]', 'en'). This function will return to you alias in language 'en'. Refresh the page, and you will see, that the alias changed to LANGUAGE_NONE.

i'm sure this strange behaviour is because different logic used in drupal_lookup_path for first time, and later, when getting alias from cache. As you can see below, the ordering is totally reversed for some strange reason.

path.inc from line 108:

          if ($path_language == LANGUAGE_NONE) {
            // Prevent PDO from complaining about a token the query doesn't use.
            unset($args[':language']);
            $result = db_query('SELECT source, alias FROM {url_alias} WHERE source IN (:system) AND language = :language_none ORDER BY pid ASC', $args);
          }
          elseif ($path_language < LANGUAGE_NONE) {
            $result = db_query('SELECT source, alias FROM {url_alias} WHERE source IN (:system) AND language IN (:language, :language_none) ORDER BY language ASC, pid ASC', $args);
          }
          else {
            $result = db_query('SELECT source, alias FROM {url_alias} WHERE source IN (:system) AND language IN (:language, :language_none) ORDER BY language DESC, pid ASC', $args);
          }

but couple lines below the ordering is reversed
path.inc from line 142:

        // See the queries above.
        if ($path_language == LANGUAGE_NONE) {
          unset($args[':language']);
          $alias = db_query("SELECT alias FROM {url_alias} WHERE source = :source AND language = :language_none ORDER BY pid DESC", $args)->fetchField();
        }
        elseif ($path_language > LANGUAGE_NONE) {
          $alias = db_query("SELECT alias FROM {url_alias} WHERE source = :source AND language IN (:language, :language_none) ORDER BY language DESC, pid DESC", $args)->fetchField();
        }
        else {
          $alias = db_query("SELECT alias FROM {url_alias} WHERE source = :source AND language IN (:language, :language_none) ORDER BY language ASC, pid DESC", $args)->fetchField();
        }

CommentFileSizeAuthor
#1 2310559-path.inc_.patch1.58 KBmaximn
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

maximn’s picture

FileSize
1.58 KB

i think, the second variant is correct, so here is simple patch for that

er.pushpinderrana’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 1: 2310559-path.inc_.patch, failed testing.

Status: Needs work » Needs review

dcam queued 1: 2310559-path.inc_.patch for re-testing.

maximn’s picture

we need a review!

this is a very important problem for SEO and if not fixed it can hurt sites search engine rankings, because of incorrect path in pages 'canonical' metatag

dcam’s picture

Has Drupal 8 been checked for this issue? Normally I would check it myself, but I can't due to an installation bug on Windows.

drupal_lookup_path() is gone in D8. I think some or all of its functionality has been moved into the Path module. With the changes to the cache system and multilingual my guess is that this problem has been fixed, but that must be verified.