From a3af55d4e221b0c6f27ef8c043960d101380423e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Wed, 13 May 2020 21:07:50 +0200 Subject: [PATCH] Clone parameters if part is cloned. Fixed issue #46 --- src/Entity/Base/AbstractStructuralDBElement.php | 13 +++++++++++++ src/Entity/Parts/Part.php | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/src/Entity/Base/AbstractStructuralDBElement.php b/src/Entity/Base/AbstractStructuralDBElement.php index 4ef2ab6d..2cb8506d 100644 --- a/src/Entity/Base/AbstractStructuralDBElement.php +++ b/src/Entity/Base/AbstractStructuralDBElement.php @@ -107,6 +107,19 @@ abstract class AbstractStructuralDBElement extends AttachmentContainingDBElement $this->parameters = new ArrayCollection(); } + public function __clone() + { + if ($this->id) { + //Deep clone parameters + $parameters = $this->parameters; + $this->parameters = new ArrayCollection(); + foreach ($parameters as $parameter) { + $this->addParameter(clone $parameter); + } + } + parent::__clone(); + } + /****************************************************************************** * StructuralDBElement constructor. *****************************************************************************/ diff --git a/src/Entity/Parts/Part.php b/src/Entity/Parts/Part.php index 3bfc3195..7501ff27 100644 --- a/src/Entity/Parts/Part.php +++ b/src/Entity/Parts/Part.php @@ -165,6 +165,13 @@ class Part extends AttachmentContainingDBElement foreach ($orderdetails as $orderdetail) { $this->addOrderdetail(clone $orderdetail); } + + //Deep clone parameters + $parameters = $this->parameters; + $this->parameters = new ArrayCollection(); + foreach ($parameters as $parameter) { + $this->addParameter(clone $parameter); + } } parent::__clone(); }