mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-12-08 12:09:30 +00:00
* Erweiterungstätigkeiten zur IPN-Vorschlagsliste anhand von Präfixen aus den Kategorien * Umstellung Migrationen bzgl. Multi-Plattform-Support. Zunächst MySQL, SQLite Statements integrieren. * Postgre Statements integrieren * SQL-Formatierung in Migration verbessern * Erweitere IPN-Suggest um Bauteilbeschreibung. Die Implementierung berücksichtigt nun zusätzlich die Bauteilbeschreibung zu maximal 150 Zeichen Länge für die Generierung von IPN-Vorschlägen und Inkrementen. * Anpassungen aus Analyse vornehmen * IPN-Validierung für Parts überarbeiten * IPN-Vorschlagslogik um Konfiguration erweitert * Anpassungen aus phpstan Analyse * IPN-Vorschlagslogik erweitert und Bauteil-IPN vereindeutigt Die IPN-Logik wurde um eine Konfiguration zur automatischen Suffix-Anfügung und die Berücksichtigung von doppelten Beschreibungen bei Bedarf ergänzt. Zudem wurde das Datenmodell angepasst, um eine eindeutige Speicherung der IPN zu gewährleisten. * Regex-Konfigurationsmöglichkeit für IPN-Vorschläge einführen Die Einstellungen für die IPN-Vorschlagslogik wurden um eine Regex-Validierung und eine Hilfetext-Konfiguration erweitert. Tests und Änderungen an den Formularoptionen wurden implementiert. * Match range assert and form limits in suggestPartDigits * Keep existing behavior with autoAppend suffix by default * Show the regex hint in the browser validation notice. * Improved translations * Removed unnecessary service definition * Removed german comments --------- Co-authored-by: Marcel Diegelmann <marcel.diegelmann@gmail.com> Co-authored-by: Jan Böhmer <mail@jan-boehmer.de>
55 lines
1.7 KiB
PHP
55 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Validator\Constraints;
|
|
|
|
use App\Entity\Parts\Part;
|
|
use App\Settings\MiscSettings\IpnSuggestSettings;
|
|
use Symfony\Component\Validator\Constraint;
|
|
use Symfony\Component\Validator\ConstraintValidator;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
class UniquePartIpnValidator extends ConstraintValidator
|
|
{
|
|
private EntityManagerInterface $entityManager;
|
|
private IpnSuggestSettings $ipnSuggestSettings;
|
|
|
|
public function __construct(EntityManagerInterface $entityManager, IpnSuggestSettings $ipnSuggestSettings)
|
|
{
|
|
$this->entityManager = $entityManager;
|
|
$this->ipnSuggestSettings = $ipnSuggestSettings;
|
|
}
|
|
|
|
public function validate($value, Constraint $constraint): void
|
|
{
|
|
if (null === $value || '' === $value) {
|
|
return;
|
|
}
|
|
|
|
//If the autoAppendSuffix option is enabled, the IPN becomes unique automatically later
|
|
if ($this->ipnSuggestSettings->autoAppendSuffix) {
|
|
return;
|
|
}
|
|
|
|
if (!$constraint instanceof UniquePartIpnConstraint) {
|
|
return;
|
|
}
|
|
|
|
/** @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()) {
|
|
$this->context->buildViolation($constraint->message)
|
|
->setParameter('{{ value }}', $value)
|
|
->addViolation();
|
|
}
|
|
}
|
|
}
|
|
}
|