Skip to content

Commit

Permalink
Fix Exception catching in OC\DB\Adapter
Browse files Browse the repository at this point in the history
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
  • Loading branch information
come-nc committed Sep 5, 2023
1 parent e966cfb commit 5c78adb
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/private/DB/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use OC\DB\Exceptions\DbalException;

/**
* This handles the way we use to write queries, into something that can be
Expand Down Expand Up @@ -143,8 +144,11 @@ public function insertIgnoreConflict(string $table, array $values) : int {
$builder->setValue($key, $builder->createNamedParameter($value));
}
return $builder->executeStatement();
} catch (UniqueConstraintViolationException $e) {
return 0;
} catch (DbalException $e) {
if ($e->getReason() === \OCP\DB\Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
return 0;
}
throw $e;
}
}
}

0 comments on commit 5c78adb

Please sign in to comment.