From 546c17031a62b000f780073f6d296702c7a10bd0 Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Thu, 12 Dec 2024 12:43:11 +0100 Subject: [PATCH] Make NodaImportLogger more resilient, prevent error in case of duplicate import names --- src/NodaImportLogger.php | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/NodaImportLogger.php b/src/NodaImportLogger.php index a3633fe..403bafd 100644 --- a/src/NodaImportLogger.php +++ b/src/NodaImportLogger.php @@ -32,8 +32,12 @@ final class NodaImportLogger { $logStmt = $mysqli_noda->do_prepare("INSERT INTO `persinst_logged_imports` (`instance`, `institution_id`, `input_string`, `persinst_id`) VALUES (?, ?, ?, ?)"); - $logStmt->bind_param("sisi", $instance, $institution_id, $loggedName, $persinst_id); - $logStmt->execute(); + try { + $logStmt->bind_param("sisi", $instance, $institution_id, $loggedName, $persinst_id); + $logStmt->execute(); + } + catch (MDMysqliDuplicateKeysError $e) { + } $logStmt->close(); } @@ -54,8 +58,12 @@ final class NodaImportLogger { $logStmt = $mysqli_noda->do_prepare("INSERT INTO `orte_logged_imports` (`instance`, `institution_id`, `input_string`, `ort_id`) VALUES (?, ?, ?, ?)"); - $logStmt->bind_param("sisi", $instance, $institution_id, $name, $ort_id); - $logStmt->execute(); + try { + $logStmt->bind_param("sisi", $instance, $institution_id, $name, $ort_id); + $logStmt->execute(); + } + catch (MDMysqliDuplicateKeysError $e) { + } $logStmt->close(); } @@ -76,8 +84,12 @@ final class NodaImportLogger { $logStmt = $mysqli_noda->do_prepare("INSERT INTO `zeiten_logged_imports` (`instance`, `institution_id`, `input_string`, `zeit_id`) VALUES (?, ?, ?, ?)"); - $logStmt->bind_param("sisi", $instance, $institution_id, $name, $zeit_id); - $logStmt->execute(); + try { + $logStmt->bind_param("sisi", $instance, $institution_id, $name, $zeit_id); + $logStmt->execute(); + } + catch (MDMysqliDuplicateKeysError $e) { + } $logStmt->close(); } @@ -98,8 +110,12 @@ final class NodaImportLogger { $logStmt = $mysqli_noda->do_prepare("INSERT INTO `tag_logged_imports` (`instance`, `institution_id`, `input_string`, `tag_id`) VALUES (?, ?, ?, ?)"); - $logStmt->bind_param("sisi", $instance, $institution_id, $name, $tag_id); - $logStmt->execute(); + try { + $logStmt->bind_param("sisi", $instance, $institution_id, $name, $tag_id); + $logStmt->execute(); + } + catch (MDMysqliDuplicateKeysError $e) { + } $logStmt->close(); }