Fix UniqueConstraintViolationException while insert into oc_groups
* fixes race condition in insert * fixes potentiaol deadlock Signed-off-by: Morris Jobke <hey@morrisjobke.de>
This commit is contained in:
parent
859dd1e742
commit
84fd81e33f
|
@ -41,6 +41,7 @@
|
||||||
|
|
||||||
namespace OC\Group;
|
namespace OC\Group;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
|
||||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||||
use OCP\Group\Backend\ABackend;
|
use OCP\Group\Backend\ABackend;
|
||||||
use OCP\Group\Backend\IAddToGroupBackend;
|
use OCP\Group\Backend\IAddToGroupBackend;
|
||||||
|
@ -97,10 +98,15 @@ class Database extends ABackend
|
||||||
public function createGroup(string $gid): bool {
|
public function createGroup(string $gid): bool {
|
||||||
$this->fixDI();
|
$this->fixDI();
|
||||||
|
|
||||||
// Add group
|
try {
|
||||||
$result = $this->dbConn->insertIfNotExist('*PREFIX*groups', [
|
// Add group
|
||||||
'gid' => $gid,
|
$builder = $this->dbConn->getQueryBuilder();
|
||||||
]);
|
$result = $builder->insert('groups')
|
||||||
|
->setValue('gid', $builder->createNamedParameter($gid))
|
||||||
|
->execute();
|
||||||
|
} catch(UniqueConstraintViolationException $e) {
|
||||||
|
$result = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Add to cache
|
// Add to cache
|
||||||
$this->groupCache[$gid] = $gid;
|
$this->groupCache[$gid] = $gid;
|
||||||
|
|
Loading…
Reference in New Issue