From: Thomas Tanghus Date: Fri, 6 Jul 2012 11:24:56 +0000 (+0200) Subject: Fix endless loop when no addressbooks. X-Git-Tag: v4.5.0beta1~74^2~225^2~28 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=cafbd023379073623295d11ae06be55a5f2cb569;p=nextcloud-server.git Fix endless loop when no addressbooks. --- diff --git a/apps/contacts/lib/addressbook.php b/apps/contacts/lib/addressbook.php index 40675efd8b4..7549464f464 100644 --- a/apps/contacts/lib/addressbook.php +++ b/apps/contacts/lib/addressbook.php @@ -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 );