rescan.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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('calendar');
  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('calendar','ajax/categories/rescan.php: '.$msg, OCP\Util::DEBUG);
  16. exit();
  17. }
  18. function debug($msg) {
  19. OCP\Util::writeLog('calendar','ajax/categories/rescan.php: '.$msg, OCP\Util::DEBUG);
  20. }
  21. $calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser());
  22. if(count($calendars) == 0) {
  23. bailOut(OC_Calendar_App::$l10n->t('No calendars found.'));
  24. }
  25. $events = array();
  26. foreach($calendars as $calendar) {
  27. $calendar_events = OC_Calendar_Object::all($calendar['id']);
  28. $events = $events + $calendar_events;
  29. }
  30. if(count($events) == 0) {
  31. bailOut(OC_Calendar_App::$l10n->t('No events found.'));
  32. }
  33. OC_Calendar_App::scanCategories($events);
  34. $categories = OC_Calendar_App::getCategoryOptions();
  35. OCP\JSON::success(array('data' => array('categories'=>$categories)));