PartKeepr\CategoryBundle\Services\CategoryService::ensureRootNodeExists PHP Method

ensureRootNodeExists() public method

Creates the root node for a tree if it doesn't exist.
    public function ensureRootNodeExists()
    {
        try {
            $this->getRootNode();
        } catch (RootNodeNotFoundException $e) {
            /**
             * @var AbstractCategory
             */
            $rootNode = new $this->entityClass();
            $rootNode->setName('Root Category');
            $this->entityManager->persist($rootNode);
            $this->entityManager->flush();
        }
    }