Skip to content
Snippets Groups Projects
Commit f91783e9 authored by Thomas Tanghus's avatar Thomas Tanghus
Browse files

Fix errors when no addressbook.

parent e52ab59b
Branches
No related tags found
No related merge requests found
...@@ -71,10 +71,15 @@ class OC_Contacts_Addressbook{ ...@@ -71,10 +71,15 @@ class OC_Contacts_Addressbook{
* @return associative array * @return associative array
*/ */
public static function find($id){ public static function find($id){
try {
$stmt = OCP\DB::prepare( 'SELECT * FROM *PREFIX*contacts_addressbooks WHERE id = ?' ); $stmt = OCP\DB::prepare( 'SELECT * FROM *PREFIX*contacts_addressbooks WHERE id = ?' );
$result = $stmt->execute(array($id)); $result = $stmt->execute(array($id));
return $result->fetchRow(); return $result->fetchRow();
} catch(Exception $e) {
OCP\Util::writeLog('contacts', __CLASS__.'::'.__METHOD__.', exception: '.$e->getMessage(), OCP\Util::ERROR);
OCP\Util::writeLog('contacts', __CLASS__.'::'.__METHOD__.', id: '.$id, OCP\Util::DEBUG);
return false;
}
} }
/** /**
...@@ -171,7 +176,7 @@ class OC_Contacts_Addressbook{ ...@@ -171,7 +176,7 @@ class OC_Contacts_Addressbook{
$prefbooks = OCP\Config::getUserValue($uid,'contacts','openaddressbooks',null); $prefbooks = OCP\Config::getUserValue($uid,'contacts','openaddressbooks',null);
$prefbooks = explode(';',$prefbooks); $prefbooks = explode(';',$prefbooks);
for ($i = 0; $i < count($prefbooks); $i++) { for ($i = 0; $i < count($prefbooks); $i++) {
if(!self::find($prefbooks[$i])) { if(!$prefbooks[$i] || !self::find($prefbooks[$i])) {
unset($prefbooks[$i]); unset($prefbooks[$i]);
} }
} }
...@@ -207,16 +212,15 @@ class OC_Contacts_Addressbook{ ...@@ -207,16 +212,15 @@ class OC_Contacts_Addressbook{
try { try {
$stmt = OCP\DB::prepare( $prep ); $stmt = OCP\DB::prepare( $prep );
$result = $stmt->execute($active); $result = $stmt->execute($active);
while( $row = $result->fetchRow()){
$addressbooks[] = $row;
}
} catch(Exception $e) { } catch(Exception $e) {
OCP\Util::writeLog('contacts','OC_Contacts_Addressbook:active:, exception: '.$e->getMessage(),OCP\Util::DEBUG); OCP\Util::writeLog('contacts','OC_Contacts_Addressbook:active:, exception: '.$e->getMessage(),OCP\Util::DEBUG);
OCP\Util::writeLog('contacts','OC_Contacts_Addressbook:active, ids: '.join(',', $active),OCP\Util::DEBUG); OCP\Util::writeLog('contacts','OC_Contacts_Addressbook:active, ids: '.join(',', $active),OCP\Util::DEBUG);
OCP\Util::writeLog('contacts','OC_Contacts_Addressbook::active, SQL:'.$prep,OCP\Util::DEBUG); OCP\Util::writeLog('contacts','OC_Contacts_Addressbook::active, SQL:'.$prep,OCP\Util::DEBUG);
} }
while( $row = $result->fetchRow()){
$addressbooks[] = $row;
}
return $addressbooks; return $addressbooks;
} }
......
...@@ -62,6 +62,9 @@ class OC_Contacts_VCard{ ...@@ -62,6 +62,9 @@ class OC_Contacts_VCard{
} }
} elseif($id) { } elseif($id) {
if(is_array($id)) { if(is_array($id)) {
if(count($id) == 0) {
return array();
}
$id = $id[0]; $id = $id[0];
} }
try { try {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment