CleanupInvitationTokenJob.php 879 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\DAV\BackgroundJob;
  8. use OCP\AppFramework\Utility\ITimeFactory;
  9. use OCP\BackgroundJob\TimedJob;
  10. use OCP\IDBConnection;
  11. class CleanupInvitationTokenJob extends TimedJob {
  12. /** @var IDBConnection */
  13. private $db;
  14. public function __construct(IDBConnection $db, ITimeFactory $time) {
  15. parent::__construct($time);
  16. $this->db = $db;
  17. // Run once a day at off-peak time
  18. $this->setInterval(24 * 60 * 60);
  19. $this->setTimeSensitivity(self::TIME_INSENSITIVE);
  20. }
  21. public function run($argument) {
  22. $query = $this->db->getQueryBuilder();
  23. $query->delete('calendar_invitations')
  24. ->where($query->expr()->lt('expiration',
  25. $query->createNamedParameter($this->time->getTime())))
  26. ->execute();
  27. }
  28. }