ClearOldStatusesBackgroundJob.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\UserStatus\BackgroundJob;
  8. use OCA\UserStatus\Db\UserStatusMapper;
  9. use OCA\UserStatus\Service\StatusService;
  10. use OCP\AppFramework\Utility\ITimeFactory;
  11. use OCP\BackgroundJob\TimedJob;
  12. /**
  13. * Class ClearOldStatusesBackgroundJob
  14. *
  15. * @package OCA\UserStatus\BackgroundJob
  16. */
  17. class ClearOldStatusesBackgroundJob extends TimedJob {
  18. /**
  19. * ClearOldStatusesBackgroundJob constructor.
  20. *
  21. * @param ITimeFactory $time
  22. * @param UserStatusMapper $mapper
  23. */
  24. public function __construct(
  25. ITimeFactory $time,
  26. private UserStatusMapper $mapper,
  27. ) {
  28. parent::__construct($time);
  29. // Run every time the cron is run
  30. $this->setInterval(0);
  31. }
  32. /**
  33. * @inheritDoc
  34. */
  35. protected function run($argument) {
  36. $now = $this->time->getTime();
  37. $this->mapper->clearOlderThanClearAt($now);
  38. $this->mapper->clearStatusesOlderThan($now - StatusService::INVALIDATE_STATUS_THRESHOLD, $now);
  39. }
  40. }