CleanupJob.php 793 B

12345678910111213141516171819202122232425262728293031323334
  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\ContactsInteraction\BackgroundJob;
  8. use OCA\ContactsInteraction\Db\RecentContactMapper;
  9. use OCP\AppFramework\Utility\ITimeFactory;
  10. use OCP\BackgroundJob\IJob;
  11. use OCP\BackgroundJob\TimedJob;
  12. class CleanupJob extends TimedJob {
  13. public function __construct(
  14. ITimeFactory $time,
  15. private RecentContactMapper $mapper,
  16. ) {
  17. parent::__construct($time);
  18. $this->setInterval(24 * 60 * 60);
  19. $this->setTimeSensitivity(IJob::TIME_INSENSITIVE);
  20. }
  21. protected function run(mixed $argument): void {
  22. $time = $this->time->getDateTime();
  23. $time->modify('-7days');
  24. $this->mapper->cleanUp($time->getTimestamp());
  25. }
  26. }