/** * @param EmailModel $model * @param Email $email */ protected function persistAttachments(EmailModel $model, Email $email) { /** @var EmailAttachmentModel $emailAttachmentModel */ foreach ($model->getAttachments() as $emailAttachmentModel) { $attachment = $emailAttachmentModel->getEmailAttachment(); if (!$attachment->getId()) { $this->getEntityManager()->persist($attachment); } else { $attachmentContent = clone $attachment->getContent(); $attachment = clone $attachment; $attachment->setContent($attachmentContent); $this->getEntityManager()->persist($attachment); } $email->getEmailBody()->addAttachment($attachment); $attachment->setEmailBody($email->getEmailBody()); } }