]> source.dussan.org Git - nextcloud-server.git/commitdiff
Contacts: rescan categories on load if there are none.
authorThomas Tanghus <thomas@tanghus.net>
Thu, 29 Mar 2012 16:54:06 +0000 (18:54 +0200)
committerThomas Tanghus <thomas@tanghus.net>
Tue, 3 Apr 2012 01:29:12 +0000 (03:29 +0200)
apps/contacts/index.php

index 04f6c65a145c1aa68575a23a58699137a52e832f..076b10c2ee21d400936e7fd207020dd56d45a215 100644 (file)
@@ -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);