|
45 | 45 | */ |
46 | 46 | namespace OC\User; |
47 | 47 |
|
| 48 | +use OCP\AppFramework\Db\TTransactional; |
48 | 49 | use OCP\Cache\CappedMemoryCache; |
49 | 50 | use OCP\EventDispatcher\IEventDispatcher; |
50 | 51 | use OCP\IDBConnection; |
@@ -85,6 +86,8 @@ class Database extends ABackend implements |
85 | 86 | /** @var string */ |
86 | 87 | private $table; |
87 | 88 |
|
| 89 | + use TTransactional; |
| 90 | + |
88 | 91 | /** |
89 | 92 | * \OC\User\Database constructor. |
90 | 93 | * |
@@ -122,20 +125,24 @@ public function createUser(string $uid, string $password): bool { |
122 | 125 | if (!$this->userExists($uid)) { |
123 | 126 | $this->eventDispatcher->dispatchTyped(new ValidatePasswordPolicyEvent($password)); |
124 | 127 |
|
125 | | - $qb = $this->dbConn->getQueryBuilder(); |
126 | | - $qb->insert($this->table) |
127 | | - ->values([ |
128 | | - 'uid' => $qb->createNamedParameter($uid), |
129 | | - 'password' => $qb->createNamedParameter(\OC::$server->getHasher()->hash($password)), |
130 | | - 'uid_lower' => $qb->createNamedParameter(mb_strtolower($uid)), |
131 | | - ]); |
| 128 | + return $this->atomic(function () use ($uid, $password) { |
| 129 | + $qb = $this->dbConn->getQueryBuilder(); |
| 130 | + $qb->insert($this->table) |
| 131 | + ->values([ |
| 132 | + 'uid' => $qb->createNamedParameter($uid), |
| 133 | + 'password' => $qb->createNamedParameter(\OC::$server->getHasher()->hash($password)), |
| 134 | + 'uid_lower' => $qb->createNamedParameter(mb_strtolower($uid)), |
| 135 | + ]); |
132 | 136 |
|
133 | | - $result = $qb->execute(); |
| 137 | + $result = $qb->executeStatement(); |
134 | 138 |
|
135 | | - // Clear cache |
136 | | - unset($this->cache[$uid]); |
| 139 | + // Clear cache |
| 140 | + unset($this->cache[$uid]); |
| 141 | + // Repopulate the cache |
| 142 | + $this->loadUser($uid); |
137 | 143 |
|
138 | | - return $result ? true : false; |
| 144 | + return (bool) $result; |
| 145 | + }, $this->dbConn); |
139 | 146 | } |
140 | 147 |
|
141 | 148 | return false; |
|
0 commit comments