summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/contacts/ajax/categories/list.php2
-rw-r--r--apps/contacts/ajax/categories/rescan.php9
-rw-r--r--apps/contacts/index.php19
-rw-r--r--apps/contacts/lib/app.php40
-rw-r--r--apps/contacts/lib/vcard.php4
5 files changed, 44 insertions, 30 deletions
diff --git a/apps/contacts/ajax/categories/list.php b/apps/contacts/ajax/categories/list.php
index 3b41b7bfa95..64d74c82e69 100644
--- a/apps/contacts/ajax/categories/list.php
+++ b/apps/contacts/ajax/categories/list.php
@@ -10,7 +10,7 @@ require_once('../../../../lib/base.php');
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
-$categories = OC_Contacts_App::$categories->categories();
+$categories = OC_Contacts_App::getCategories();
OC_JSON::success(array('data' => array('categories'=>$categories)));
diff --git a/apps/contacts/ajax/categories/rescan.php b/apps/contacts/ajax/categories/rescan.php
index dd27192baa0..5f1057bab44 100644
--- a/apps/contacts/ajax/categories/rescan.php
+++ b/apps/contacts/ajax/categories/rescan.php
@@ -36,13 +36,8 @@ if(count($contacts) == 0) {
bailOut(OC_Contacts_App::$l10n->t('No contacts found.'));
}
-$cards = array();
-foreach($contacts as $contact) {
- $cards[] = $contact['carddata'];
-}
-
-OC_Contacts_App::$categories->rescan($cards);
-$categories = OC_Contacts_App::$categories->categories();
+OC_Contacts_App::scanCategories($contacts);
+$categories = OC_Contacts_App::getCategories();
OC_JSON::success(array('data' => array('categories'=>$categories)));
diff --git a/apps/contacts/index.php b/apps/contacts/index.php
index 776c57ca605..97117c329b2 100644
--- a/apps/contacts/index.php
+++ b/apps/contacts/index.php
@@ -35,25 +35,6 @@ if(!is_null($id)) {
$property_types = OC_Contacts_App::getAddPropertyOptions();
$phone_types = OC_Contacts_App::getTypesOfProperty('TEL');
$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) {
- $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'));
diff --git a/apps/contacts/lib/app.php b/apps/contacts/lib/app.php
index cc33c733007..f6f6e619075 100644
--- a/apps/contacts/lib/app.php
+++ b/apps/contacts/lib/app.php
@@ -156,7 +156,45 @@ class OC_Contacts_App {
}
public static function getCategories() {
- return self::$categories->categories();
+ $categories = self::$categories->categories();
+ if(count($categories) == 0) {
+ self::scanCategories();
+ $categories = self::$categories->categories();
+ }
+ return $categories;
+ }
+
+ /**
+ * scan vcards for categories.
+ * @param $vccontacts VCards to scan. null to check all vcards for the current user.
+ */
+ public static function scanCategories($vccontacts = null) {
+ if (is_null($vccontacts)) {
+ $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(is_array($vccontacts) && count($vccontacts) > 0) {
+ $cards = array();
+ foreach($vccontacts as $vccontact) {
+ $cards[] = $vccontact['carddata'];
+ }
+
+ self::$categories->rescan($cards);
+ }
+ }
+
+ /**
+ * check VCard for new categories.
+ * @see OC_VCategories::loadFromVObject
+ */
+ public static function loadCategoriesFromVCard(OC_VObject $contact) {
+ self::$categories->loadFromVObject($contact);
}
public static function setLastModifiedHeader($contact) {
diff --git a/apps/contacts/lib/vcard.php b/apps/contacts/lib/vcard.php
index 15a6176d40c..1502423b90f 100644
--- a/apps/contacts/lib/vcard.php
+++ b/apps/contacts/lib/vcard.php
@@ -234,7 +234,7 @@ class OC_Contacts_VCard{
return null;
};
- OC_Contacts_App::$categories->loadFromVObject($card);
+ OC_Contacts_App::loadCategoriesFromVCard($card);
self::updateValuesFromAdd($card);
@@ -306,7 +306,7 @@ class OC_Contacts_VCard{
return false;
}
- OC_Contacts_App::$categories->loadFromVObject($card);
+ OC_Contacts_App::loadCategoriesFromVCard($card);
$fn = $card->getAsString('FN');
if (empty($fn)) {