mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-01-11 04:39:33 +00:00
IPN-Validierung für Parts überarbeiten
This commit is contained in:
parent
ff00ae98db
commit
b823d7d613
1 changed files with 20 additions and 7 deletions
|
|
@ -24,14 +24,27 @@ class UniquePartIpnValidator extends ConstraintValidator
|
|||
return;
|
||||
}
|
||||
|
||||
$repository = $this->entityManager->getRepository(Part::class);
|
||||
$existingPart = $repository->findOneBy(['ipn' => $value]);
|
||||
if (!$this->enforceUniqueIpn) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($existingPart) {
|
||||
if ($this->enforceUniqueIpn) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $value)
|
||||
->addViolation();
|
||||
/** @var Part $currentPart */
|
||||
$currentPart = $this->context->getObject();
|
||||
|
||||
if (!$currentPart instanceof Part) {
|
||||
return;
|
||||
}
|
||||
|
||||
$repository = $this->entityManager->getRepository(Part::class);
|
||||
$existingParts = $repository->findBy(['ipn' => $value]);
|
||||
|
||||
foreach ($existingParts as $existingPart) {
|
||||
if ($currentPart->getId() !== $existingPart->getId()) {
|
||||
if ($this->enforceUniqueIpn) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('{{ value }}', $value)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue