summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>2023-11-15 09:03:02 +0100
committerGitHub <noreply@github.com>2023-11-15 09:03:02 +0100
commit11764ffec1113f14fe15a22e6db90ec633d1bb8e (patch)
tree6374741ee18bcf22925692623ba667e67767663a
parent5c91f2de2419628819e9bcdf4d84c2db0c099745 (diff)
parent234e8d21bd0471bde1dda441505c58c7aec9f9c9 (diff)
downloadnextcloud-server-11764ffec1113f14fe15a22e6db90ec633d1bb8e.tar.gz
nextcloud-server-11764ffec1113f14fe15a22e6db90ec633d1bb8e.zip
Merge pull request #41212 from nextcloud/backport/fix/aborted_pgsql_transaction_on_error/stable27
[stable27] fix(twofactor): avoid DB error on Twofactor (en/dis)abled event #40472
-rw-r--r--lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php37
1 files changed, 17 insertions, 20 deletions
diff --git a/lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php b/lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php
index 19d80218562..66bb9df8271 100644
--- a/lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php
+++ b/lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php
@@ -25,8 +25,6 @@ declare(strict_types=1);
*/
namespace OC\Authentication\TwoFactorAuth\Db;
-use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
-use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use function array_map;
@@ -70,25 +68,24 @@ class ProviderUserAssignmentDao {
* Persist a new/updated (provider_id, uid, enabled) tuple
*/
public function persist(string $providerId, string $uid, int $enabled) {
- $qb = $this->conn->getQueryBuilder();
-
- try {
- // Insert a new entry
- $insertQuery = $qb->insert(self::TABLE_NAME)->values([
- 'provider_id' => $qb->createNamedParameter($providerId),
- 'uid' => $qb->createNamedParameter($uid),
- 'enabled' => $qb->createNamedParameter($enabled, IQueryBuilder::PARAM_INT),
- ]);
-
- $insertQuery->execute();
- } catch (UniqueConstraintViolationException $ex) {
- // There is already an entry -> update it
- $updateQuery = $qb->update(self::TABLE_NAME)
- ->set('enabled', $qb->createNamedParameter($enabled))
- ->where($qb->expr()->eq('provider_id', $qb->createNamedParameter($providerId)))
- ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($uid)));
- $updateQuery->execute();
+ $conn = $this->conn;
+
+ // Insert a new entry
+ if ($conn->insertIgnoreConflict(self::TABLE_NAME, [
+ 'provider_id' => $providerId,
+ 'uid' => $uid,
+ 'enabled' => $enabled,
+ ])) {
+ return;
}
+
+ // There is already an entry -> update it
+ $qb = $conn->getQueryBuilder();
+ $updateQuery = $qb->update(self::TABLE_NAME)
+ ->set('enabled', $qb->createNamedParameter($enabled))
+ ->where($qb->expr()->eq('provider_id', $qb->createNamedParameter($providerId)))
+ ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($uid)));
+ $updateQuery->executeStatement();
}
/**