diff options
author | Joas Schilling <nickvergessen@owncloud.com> | 2016-01-14 10:08:41 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-01-14 13:13:27 +0100 |
commit | 436ce1f4a69f15ed4232bf81f706c631a1a68663 (patch) | |
tree | e9c601652d6138f3e7b9a70b3c7705a59e4ed0bd /lib/private | |
parent | 8f89e3520d74e1805dc46947742a17683ece6ca7 (diff) | |
download | nextcloud-server-436ce1f4a69f15ed4232bf81f706c631a1a68663.tar.gz nextcloud-server-436ce1f4a69f15ed4232bf81f706c631a1a68663.zip |
Use insertIfNotExists() when creating a group
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/group/database.php | 38 |
1 files changed, 5 insertions, 33 deletions
diff --git a/lib/private/group/database.php b/lib/private/group/database.php index b769e69b4ba..8ea5a46c52b 100644 --- a/lib/private/group/database.php +++ b/lib/private/group/database.php @@ -85,44 +85,16 @@ class OC_Group_Database extends OC_Group_Backend { public function createGroup( $gid ) { $this->fixDI(); - // Check cache first - if (isset($this->groupCache[$gid])) { - return false; - } else { - // Check for existence in DB - $qb = $this->dbConn->getQueryBuilder(); - $cursor = $qb->select('gid') - ->from('groups') - ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) - ->execute(); - - $result = $cursor->fetch(); - $cursor->closeCursor(); - - if($result) { - // Can not add an existing group - - // Add to cache - $this->groupCache[$gid] = $gid; - - return false; - } - } - - // Add group and exit + // Add group $qb = $this->dbConn->getQueryBuilder(); - $result = $qb->insert('groups') - ->setValue('gid', $qb->createNamedParameter($gid)) - ->execute(); - - if (!$result) { - return false; - } + $result = $qb->insertIfNotExists('groups', [ + 'gid' => $gid, + ]); // Add to cache $this->groupCache[$gid] = $gid; - return true; + return $result === 1; } /** |