summaryrefslogtreecommitdiffstats
path: root/apps/contacts/lib
diff options
context:
space:
mode:
authorThomas Tanghus <thomas@tanghus.net>2012-07-08 15:41:38 +0200
committerThomas Tanghus <thomas@tanghus.net>2012-07-08 15:41:38 +0200
commit25b95a9ec7da492e43c26ba5d6f38c773cecd39f (patch)
tree7e7f4493e67a4b0500bb06ab674049f0b49e1a50 /apps/contacts/lib
parent554cb2d3ab559a2ebfc9f3ffea3e12db7a5c5983 (diff)
downloadnextcloud-server-25b95a9ec7da492e43c26ba5d6f38c773cecd39f.tar.gz
nextcloud-server-25b95a9ec7da492e43c26ba5d6f38c773cecd39f.zip
Improve checking for active addressbooks and creating default addressbook.
Diffstat (limited to 'apps/contacts/lib')
-rw-r--r--apps/contacts/lib/addressbook.php23
-rw-r--r--apps/contacts/lib/vcard.php16
2 files changed, 29 insertions, 10 deletions
diff --git a/apps/contacts/lib/addressbook.php b/apps/contacts/lib/addressbook.php
index 79445ceeee1..73b30e942fa 100644
--- a/apps/contacts/lib/addressbook.php
+++ b/apps/contacts/lib/addressbook.php
@@ -169,16 +169,26 @@ class OC_Contacts_Addressbook{
$uid = OCP\USER::getUser();
}
$prefbooks = OCP\Config::getUserValue($uid,'contacts','openaddressbooks',null);
+ $prefbooks = explode(';',$prefbooks);
+ for ($i = 0; $i < count($prefbooks); $i++) {
+ if(!self::find($prefbooks[$i])) {
+ unset($prefbooks[$i]);
+ }
+ }
if(!$prefbooks){
+ OCP\Util::writeLog('contacts','OC_Contacts_Addressbook:activeIds:, No active addressbooks',OCP\Util::DEBUG);
$addressbooks = OC_Contacts_Addressbook::all($uid);
if(count($addressbooks) == 0){
- OC_Contacts_Addressbook::add($uid,'default','Default Address Book');
+ OCP\Util::writeLog('contacts','OC_Contacts_Addressbook:activeIds:, No addressbooks',OCP\Util::DEBUG);
+ $id = self::add($uid,'default','Default Address Book');
+ OCP\Util::writeLog('contacts','OC_Contacts_Addressbook:activeIds:, Created addressbook: '.$id,OCP\Util::DEBUG);
+ self::setActive($id, true);
$addressbooks = OC_Contacts_Addressbook::all($uid);
}
- $prefbooks = $addressbooks[0]['id'];
- OCP\Config::setUserValue($uid,'contacts','openaddressbooks',$prefbooks);
+ $prefbooks[] = $addressbooks[0]['id'];
+ OCP\Config::setUserValue($uid,'contacts','openaddressbooks',implode(';',$prefbooks));
}
- return explode(';',$prefbooks);
+ return $prefbooks;
}
/**
@@ -189,6 +199,9 @@ class OC_Contacts_Addressbook{
public static function active($uid){
$active = self::activeIds($uid);
$addressbooks = array();
+ if(!$active) {
+ return $addressbooks;
+ }
$ids_sql = join(',', array_fill(0, count($active), '?'));
$prep = 'SELECT * FROM *PREFIX*contacts_addressbooks WHERE id IN ('.$ids_sql.') ORDER BY displayname';
try {
@@ -213,7 +226,7 @@ class OC_Contacts_Addressbook{
* @param integer $name
* @return boolean
*/
- public static function setActive($id,$active){
+ public static function setActive($id,$active=true){
// Need these ones for checking uri
//$addressbook = self::find($id);
diff --git a/apps/contacts/lib/vcard.php b/apps/contacts/lib/vcard.php
index 71a874d783b..2868643387d 100644
--- a/apps/contacts/lib/vcard.php
+++ b/apps/contacts/lib/vcard.php
@@ -49,25 +49,31 @@ class OC_Contacts_VCard{
*/
public static function all($id){
$result = null;
- if(is_array($id)) {
+ if(is_array($id) && count($id) > 1) {
$id_sql = join(',', array_fill(0, count($id), '?'));
$prep = 'SELECT * FROM *PREFIX*contacts_cards WHERE addressbookid IN ('.$id_sql.') ORDER BY fullname';
try {
$stmt = OCP\DB::prepare( $prep );
$result = $stmt->execute($id);
} catch(Exception $e) {
- OCP\Util::writeLog('contacts','OC_Contacts_VCard:all:, exception: '.$e->getMessage(),OCP\Util::DEBUG);
- OCP\Util::writeLog('contacts','OC_Contacts_VCard:all, ids: '.join(',', $id),OCP\Util::DEBUG);
+ OCP\Util::writeLog('contacts','OC_Contacts_VCard:all:, exception: '.$e->getMessage(),OCP\Util::ERROR);
+ OCP\Util::writeLog('contacts','OC_Contacts_VCard:all, ids: '.count($id).' '.join(',', $id),OCP\Util::DEBUG);
OCP\Util::writeLog('contacts','SQL:'.$prep,OCP\Util::DEBUG);
}
} elseif($id) {
+ if(is_array($id)) {
+ $id = $id[0];
+ }
try {
$stmt = OCP\DB::prepare( 'SELECT * FROM *PREFIX*contacts_cards WHERE addressbookid = ? ORDER BY fullname' );
$result = $stmt->execute(array($id));
} catch(Exception $e) {
- OCP\Util::writeLog('contacts','OC_Contacts_VCard:all:, exception: '.$e->getMessage(),OCP\Util::DEBUG);
- OCP\Util::writeLog('contacts','OC_Contacts_VCard:all, ids: '. $id,OCP\Util::DEBUG);
+ OCP\Util::writeLog('contacts','OC_Contacts_VCard:all:, exception: '.$e->getMessage(),OCP\Util::ERROR);
+ OCP\Util::writeLog('contacts','OC_Contacts_VCard:all, id: '. $id,OCP\Util::DEBUG);
}
+ } else {
+ OCP\Util::writeLog('contacts','OC_Contacts_VCard:all: No ID given.',OCP\Util::ERROR);
+ return array();
}
$cards = array();
if(!is_null($result)) {