Skip to content

Commit 506b3c3

Browse files
committed
Only store changes that were done throug the admin backend
1 parent e235b25 commit 506b3c3

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/EntityListener/PaymentOrderChangedFieldsListener.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Doctrine\Bundle\DoctrineBundle\Attribute\AsEntityListener;
1111
use Doctrine\ORM\Event\PreUpdateEventArgs;
1212
use Symfony\Bundle\SecurityBundle\Security;
13+
use Symfony\Component\HttpFoundation\RequestStack;
1314

1415
#[AsEntityListener]
1516
class PaymentOrderChangedFieldsListener
@@ -43,7 +44,7 @@ class PaymentOrderChangedFieldsListener
4344
'bank_info.reference',
4445
];
4546

46-
public function __construct(private readonly Security $security)
47+
public function __construct(private readonly Security $security, private readonly RequestStack $requestStack)
4748
{
4849
}
4950

@@ -55,6 +56,11 @@ public function preUpdate(PaymentOrder $paymentOrder, PreUpdateEventArgs $eventA
5556
return;
5657
}
5758

59+
//Ensure that the change is done through the backend
60+
if (!$this->isBackendChange()) {
61+
return;
62+
}
63+
5864
$entity = $paymentOrder;
5965

6066
// get the changed fields
@@ -85,6 +91,17 @@ public function preUpdate(PaymentOrder $paymentOrder, PreUpdateEventArgs $eventA
8591
$eventArgs->getObjectManager()->getClassMetadata(PaymentOrder::class),
8692
$entity
8793
);
94+
}
95+
96+
/**
97+
* Check if the change is done through the backend
98+
* @return bool
99+
*/
100+
private function isBackendChange(): bool
101+
{
102+
$request = $this->requestStack->getCurrentRequest();
88103

104+
//The request must containn the backend path "/admin" to be considered a backend change
105+
return $request !== null && str_contains($request->getPathInfo(), '/admin');
89106
}
90107
}

0 commit comments

Comments
 (0)