GenerateBirthdayCalendarBackgroundJob.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. public function __construct(
  14. ITimeFactory $time,
  15. private BirthdayService $birthdayService,
  16. private IConfig $config,
  17. ) {
  18. parent::__construct($time);
  19. }
  20. public function run($argument) {
  21. $userId = $argument['userId'];
  22. $purgeBeforeGenerating = $argument['purgeBeforeGenerating'] ?? false;
  23. // make sure admin didn't change their mind
  24. $isGloballyEnabled = $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes');
  25. if ($isGloballyEnabled !== 'yes') {
  26. return;
  27. }
  28. // did the user opt out?
  29. $isUserEnabled = $this->config->getUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes');
  30. if ($isUserEnabled !== 'yes') {
  31. return;
  32. }
  33. if ($purgeBeforeGenerating) {
  34. $this->birthdayService->resetForUser($userId);
  35. }
  36. $this->birthdayService->syncUser($userId);
  37. }
  38. }