]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix endless loop when no addressbooks.
authorThomas Tanghus <thomas@tanghus.net>
Fri, 6 Jul 2012 11:24:56 +0000 (13:24 +0200)
committerThomas Tanghus <thomas@tanghus.net>
Fri, 6 Jul 2012 11:24:56 +0000 (13:24 +0200)
apps/contacts/lib/addressbook.php

index 40675efd8b4357e7e5675f8d3aef4a44aaa01b28..7549464f46484ca0ceec4893e439cb3453543e60 100644 (file)
@@ -148,10 +148,17 @@ class OC_Contacts_Addressbook{
         * @return insertid
         */
        public static function add($uid,$name,$description=''){
-               $all = self::all($uid);
+               try {
+                       $stmt = OCP\DB::prepare( 'SELECT uri FROM *PREFIX*contacts_addressbooks WHERE userid = ? ' );
+                       $result = $stmt->execute(array($uid));
+               } catch(Exception $e) {
+                       OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.' exception: '.$e->getMessage(),OCP\Util::ERROR);
+                       OCP\Util::writeLog('contacts',__CLASS__.'::'.__METHOD__.' uid: '.$uid,OCP\Util::DEBUG);
+                       return false;
+               }
                $uris = array();
-               foreach($all as $i){
-                       $uris[] = $i['uri'];
+               while($row = $result->fetchRow()){
+                       $uris[] = $row['uri'];
                }
 
                $uri = self::createURI($name, $uris );