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`
|
### `kontakte`
|
||||||
|
|
||||||
- `party`
|
- `party`
|
||||||
|
- `party_role`
|
||||||
- `address`
|
- `address`
|
||||||
- `contact`
|
- `contact`
|
||||||
- `party_external_identity`
|
- `party_external_identity`
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ Zentraler Kontaktstamm fuer Kunden, Lieferanten und sonstige Parteien.
|
|||||||
## Writes
|
## Writes
|
||||||
|
|
||||||
- Kontaktstamm
|
- Kontaktstamm
|
||||||
|
- Herstellerrollen im Parteien-Stamm
|
||||||
- Adressen
|
- Adressen
|
||||||
- Kommunikationsdaten
|
- Kommunikationsdaten
|
||||||
|
|
||||||
|
|||||||
@@ -138,7 +138,6 @@ function create_manufacturer(PDO $pdo, string $name, ?string $email = null, ?str
|
|||||||
$existingStmt = $pdo->prepare(
|
$existingStmt = $pdo->prepare(
|
||||||
"SELECT p.id, p.name, p.email, p.phone
|
"SELECT p.id, p.name, p.email, p.phone
|
||||||
FROM party p
|
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)
|
WHERE LOWER(TRIM(p.name)) = LOWER(:name)
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
FOR UPDATE"
|
FOR UPDATE"
|
||||||
@@ -146,6 +145,11 @@ function create_manufacturer(PDO $pdo, string $name, ?string $email = null, ?str
|
|||||||
$existingStmt->execute([':name' => $name]);
|
$existingStmt->execute([':name' => $name]);
|
||||||
$existing = $existingStmt->fetch();
|
$existing = $existingStmt->fetch();
|
||||||
if (is_array($existing)) {
|
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 [
|
return [
|
||||||
'id' => (int) $existing['id'],
|
'id' => (int) $existing['id'],
|
||||||
'name' => (string) $existing['name'],
|
'name' => (string) $existing['name'],
|
||||||
|
|||||||
Reference in new issue
Block a user