diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-01-14 16:11:43 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-01-14 16:11:43 +0100 |
commit | 953c4bf18a2e14b05e36823d97489b566bb65551 (patch) | |
tree | 0beda0b36ffc89bb5688dc9d1c3636d0c8cd3c03 /lib/private/group | |
parent | 1f0af76eb2078a423ba3613416061c9f1f336548 (diff) | |
parent | 5036e4527ff12034972f02dc011638bc06fbee81 (diff) | |
download | nextcloud-server-953c4bf18a2e14b05e36823d97489b566bb65551.tar.gz nextcloud-server-953c4bf18a2e14b05e36823d97489b566bb65551.zip |
Merge pull request #21714 from owncloud/groups-insertifnotexists
Groups insertifnotexists
Diffstat (limited to 'lib/private/group')
-rw-r--r-- | lib/private/group/database.php | 39 |
1 files changed, 5 insertions, 34 deletions
diff --git a/lib/private/group/database.php b/lib/private/group/database.php index b769e69b4ba..21e7b103554 100644 --- a/lib/private/group/database.php +++ b/lib/private/group/database.php @@ -85,44 +85,15 @@ 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 - $qb = $this->dbConn->getQueryBuilder(); - $result = $qb->insert('groups') - ->setValue('gid', $qb->createNamedParameter($gid)) - ->execute(); - - if (!$result) { - return false; - } + // Add group + $result = $this->dbConn->insertIfNotExist('*PREFIX*groups', [ + 'gid' => $gid, + ]); // Add to cache $this->groupCache[$gid] = $gid; - return true; + return $result === 1; } /** |