From 718e0b5c1ee14a911256cfc5aacaabf526b492af Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Wed, 31 Aug 2022 13:18:21 +0200 Subject: [PATCH] prevent accidental invoice template updates (#3493) --- src/Invoice/ServiceInvoice.php | 3 +++ src/Repository/InvoiceRepository.php | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/Invoice/ServiceInvoice.php b/src/Invoice/ServiceInvoice.php index 09f6e064..daeedcf1 100644 --- a/src/Invoice/ServiceInvoice.php +++ b/src/Invoice/ServiceInvoice.php @@ -465,6 +465,9 @@ final class ServiceInvoice throw new \Exception('Cannot create invoice model without template'); } + // prevent that changes on the template will be persisted + $this->invoiceRepository->preventTemplateUpdate($template); + if (null === $template->getLanguage()) { $template->setLanguage(Constants::DEFAULT_LOCALE); @trigger_error('Using invoice templates without a language is is deprecated and trigger and will throw an exception with 2.0', E_USER_DEPRECATED); diff --git a/src/Repository/InvoiceRepository.php b/src/Repository/InvoiceRepository.php index 23677090..9b1365c8 100644 --- a/src/Repository/InvoiceRepository.php +++ b/src/Repository/InvoiceRepository.php @@ -12,6 +12,7 @@ namespace App\Repository; use App\Entity\Customer; use App\Entity\Invoice; use App\Entity\InvoiceMeta; +use App\Entity\InvoiceTemplate; use App\Entity\Team; use App\Entity\User; use App\Repository\Loader\InvoiceLoader; @@ -29,6 +30,17 @@ class InvoiceRepository extends EntityRepository { use RepositorySearchTrait; + /** + * @param InvoiceTemplate $invoiceTemplate + * @return void + * @deprecated replace me in 2.0 + */ + public function preventTemplateUpdate(InvoiceTemplate $invoiceTemplate): void + { + $em = $this->getEntityManager(); + $em->detach($invoiceTemplate); + } + public function saveInvoice(Invoice $invoice) { $entityManager = $this->getEntityManager();