public function rebuildTable() { $c = new Criteria(); $this->del($c); $categoryModel = Model::factoryInstance($this->categoryModelName); $categoryPrimaryKey = $categoryModel->getPrimaryKey(); $categories = $categoryModel->findAll($c, $categoryPrimaryKey . "," . $this->categoryParentKey); $tree = new NavigationTree(); foreach ($categories as $category) { $tree->addNode($category[$categoryPrimaryKey], $category[$this->categoryParentKey]); } $connections = $tree->getAllConnections(); foreach ($connections as $connection) { $this->addNode($connection['parentCategoryId'], $connection['categoryId']); } }
function createUrlNames() { $withParents = Config::get('advancedUrlRewritingParentsEnabled'); set_time_limit(600); $categories = $this->category->findAll(null, "categoryId, parentCategoryId, name, urlName"); $tree = new NavigationTree(); foreach ($categories as $category) { $tree->addNode($category['categoryId'], $category['parentCategoryId'], array("name" => $category['name'], "urlName" => $category['urlName'])); } $connections = $tree->getAllConnections(); $urlNames = array(""); foreach ($connections as $connection) { $urlName = NameTool::strToAscii($connection['value']['name']); if ($withParents) { $urlName = ltrim($urlNames[$connection['depth'] - 1] . "\\" . $urlName, "\\"); $urlNames[$connection['depth']] = $urlName; } $urlName = $this->category->getFreeUrlName($urlName, $connection['categoryId']); if ($connection['value']['urlName'] && $connection['value']['urlName'] != $urlName && !$this->rewrite->findByPk($connection['value']['urlName'])) { $rewrite = new RewriteRecord(); $rewrite->originalUrl = $connection['value']['urlName']; $rewrite->rewrittedUrl = $urlName; $rewrite->save(); } $this->category->updateByPk(array("urlName" => $urlName), $connection['categoryId']); } }