partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit 656e122dc4db183369c4e0afd704bf99633f3d57
parent d6a4bd5c60690c09d0ce47d15750c850669e3bde
Author: Felicitus <felicitus@felicitus.org>
Date:   Sat, 10 Oct 2015 18:38:50 +0200

Additional check for root nodes

Diffstat:
Msrc/PartKeepr/CategoryBundle/EventListener/RootCategoryListener.php | 14++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/PartKeepr/CategoryBundle/EventListener/RootCategoryListener.php b/src/PartKeepr/CategoryBundle/EventListener/RootCategoryListener.php @@ -15,10 +15,12 @@ class RootCategoryListener extends ContainerAware */ private $service; - public function __construct (Container $container, $service) { + public function __construct(Container $container, $service) + { $this->setContainer($container); $this->service = $service; } + /** * Checks that only one root category exists * @@ -43,11 +45,15 @@ class RootCategoryListener extends ContainerAware } } - protected function checkForRoot (AbstractCategory $category) { + protected function checkForRoot(AbstractCategory $category) + { if ($category->getParent() === null) { try { - $this->container->get($this->service)->getRootNode(); - throw new OnlySingleRootNodeAllowedException(); + $rootNode = $this->container->get($this->service)->getRootNode(); + + if ($rootNode->getId() != $category->getId()) { + throw new OnlySingleRootNodeAllowedException(); + } } catch (RootNodeNotFoundException $e) { }