Merge pull request #26587 from nextcloud/backport/26581/stable21

[stable21] Fix constraint violation detection in QB Mapper
This commit is contained in:
Roeland Jago Douma 2021-04-16 12:58:21 +02:00 committed by GitHub
commit 50e897aa53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 3 deletions

View File

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