]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix constraint violation detection in QB Mapper 26587/head
authorJoas Schilling <coding@schilljs.com>
Fri, 16 Apr 2021 07:07:32 +0000 (09:07 +0200)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Fri, 16 Apr 2021 09:14:29 +0000 (09:14 +0000)
Signed-off-by: Joas Schilling <coding@schilljs.com>
lib/public/AppFramework/Db/QBMapper.php

index 72373ba26c303a7d41769adeecceac25d19c9384..fb5215895a28d0195b75ae54f310c77f78b24a44 100644 (file)
@@ -30,7 +30,7 @@ declare(strict_types=1);
 
 namespace OCP\AppFramework\Db;
 
-use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
+use OCP\DB\Exception;
 use OCP\DB\QueryBuilder\IQueryBuilder;
 use OCP\IDBConnection;
 
@@ -157,8 +157,11 @@ abstract class QBMapper {
        public function insertOrUpdate(Entity $entity): Entity {
                try {
                        return $this->insert($entity);
-               } catch (UniqueConstraintViolationException $ex) {
-                       return $this->update($entity);
+               } catch (Exception $ex) {
+                       if ($ex->getReason() === Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
+                               return $this->update($entity);
+                       }
+                       throw $ex;
                }
        }