From ae99fe3be201d82d6f78f5cccc647104f57d3d21 Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Wed, 10 Nov 2021 08:58:55 -0300 Subject: [PATCH] Use Doctrine references when saving links This commit changes the code of the method \MailPoet\Newsletter\Links\Links::save() to use Doctrine references instead of full entities when getting a newsletter and sending queue entities to save the related links. We don't need the full entities here, and getting a full entity for the sending queue was generating an error in the testItLogsErrorWhenNewlyRenderedNewsletterBodyIsInvalid() integration test (see the description of PR https://github.com/mailpoet/mailpoet/pull/3784 for more details). To be able to get the reference, it was necessary to add a helper method called getReference() to \MailPoet\Doctrine\Repository. [MAILPOET-3816] --- lib/Doctrine/Repository.php | 4 ++++ lib/Newsletter/Links/Links.php | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/Repository.php b/lib/Doctrine/Repository.php index 14b167db41..2879badf38 100644 --- a/lib/Doctrine/Repository.php +++ b/lib/Doctrine/Repository.php @@ -103,6 +103,10 @@ abstract class Repository { $this->entityManager->flush(); } + public function getReference($id) { + return $this->entityManager->getReference($this->getEntityClassName(), $id); + } + /** * @param T $entity */ diff --git a/lib/Newsletter/Links/Links.php b/lib/Newsletter/Links/Links.php index 5853bae2a9..8cc29a52c2 100644 --- a/lib/Newsletter/Links/Links.php +++ b/lib/Newsletter/Links/Links.php @@ -169,8 +169,8 @@ class Links { continue; } - $newsletter = $this->newslettersRepository->findOneById($newsletterId); - $sendingQueue = $this->sendingQueueRepository->findOneById($queueId); + $newsletter = $this->newslettersRepository->getReference($newsletterId); + $sendingQueue = $this->sendingQueueRepository->getReference($queueId); if (!$newsletter instanceof NewsletterEntity || !$sendingQueue instanceof SendingQueueEntity) { continue;