]> source.dussan.org Git - nextcloud-server.git/commitdiff
Use insertIfNotExists() when creating a group
authorJoas Schilling <nickvergessen@owncloud.com>
Thu, 14 Jan 2016 09:08:41 +0000 (10:08 +0100)
committerThomas Müller <thomas.mueller@tmit.eu>
Thu, 14 Jan 2016 12:13:27 +0000 (13:13 +0100)
lib/private/group/database.php

index b769e69b4ba80c0b0c77d02a5bef69a8be0739be..8ea5a46c52b3fca8913278f1e75f12f88943bf81 100644 (file)
@@ -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;
        }
 
        /**