From 896bff57480448456b2ca7d57f5ff2b0439315f6 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Thu, 29 Mar 2012 18:54:06 +0200 Subject: [PATCH] Contacts: rescan categories on load if there are none. --- apps/contacts/index.php | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/apps/contacts/index.php b/apps/contacts/index.php index 04f6c65a145..076b10c2ee2 100644 --- a/apps/contacts/index.php +++ b/apps/contacts/index.php @@ -34,7 +34,28 @@ if(!is_null($id)) { } $property_types = OC_Contacts_App::getAddPropertyOptions(); $phone_types = OC_Contacts_App::getTypesOfProperty('TEL'); -$categories = OC_Contacts_App::$categories->categories(); +$categories = OC_Contacts_App::getCategories(); +if(count($categories) == 0) { + $vcaddressbooks = OC_Contacts_Addressbook::all(OC_User::getUser()); + if(count($vcaddressbooks) > 0) { + $vcaddressbookids = array(); + foreach($vcaddressbooks as $vcaddressbook) { + $vcaddressbookids[] = $vcaddressbook['id']; + } + $vccontacts = OC_Contacts_VCard::all($vcaddressbookids); + if(count($vccontacts) == 0) { + bailOut(OC_Contacts_App::$l10n->t('No contacts found.')); + } + + $cards = array(); + foreach($vccontacts as $vccontact) { + $cards[] = $vccontact['carddata']; + } + + OC_Contacts_App::$categories->rescan($cards); + $categories = OC_Contacts_App::$categories->categories(); + } +} $upload_max_filesize = OC_Helper::computerFileSize(ini_get('upload_max_filesize')); $post_max_size = OC_Helper::computerFileSize(ini_get('post_max_size')); @@ -61,7 +82,6 @@ $tmpl = new OC_Template( "contacts", "index", "user" ); $tmpl->assign('uploadMaxFilesize', $maxUploadFilesize); $tmpl->assign('uploadMaxHumanFilesize', OC_Helper::humanFileSize($maxUploadFilesize)); $tmpl->assign('property_types',$property_types); -$tmpl->assign('categories',OC_Contacts_App::getCategories()); $tmpl->assign('phone_types',$phone_types); $tmpl->assign('categories',$categories); $tmpl->assign('addressbooks', $addressbooks); -- 2.39.5