1
0

GenerateBirthdayCalendarBackgroundJob.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\DAV\BackgroundJob;
  8. use OCA\DAV\CalDAV\BirthdayService;
  9. use OCP\AppFramework\Utility\ITimeFactory;
  10. use OCP\BackgroundJob\QueuedJob;
  11. use OCP\IConfig;
  12. class GenerateBirthdayCalendarBackgroundJob extends QueuedJob {
  13. /** @var BirthdayService */
  14. private $birthdayService;
  15. /** @var IConfig */
  16. private $config;
  17. public function __construct(ITimeFactory $time,
  18. BirthdayService $birthdayService,
  19. IConfig $config) {
  20. parent::__construct($time);
  21. $this->birthdayService = $birthdayService;
  22. $this->config = $config;
  23. }
  24. public function run($argument) {
  25. $userId = $argument['userId'];
  26. $purgeBeforeGenerating = $argument['purgeBeforeGenerating'] ?? false;
  27. // make sure admin didn't change his mind
  28. $isGloballyEnabled = $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes');
  29. if ($isGloballyEnabled !== 'yes') {
  30. return;
  31. }
  32. // did the user opt out?
  33. $isUserEnabled = $this->config->getUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes');
  34. if ($isUserEnabled !== 'yes') {
  35. return;
  36. }
  37. if ($purgeBeforeGenerating) {
  38. $this->birthdayService->resetForUser($userId);
  39. }
  40. $this->birthdayService->syncUser($userId);
  41. }
  42. }