1
0

ScheduledNotifications.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\FilesReminders\BackgroundJob;
  8. use OCA\FilesReminders\Db\ReminderMapper;
  9. use OCA\FilesReminders\Service\ReminderService;
  10. use OCP\AppFramework\Db\DoesNotExistException;
  11. use OCP\AppFramework\Utility\ITimeFactory;
  12. use OCP\BackgroundJob\Job;
  13. use Psr\Log\LoggerInterface;
  14. class ScheduledNotifications extends Job {
  15. public function __construct(
  16. ITimeFactory $time,
  17. protected ReminderMapper $reminderMapper,
  18. protected ReminderService $reminderService,
  19. protected LoggerInterface $logger,
  20. ) {
  21. parent::__construct($time);
  22. }
  23. /**
  24. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  25. */
  26. public function run($argument) {
  27. $reminders = $this->reminderMapper->findOverdue();
  28. foreach ($reminders as $reminder) {
  29. try {
  30. $this->reminderService->send($reminder);
  31. } catch (DoesNotExistException $e) {
  32. $this->logger->debug('Could not send notification for reminder with id ' . $reminder->getId());
  33. }
  34. }
  35. }
  36. }