1
0

DirectMapper.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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\Db;
  8. use OCP\AppFramework\Db\DoesNotExistException;
  9. use OCP\AppFramework\Db\QBMapper;
  10. use OCP\IDBConnection;
  11. /**
  12. * @template-extends QBMapper<Direct>
  13. */
  14. class DirectMapper extends QBMapper {
  15. public function __construct(IDBConnection $db) {
  16. parent::__construct($db, 'directlink', Direct::class);
  17. }
  18. /**
  19. * @param string $token
  20. * @return Direct
  21. * @throws DoesNotExistException
  22. */
  23. public function getByToken(string $token): Direct {
  24. $qb = $this->db->getQueryBuilder();
  25. $qb->select('*')
  26. ->from($this->getTableName())
  27. ->where(
  28. $qb->expr()->eq('token', $qb->createNamedParameter($token))
  29. );
  30. return parent::findEntity($qb);
  31. }
  32. public function deleteExpired(int $expiration) {
  33. $qb = $this->db->getQueryBuilder();
  34. $qb->delete($this->getTableName())
  35. ->where(
  36. $qb->expr()->lt('expiration', $qb->createNamedParameter($expiration))
  37. );
  38. $qb->executeStatement();
  39. }
  40. }