public static function fetchByPath($uriString, $glob = false)
 {
     $uriString = eZURLAliasML::cleanURL($uriString);
     $db = eZDB::instance();
     if ($uriString == '' && $glob !== false) {
         $elements = array();
     } else {
         $elements = explode('/', $uriString);
     }
     $len = count($elements);
     $i = 0;
     $selects = array();
     $tables = array();
     $conds = array();
     $prevTable = false;
     foreach ($elements as $element) {
         $table = "e" . $i;
         $langMask = trim(eZContentLanguage::languagesSQLFilter($table, 'lang_mask'));
         if ($glob === false && $i == $len - 1) {
             $selects[] = eZURLAliasML::generateFullSelect($table);
         } else {
             $selects[] = eZURLAliasML::generateSelect($table, $i, $len);
         }
         $tables[] = "ezurlalias_ml " . $table;
         $conds[] = eZURLAliasML::generateCond($table, $prevTable, $i, $langMask, $element);
         $prevTable = $table;
         ++$i;
     }
     if ($glob !== false) {
         ++$len;
         $table = "e" . $i;
         $langMask = trim(eZContentLanguage::languagesSQLFilter($table, 'lang_mask'));
         $selects[] = eZURLAliasML::generateFullSelect($table);
         $tables[] = "ezurlalias_ml " . $table;
         $conds[] = eZURLAliasML::generateGlobCond($table, $prevTable, $i, $langMask, $glob);
         $prevTable = $table;
         ++$i;
     }
     $elementOffset = $i - 1;
     $query = "SELECT DISTINCT " . join(", ", $selects) . " FROM " . join(", ", $tables) . " WHERE " . join(" AND ", $conds);
     $pathRows = $db->arrayQuery($query);
     $elements = array();
     if (count($pathRows) > 0) {
         foreach ($pathRows as $pathRow) {
             $redirectLink = false;
             $table = "e" . $elementOffset;
             $element = array('id' => $pathRow[$table . "_id"], 'parent' => $pathRow[$table . "_parent"], 'lang_mask' => $pathRow[$table . "_lang_mask"], 'text' => $pathRow[$table . "_text"], 'action' => $pathRow[$table . "_action"], 'link' => $pathRow[$table . "_link"]);
             $path = array();
             $lastID = false;
             for ($i = 0; $i < $len; ++$i) {
                 $table = "e" . $i;
                 $id = $pathRow[$table . "_id"];
                 $link = $pathRow[$table . "_link"];
                 $path[] = $pathRow[$table . "_text"];
                 if ($link != $id) {
                     // Mark the redirect link
                     $redirectLink = $link;
                     $redirectOffset = $i;
                 }
                 $lastID = $link;
             }
             if ($redirectLink) {
                 $newLinkID = $redirectLink;
                 // Resolve new links until a real element is found.
                 // TODO: Add max redirection count?
                 while ($newLinkID) {
                     $query = "SELECT id, parent, lang_mask, text, link FROM ezurlalias_ml WHERE id={$newLinkID}";
                     $rows = $db->arrayQuery($query);
                     if (count($rows) == 0) {
                         return false;
                     }
                     $newLinkID = false;
                     if ($rows[0]['id'] != $rows[0]['link']) {
                         $newLinkID = (int) $rows[0]['link'];
                     }
                 }
                 $id = (int) $newLinkID;
                 $path = array();
                 // Fetch path 'text' elements of correct parent path
                 while ($id != 0) {
                     $query = "SELECT parent, lang_mask, text FROM ezurlalias_ml WHERE id={$id}";
                     $rows = $db->arrayQuery($query);
                     if (count($rows) == 0) {
                         break;
                     }
                     $result = eZURLAliasML::choosePrioritizedRow($rows);
                     if (!$result) {
                         $result = $rows[0];
                     }
                     $id = (int) $result['parent'];
                     array_unshift($path, $result['text']);
                 }
                 // Fill in end of path elements
                 for ($i = $redirectOffset; $i < $len; ++$i) {
                     $table = "e" . $i;
                     $path[] = $pathRow[$table . "_text"];
                 }
             }
             $element['path'] = implode('/', $path);
             $elements[] = $element;
         }
     }
     $rows = array();
     $ids = array();
     // Discard duplicates
     foreach ($elements as $element) {
         $id = (int) $element['id'];
         if (isset($ids[$id])) {
             continue;
         }
         $ids[$id] = true;
         $rows[] = $element;
     }
     $objectList = eZPersistentObject::handleRows($rows, 'eZURLAliasML', true);
     return $objectList;
 }