summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-11-12 17:36:35 +0100
committerMorris Jobke <hey@morrisjobke.de>2018-11-12 17:36:35 +0100
commit84fd81e33f9334f13d4912edf79570131dd18939 (patch)
tree0fb9b299f789f9eb369b5c2df1a5a0a7b157d00a
parent859dd1e742c4c71b3fbd7035a866c230b80142c2 (diff)
downloadnextcloud-server-84fd81e33f9334f13d4912edf79570131dd18939.tar.gz
nextcloud-server-84fd81e33f9334f13d4912edf79570131dd18939.zip
Fix UniqueConstraintViolationException while insert into oc_groups
* fixes race condition in insert * fixes potentiaol deadlock Signed-off-by: Morris Jobke <hey@morrisjobke.de>
-rw-r--r--lib/private/Group/Database.php14
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/private/Group/Database.php b/lib/private/Group/Database.php
index c77ae9e2ee8..c6599839a75 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;