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]
This commit is contained in:
Rodrigo Primo
2021-11-10 08:58:55 -03:00
committed by Veljko V
parent ea3b38bc08
commit ae99fe3be2
2 changed files with 6 additions and 2 deletions

View File

@@ -103,6 +103,10 @@ abstract class Repository {
$this->entityManager->flush(); $this->entityManager->flush();
} }
public function getReference($id) {
return $this->entityManager->getReference($this->getEntityClassName(), $id);
}
/** /**
* @param T $entity * @param T $entity
*/ */

View File

@@ -169,8 +169,8 @@ class Links {
continue; continue;
} }
$newsletter = $this->newslettersRepository->findOneById($newsletterId); $newsletter = $this->newslettersRepository->getReference($newsletterId);
$sendingQueue = $this->sendingQueueRepository->findOneById($queueId); $sendingQueue = $this->sendingQueueRepository->getReference($queueId);
if (!$newsletter instanceof NewsletterEntity || !$sendingQueue instanceof SendingQueueEntity) { if (!$newsletter instanceof NewsletterEntity || !$sendingQueue instanceof SendingQueueEntity) {
continue; continue;