aboutsummaryrefslogtreecommitdiffstats
path: root/apps/contacts/lib/addressbook.php
diff options
context:
space:
mode:
authorThomas Tanghus <thomas@tanghus.net>2012-06-20 20:59:33 +0200
committerThomas Tanghus <thomas@tanghus.net>2012-06-20 21:00:49 +0200
commitdc8c188ffed520b719a117564db78b0a23828a75 (patch)
tree1951aeef8e15ac4cec7efcb9b8c1f06dcbd546d3 /apps/contacts/lib/addressbook.php
parent426ed27be2dc5df34cc036cc87337837288156ec (diff)
downloadnextcloud-server-dc8c188ffed520b719a117564db78b0a23828a75.tar.gz
nextcloud-server-dc8c188ffed520b719a117564db78b0a23828a75.zip
Better error checking.
Diffstat (limited to 'apps/contacts/lib/addressbook.php')
-rw-r--r--apps/contacts/lib/addressbook.php23
1 files changed, 13 insertions, 10 deletions
diff --git a/apps/contacts/lib/addressbook.php b/apps/contacts/lib/addressbook.php
index 79445ceeee1..878d8835f94 100644
--- a/apps/contacts/lib/addressbook.php
+++ b/apps/contacts/lib/addressbook.php
@@ -172,12 +172,11 @@ class OC_Contacts_Addressbook{
if(!$prefbooks){
$addressbooks = OC_Contacts_Addressbook::all($uid);
if(count($addressbooks) == 0){
- OC_Contacts_Addressbook::add($uid,'default','Default Address Book');
- $addressbooks = OC_Contacts_Addressbook::all($uid);
+ $id = OC_Contacts_Addressbook::add($uid,'default','Default Address Book');
+ self::setActive($id, true);
}
- $prefbooks = $addressbooks[0]['id'];
- OCP\Config::setUserValue($uid,'contacts','openaddressbooks',$prefbooks);
}
+ $prefbooks = OCP\Config::getUserValue($uid,'contacts','openaddressbooks',null);
return explode(';',$prefbooks);
}
@@ -195,7 +194,7 @@ class OC_Contacts_Addressbook{
$stmt = OCP\DB::prepare( $prep );
$result = $stmt->execute($active);
} 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::ERROR);
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);
}
@@ -210,7 +209,7 @@ class OC_Contacts_Addressbook{
/**
* @brief Activates an addressbook
* @param integer $id
- * @param integer $name
+ * @param boolean $active
* @return boolean
*/
public static function setActive($id,$active){
@@ -256,11 +255,15 @@ class OC_Contacts_Addressbook{
* @return boolean
*/
public static function delete($id){
- // FIXME: There's no error checking at all.
self::setActive($id, false);
- $stmt = OCP\DB::prepare( 'DELETE FROM *PREFIX*contacts_addressbooks WHERE id = ?' );
- $stmt->execute(array($id));
-
+ try {
+ $stmt = OCP\DB::prepare( 'DELETE FROM *PREFIX*contacts_addressbooks WHERE id = ?' );
+ $stmt->execute(array($id));
+ } catch(Exception $e) {
+ OCP\Util::writeLog('contacts','OC_Contacts_Addressbook:delete:, exception for '.$id.': '.$e->getMessage(),OCP\Util::ERROR);
+ return false;
+ }
+
$cards = OC_Contacts_VCard::all($id);
foreach($cards as $card){
OC_Contacts_VCard::delete($card['id']);