From 3fb0aa40cd0c06d208653d17d62c0ce2b358d6cc Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Wed, 29 May 2024 11:01:19 +0200 Subject: [PATCH] feat(db): add mapping for lock wait timeout Signed-off-by: Daniel Kesselberg --- lib/private/DB/Exceptions/DbalException.php | 4 ++++ lib/public/DB/Exception.php | 7 +++++++ tests/lib/DB/Exception/DbalExceptionTest.php | 2 ++ 3 files changed, 13 insertions(+) diff --git a/lib/private/DB/Exceptions/DbalException.php b/lib/private/DB/Exceptions/DbalException.php index 81ee9c62a0f8d..05ea9e22a5d42 100644 --- a/lib/private/DB/Exceptions/DbalException.php +++ b/lib/private/DB/Exceptions/DbalException.php @@ -17,6 +17,7 @@ use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException; use Doctrine\DBAL\Exception\InvalidArgumentException; use Doctrine\DBAL\Exception\InvalidFieldNameException; +use Doctrine\DBAL\Exception\LockWaitTimeoutException; use Doctrine\DBAL\Exception\NonUniqueFieldNameException; use Doctrine\DBAL\Exception\NotNullConstraintViolationException; use Doctrine\DBAL\Exception\RetryableException; @@ -82,6 +83,9 @@ public function getReason(): ?int { /** * Other server errors */ + if ($this->original instanceof LockWaitTimeoutException) { + return parent::REASON_LOCK_WAIT_TIMEOUT; + } if ($this->original instanceof DatabaseObjectExistsException) { return parent::REASON_DATABASE_OBJECT_EXISTS; } diff --git a/lib/public/DB/Exception.php b/lib/public/DB/Exception.php index 8fef01ca0a4c5..6b908382aeab6 100644 --- a/lib/public/DB/Exception.php +++ b/lib/public/DB/Exception.php @@ -120,6 +120,13 @@ class Exception extends BaseException { */ public const REASON_UNIQUE_CONSTRAINT_VIOLATION = 14; + /** + * The lock wait timeout was exceeded + * + * @since 30.0.0 + */ + public const REASON_LOCK_WAIT_TIMEOUT = 15; + /** * @return int|null * @psalm-return Exception::REASON_* diff --git a/tests/lib/DB/Exception/DbalExceptionTest.php b/tests/lib/DB/Exception/DbalExceptionTest.php index 97f0efa4b6535..470beff9080b9 100644 --- a/tests/lib/DB/Exception/DbalExceptionTest.php +++ b/tests/lib/DB/Exception/DbalExceptionTest.php @@ -17,6 +17,7 @@ use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException; use Doctrine\DBAL\Exception\InvalidArgumentException; use Doctrine\DBAL\Exception\InvalidFieldNameException; +use Doctrine\DBAL\Exception\LockWaitTimeoutException; use Doctrine\DBAL\Exception\NonUniqueFieldNameException; use Doctrine\DBAL\Exception\NotNullConstraintViolationException; use Doctrine\DBAL\Exception\ServerException; @@ -45,6 +46,7 @@ public function testDriverException(string $class, int $reason): void { public function dataDriverException(): array { return [ + [LockWaitTimeoutException::class, DbalException::REASON_LOCK_WAIT_TIMEOUT], [ForeignKeyConstraintViolationException::class, DbalException::REASON_FOREIGN_KEY_VIOLATION], [NotNullConstraintViolationException::class, DbalException::REASON_NOT_NULL_CONSTRAINT_VIOLATION], [UniqueConstraintViolationException::class, DbalException::REASON_UNIQUE_CONSTRAINT_VIOLATION],