fix urlExists method: returns a bool and ignore nodes with alias and or a disabled url

This commit is contained in:
Simon Vieille 2021-10-06 10:24:42 +02:00
parent e4216c8974
commit 2e86ee338c
1 changed files with 4 additions and 2 deletions

View File

@ -13,11 +13,13 @@ class NodeRepository extends NestedTreeRepository
parent::__construct($manager, $manager->getClassMetadata(Node::class));
}
public function urlExists($url, Node $node)
public function urlExists($url, Node $node): bool
{
$query = $this->createQueryBuilder('n')
->join('n.menu', 'm')
->where('n.url = :url')
->andWhere('n.disableUrl = 0')
->andWhere('n.aliasNode is null')
->andWhere('m.navigation = :navigation')
->setParameter(':url', $url)
->setParameter(':navigation', $node->getMenu()->getNavigation())
@ -32,7 +34,7 @@ class NodeRepository extends NestedTreeRepository
return $query->getQuery()
->setMaxResults(1)
->getOneOrNullResult()
->getOneOrNullResult() !== null
;
}
}