mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-01-15 22:59:33 +00:00
IPN-Validierung für Parts überarbeiten
This commit is contained in:
parent
c7bc912326
commit
3100c83246
1 changed files with 20 additions and 7 deletions
|
|
@ -24,14 +24,27 @@ class UniquePartIpnValidator extends ConstraintValidator
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$repository = $this->entityManager->getRepository(Part::class);
|
if (!$this->enforceUniqueIpn) {
|
||||||
$existingPart = $repository->findOneBy(['ipn' => $value]);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ($existingPart) {
|
/** @var Part $currentPart */
|
||||||
if ($this->enforceUniqueIpn) {
|
$currentPart = $this->context->getObject();
|
||||||
$this->context->buildViolation($constraint->message)
|
|
||||||
->setParameter('{{ value }}', $value)
|
if (!$currentPart instanceof Part) {
|
||||||
->addViolation();
|
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