Merge pull request #12419 from nextcloud/bugfix/noid/group-creation-replace-insertIfNotExist

Fix UniqueConstraintViolationException while insert into oc_groups
This commit is contained in:
Morris Jobke 2018-11-12 21:14:38 +01:00 committed by GitHub
commit 3996210307
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 4 deletions

View File

@ -41,6 +41,7 @@
namespace OC\Group;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Group\Backend\ABackend;
use OCP\Group\Backend\IAddToGroupBackend;
@ -97,10 +98,15 @@ class Database extends ABackend
public function createGroup(string $gid): bool {
$this->fixDI();
// Add group
$result = $this->dbConn->insertIfNotExist('*PREFIX*groups', [
'gid' => $gid,
]);
try {
// Add group
$builder = $this->dbConn->getQueryBuilder();
$result = $builder->insert('groups')
->setValue('gid', $builder->createNamedParameter($gid))
->execute();
} catch(UniqueConstraintViolationException $e) {
$result = 0;
}
// Add to cache
$this->groupCache[$gid] = $gid;