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

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