public function rebuildPath($pk = null)
{
$fields = $this->getFields();
if (!\array_key_exists('alias', $fields) || !\array_key_exists('path', $fields)) {
return true;
}
$k = $this->_tbl_key;
$pk = \is_null($pk) ? $this->{$k} : $pk;
$query = $this->_db->getQuery(true)->select('p.alias')->from($this->_tbl . ' AS n, ' . $this->_tbl . ' AS p')->where('n.lft BETWEEN p.lft AND p.rgt')->where('n.' . $this->_tbl_key . ' = ' . (int) $pk)->order('p.lft');
$this->_db->setQuery($query);
$segments = $this->_db->loadColumn();
if ($segments[0] === 'root') {
array_shift($segments);
}
$path = trim(implode('/', $segments), ' /\\');
$query->clear()->update($this->_tbl)->set('path = ' . $this->_db->quote($path))->where($this->_tbl_key . ' = ' . (int) $pk);
$this->_db->setQuery($query)->execute();
$this->path = $path;
return true;
}