Prevent duplicate manufacturer parties
This commit is contained in:
1 parent
19ce29c3d0
commit
e43b5d34e0
3 files changed
+7
-1
No files matched your search
@@ -11,6 +11,7 @@ Diese Referenz ordnet die aktuellen Tabellen, Views und technischen DB-Artefakte
|
||||
### `kontakte`
|
||||
|
||||
- `party`
|
||||
- `party_role`
|
||||
- `address`
|
||||
- `contact`
|
||||
- `party_external_identity`
|
||||
|
||||
@@ -14,6 +14,7 @@ Zentraler Kontaktstamm fuer Kunden, Lieferanten und sonstige Parteien.
|
||||
## Writes
|
||||
|
||||
- Kontaktstamm
|
||||
- Herstellerrollen im Parteien-Stamm
|
||||
- Adressen
|
||||
- Kommunikationsdaten
|
||||
|
||||
|
||||
@@ -138,7 +138,6 @@ function create_manufacturer(PDO $pdo, string $name, ?string $email = null, ?str
|
||||
$existingStmt = $pdo->prepare(
|
||||
"SELECT p.id, p.name, p.email, p.phone
|
||||
FROM party p
|
||||
INNER JOIN party_role pr ON pr.party_id = p.id AND pr.role_code = 'manufacturer'
|
||||
WHERE LOWER(TRIM(p.name)) = LOWER(:name)
|
||||
LIMIT 1
|
||||
FOR UPDATE"
|
||||
@@ -146,6 +145,11 @@ function create_manufacturer(PDO $pdo, string $name, ?string $email = null, ?str
|
||||
$existingStmt->execute([':name' => $name]);
|
||||
$existing = $existingStmt->fetch();
|
||||
if (is_array($existing)) {
|
||||
$roleStmt = $pdo->prepare(
|
||||
"INSERT INTO party_role (party_id, role_code) VALUES (:party_id, 'manufacturer')
|
||||
ON CONFLICT (party_id, role_code) DO NOTHING"
|
||||
);
|
||||
$roleStmt->execute([':party_id' => (int) $existing['id']]);
|
||||
return [
|
||||
'id' => (int) $existing['id'],
|
||||
'name' => (string) $existing['name'],
|
||||
|
||||
Reference in new issue
Block a user