You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GenerateBirthdayCalendarBackgroundJob.php 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * @copyright 2017 Georg Ehrke <oc.list@georgehrke.com>
  4. *
  5. * @author Georg Ehrke <oc.list@georgehrke.com>
  6. * @author Roeland Jago Douma <roeland@famdouma.nl>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\DAV\BackgroundJob;
  25. use OC\BackgroundJob\QueuedJob;
  26. use OCA\DAV\CalDAV\BirthdayService;
  27. use OCP\IConfig;
  28. class GenerateBirthdayCalendarBackgroundJob extends QueuedJob {
  29. /** @var BirthdayService */
  30. private $birthdayService;
  31. /** @var IConfig */
  32. private $config;
  33. /**
  34. * GenerateAllBirthdayCalendarsBackgroundJob constructor.
  35. *
  36. * @param BirthdayService $birthdayService
  37. * @param IConfig $config
  38. */
  39. public function __construct(BirthdayService $birthdayService,
  40. IConfig $config) {
  41. $this->birthdayService = $birthdayService;
  42. $this->config = $config;
  43. }
  44. /**
  45. * @param array $arguments
  46. */
  47. public function run($arguments) {
  48. $userId = $arguments['userId'];
  49. $purgeBeforeGenerating = $arguments['purgeBeforeGenerating'] ?? false;
  50. // make sure admin didn't change his mind
  51. $isGloballyEnabled = $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes');
  52. if ($isGloballyEnabled !== 'yes') {
  53. return;
  54. }
  55. // did the user opt out?
  56. $isUserEnabled = $this->config->getUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes');
  57. if ($isUserEnabled !== 'yes') {
  58. return;
  59. }
  60. if ($purgeBeforeGenerating) {
  61. $this->birthdayService->resetForUser($userId);
  62. }
  63. $this->birthdayService->syncUser($userId);
  64. }
  65. }