From 5ee7e8e2ad18188721f5f60ee4aa2d76546f0fc5 Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Mon, 29 Apr 2024 11:28:57 -0500 Subject: [PATCH] Fix incorrect exception check in DB connection code --- lib/DbConnection.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/DbConnection.php b/lib/DbConnection.php index e6c9ae71..747bfa12 100644 --- a/lib/DbConnection.php +++ b/lib/DbConnection.php @@ -1,8 +1,4 @@ errorInfo) && $ex->errorInfo[1] == 1213 && $deadlockRetries < 3){ // InnoDB deadlock, this is normal and happens occasionally. All we have to do is retry the query. + if(isset($ex->errorInfo) && $ex->errorInfo[1] == 1213 && $deadlockRetries < 3){ + // InnoDB deadlock, this is normal and happens occasionally. All we have to do is retry the query. $deadlockRetries++; - usleep(500000 * $deadlockRetries); // Give the deadlock some time to clear up. Start at .5 seconds } - elseif($ex->getCode() == '23000'){ + elseif(isset($ex->errorInfo) && $ex->errorInfo[1] == 1062){ // Duplicate key, bubble this up without logging it so the business logic can handle it throw new Exceptions\DuplicateDatabaseKeyException(); } @@ -130,7 +126,7 @@ class DbConnection{ } /** - * @param \PdoException $ex The exception to create details from. + * @param PdoException $ex The exception to create details from. * @param string $preparedSql The prepared SQL that caused the exception. * @param array $params The parameters passed to the prepared SQL. */