Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-08-31 15:42:55 +0300
committerGitHub <noreply@github.com>2018-08-31 15:42:55 +0300
commit7159ac12333dd3b1401d93998fbfebd71abc1dcc (patch)
tree289e7d3db69c38757fc8f5e1874f2db3910cca9a
parent3693d9568ea29076f5c3944dc30bc5bf59896d1f (diff)
parentfb98db7da7c30890ea0298ded185829bb543d86c (diff)
Merge pull request #10943 from nextcloud/fix/2fa-provider-dao-concurrent-insert
Fix handlng of concurrent inserts of the 2FA provider registry DAO
-rw-r--r--lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php29
1 files changed, 9 insertions, 20 deletions
diff --git a/lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php b/lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php
index e04512b8575..ce03eb09661 100644
--- a/lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php
+++ b/lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php
@@ -26,6 +26,7 @@ declare(strict_types=1);
namespace OC\Authentication\TwoFactorAuth\Db;
+use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
@@ -72,25 +73,7 @@ class ProviderUserAssignmentDao {
public function persist(string $providerId, string $uid, int $enabled) {
$qb = $this->conn->getQueryBuilder();
- $this->conn->beginTransaction();
- // To prevent duplicate primary key, we have to first check if an INSERT
- // or UPDATE is required
- $query = $qb->select('*')
- ->from(self::TABLE_NAME)
- ->where($qb->expr()->eq('provider_id', $qb->createNamedParameter($providerId)))
- ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($uid)));
- $result = $query->execute();
- $rowCount = count($result->fetchAll());
- $result->closeCursor();
-
- if ($rowCount > 0) {
- // There is 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();
- } else {
+ try {
// Insert a new entry
$insertQuery = $qb->insert(self::TABLE_NAME)->values([
'provider_id' => $qb->createNamedParameter($providerId),
@@ -99,8 +82,14 @@ class ProviderUserAssignmentDao {
]);
$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();
}
- $this->conn->commit();
}