diff options
author | Morris Jobke <hey@morrisjobke.de> | 2018-11-12 21:14:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-12 21:14:38 +0100 |
commit | 3996210307098444eee2df283fb72315ed3ae1a1 (patch) | |
tree | 1a726c00282351f2f3c86733ce98d4c59efa7695 | |
parent | f6fed4d54bce6156fbb68ee6ae0937e66870d502 (diff) | |
parent | 84fd81e33f9334f13d4912edf79570131dd18939 (diff) | |
download | nextcloud-server-3996210307098444eee2df283fb72315ed3ae1a1.tar.gz nextcloud-server-3996210307098444eee2df283fb72315ed3ae1a1.zip |
Merge pull request #12419 from nextcloud/bugfix/noid/group-creation-replace-insertIfNotExist
Fix UniqueConstraintViolationException while insert into oc_groups
-rw-r--r-- | lib/private/Group/Database.php | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/private/Group/Database.php b/lib/private/Group/Database.php index 53c413f0fa9..7a5728b957d 100644 --- a/lib/private/Group/Database.php +++ b/lib/private/Group/Database.php @@ -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; |