From 2b51b2f2094d3170f9727e6eba02cd3cdae9a2b5 Mon Sep 17 00:00:00 2001 From: Amine Ben hammou Date: Mon, 9 Sep 2019 19:24:08 +0100 Subject: [PATCH] Check parent exists before returning it [MAILPOET-2350] --- lib/Entities/NewsletterEntity.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/Entities/NewsletterEntity.php b/lib/Entities/NewsletterEntity.php index 19a154dc3b..9d63f05e69 100644 --- a/lib/Entities/NewsletterEntity.php +++ b/lib/Entities/NewsletterEntity.php @@ -9,6 +9,7 @@ use MailPoet\Doctrine\EntityTraits\DeletedAtTrait; use MailPoet\Doctrine\EntityTraits\UpdatedAtTrait; use MailPoetVendor\Doctrine\Common\Collections\ArrayCollection; use MailPoetVendor\Doctrine\Common\Collections\Collection; +use MailPoetVendor\Doctrine\ORM\EntityNotFoundException; use MailPoetVendor\Doctrine\ORM\Mapping\Column; /** @@ -310,7 +311,14 @@ class NewsletterEntity { * @return NewsletterEntity|null */ function getParent() { - return $this->parent; + try { + if ($this->parent && $this->parent->getId()) { + return $this->parent; + } + } catch (EntityNotFoundException $enf) { + $this->setParent(null); + return null; + } } /**