rescan.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * Copyright (c) 2012 Thomas Tanghus <thomas@tanghus.net>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. OCP\JSON::checkLoggedIn();
  9. OCP\JSON::checkAppEnabled('contacts');
  10. foreach ($_POST as $key=>$element) {
  11. debug('_POST: '.$key.'=>'.print_r($element, true));
  12. }
  13. function bailOut($msg) {
  14. OCP\JSON::error(array('data' => array('message' => $msg)));
  15. OCP\Util::writeLog('contacts','ajax/categories/rescan.php: '.$msg, OCP\Util::DEBUG);
  16. exit();
  17. }
  18. function debug($msg) {
  19. OCP\Util::writeLog('contacts','ajax/categories/rescan.php: '.$msg, OCP\Util::DEBUG);
  20. }
  21. $addressbooks = OC_Contacts_Addressbook::all(OCP\USER::getUser());
  22. if(count($addressbooks) == 0) {
  23. bailOut(OC_Contacts_App::$l10n->t('No address books found.'));
  24. }
  25. $addressbookids = array();
  26. foreach($addressbooks as $addressbook) {
  27. $addressbookids[] = $addressbook['id'];
  28. }
  29. $contacts = OC_Contacts_VCard::all($addressbookids);
  30. if(count($contacts) == 0) {
  31. bailOut(OC_Contacts_App::$l10n->t('No contacts found.'));
  32. }
  33. OC_Contacts_App::scanCategories($contacts);
  34. $categories = OC_Contacts_App::getCategories();
  35. OCP\JSON::success(array('data' => array('categories'=>$categories)));
  36. ?>