Skip to content

Commit

Permalink
Merge pull request #12419 from nextcloud/bugfix/noid/group-creation-r…
Browse files Browse the repository at this point in the history
…eplace-insertIfNotExist

Fix UniqueConstraintViolationException while insert into oc_groups
  • Loading branch information
MorrisJobke authored Nov 12, 2018
2 parents f6fed4d + 84fd81e commit 3996210
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/private/Group/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -97,10 +98,15 @@ private function fixDI() {
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;
Expand Down

0 comments on commit 3996210

Please sign in to comment.