summaryrefslogtreecommitdiffstats
path: root/lib/private/User
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2023-03-15 15:13:50 +0100
committerGitHub <noreply@github.com>2023-03-15 15:13:50 +0100
commitc7c1133c15f4ab33a69d40bb387354a270ca5541 (patch)
tree448738146e3c70334e91d50ce557ec052f83eaf0 /lib/private/User
parenta30d7c51d361edd75c9b1d7f539f220a5a81be2e (diff)
parentf7e65b17513303bd16308107d252682ac3c56359 (diff)
downloadnextcloud-server-c7c1133c15f4ab33a69d40bb387354a270ca5541.tar.gz
nextcloud-server-c7c1133c15f4ab33a69d40bb387354a270ca5541.zip
Merge pull request #35561 from nextcloud/create-user-transaction
Diffstat (limited to 'lib/private/User')
-rw-r--r--lib/private/User/Database.php29
1 files changed, 18 insertions, 11 deletions
diff --git a/lib/private/User/Database.php b/lib/private/User/Database.php
index 8bbbccd4540..944202f244e 100644
--- a/lib/private/User/Database.php
+++ b/lib/private/User/Database.php
@@ -45,6 +45,7 @@ declare(strict_types=1);
*/
namespace OC\User;
+use OCP\AppFramework\Db\TTransactional;
use OCP\Cache\CappedMemoryCache;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IDBConnection;
@@ -85,6 +86,8 @@ class Database extends ABackend implements
/** @var string */
private $table;
+ use TTransactional;
+
/**
* \OC\User\Database constructor.
*
@@ -122,20 +125,24 @@ class Database extends ABackend implements
if (!$this->userExists($uid)) {
$this->eventDispatcher->dispatchTyped(new ValidatePasswordPolicyEvent($password));
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert($this->table)
- ->values([
- 'uid' => $qb->createNamedParameter($uid),
- 'password' => $qb->createNamedParameter(\OC::$server->getHasher()->hash($password)),
- 'uid_lower' => $qb->createNamedParameter(mb_strtolower($uid)),
- ]);
+ return $this->atomic(function () use ($uid, $password) {
+ $qb = $this->dbConn->getQueryBuilder();
+ $qb->insert($this->table)
+ ->values([
+ 'uid' => $qb->createNamedParameter($uid),
+ 'password' => $qb->createNamedParameter(\OC::$server->getHasher()->hash($password)),
+ 'uid_lower' => $qb->createNamedParameter(mb_strtolower($uid)),
+ ]);
- $result = $qb->execute();
+ $result = $qb->executeStatement();
- // Clear cache
- unset($this->cache[$uid]);
+ // Clear cache
+ unset($this->cache[$uid]);
+ // Repopulate the cache
+ $this->loadUser($uid);
- return $result ? true : false;
+ return (bool) $result;
+ }, $this->dbConn);
}
return false;