EventReminderJob.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2016 Thomas Citharel <nextcloud@tcit.fr>
  5. *
  6. * @author Georg Ehrke <oc.list@georgehrke.com>
  7. * @author Thomas Citharel <nextcloud@tcit.fr>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OCA\DAV\BackgroundJob;
  26. use OCA\DAV\CalDAV\Reminder\ReminderService;
  27. use OCP\AppFramework\Utility\ITimeFactory;
  28. use OCP\BackgroundJob\TimedJob;
  29. use OCP\IConfig;
  30. class EventReminderJob extends TimedJob {
  31. /** @var ReminderService */
  32. private $reminderService;
  33. /** @var IConfig */
  34. private $config;
  35. public function __construct(ITimeFactory $time,
  36. ReminderService $reminderService,
  37. IConfig $config) {
  38. parent::__construct($time);
  39. $this->reminderService = $reminderService;
  40. $this->config = $config;
  41. // Run every 5 minutes
  42. $this->setInterval(5 * 60);
  43. $this->setTimeSensitivity(self::TIME_SENSITIVE);
  44. }
  45. /**
  46. * @throws \OCA\DAV\CalDAV\Reminder\NotificationProvider\ProviderNotAvailableException
  47. * @throws \OCA\DAV\CalDAV\Reminder\NotificationTypeDoesNotExistException
  48. * @throws \OC\User\NoUserException
  49. */
  50. public function run($argument):void {
  51. if ($this->config->getAppValue('dav', 'sendEventReminders', 'yes') !== 'yes') {
  52. return;
  53. }
  54. if ($this->config->getAppValue('dav', 'sendEventRemindersMode', 'backgroundjob') !== 'backgroundjob') {
  55. return;
  56. }
  57. $this->reminderService->processReminders();
  58. }
  59. }