Merge pull request #26587 from nextcloud/backport/26581/stable21
[stable21] Fix constraint violation detection in QB Mapper
This commit is contained in:
commit
50e897aa53
|
@ -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,9 +157,12 @@ abstract class QBMapper {
|
|||
public function insertOrUpdate(Entity $entity): Entity {
|
||||
try {
|
||||
return $this->insert($entity);
|
||||
} catch (UniqueConstraintViolationException $ex) {
|
||||
} catch (Exception $ex) {
|
||||
if ($ex->getReason() === Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
|
||||
return $this->update($entity);
|
||||
}
|
||||
throw $ex;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue