mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Merge pull request #35561 from nextcloud/create-user-transaction
This commit is contained in:
commit
c7c1133c15
1 changed files with 18 additions and 11 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue