From 451a9dbc102b5839877a0cac5a364f59544a2083 Mon Sep 17 00:00:00 2001 From: Raivis Strogonovs Date: Wed, 18 Aug 2021 15:39:55 +0100 Subject: [PATCH] fixed an import bug, where importing footprints was adding multiple directories instead of one parent directory --- .../CategoryBundle/Entity/AbstractCategory.php | 7 +++++++ .../FootprintBundle/Entity/FootprintCategory.php | 10 ++++++++++ .../SetupBundle/Services/FootprintSetupService.php | 5 ++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/PartKeepr/CategoryBundle/Entity/AbstractCategory.php b/src/PartKeepr/CategoryBundle/Entity/AbstractCategory.php index 5dd840d53..35ddedd5f 100644 --- a/src/PartKeepr/CategoryBundle/Entity/AbstractCategory.php +++ b/src/PartKeepr/CategoryBundle/Entity/AbstractCategory.php @@ -26,6 +26,13 @@ abstract class AbstractCategory extends BaseEntity */ protected $parent; + /** + * @ORM\OneToMany(targetEntity="FootprintCategory", mappedBy="parent") + * @ORM\OrderBy({"lft" = "ASC"}) + * @Groups({"tree"}) + */ + protected $children; + /** * The "left" property of the nested set. * diff --git a/src/PartKeepr/FootprintBundle/Entity/FootprintCategory.php b/src/PartKeepr/FootprintBundle/Entity/FootprintCategory.php index 36e7211df..3a19a658f 100644 --- a/src/PartKeepr/FootprintBundle/Entity/FootprintCategory.php +++ b/src/PartKeepr/FootprintBundle/Entity/FootprintCategory.php @@ -88,6 +88,16 @@ public function getChildren() return $this->children->getValues(); } + /** + * Adds a child to the list + * + * @return ArrayCollection + */ + public function addChild( $child ) + { + $this->children->add( $child ); + } + /** * Returns the category path. * diff --git a/src/PartKeepr/SetupBundle/Services/FootprintSetupService.php b/src/PartKeepr/SetupBundle/Services/FootprintSetupService.php index b1a4328be..1c9ee0fe9 100644 --- a/src/PartKeepr/SetupBundle/Services/FootprintSetupService.php +++ b/src/PartKeepr/SetupBundle/Services/FootprintSetupService.php @@ -131,6 +131,8 @@ protected function addFootprintCategoryPath(array $path, FootprintCategory $pare $category = null; + + foreach ($parentNode->getChildren() as $child) { if ($child->getName() == $name) { $category = $child; @@ -141,10 +143,11 @@ protected function addFootprintCategoryPath(array $path, FootprintCategory $pare $category = new FootprintCategory(); $category->setParent($parentNode); $category->setName($name); - $parentNode->getChildren()[] = $category; + $parentNode->addChild($category); $this->entityManager->persist($category); } + return $this->addFootprintCategoryPath($path, $category); }