Prevent duplicate manufacturer parties

This commit is contained in:
gitea_admin committed 2026-09-06 10:21:25 +02:00
1 parent 19ce29c3d0
commit e43b5d34e0
3 files changed
+7 -1

No files matched your search

+5 -1
View File
@@ -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'],