OpenLocalEditorMapper.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Files\Db;
  8. use OCP\AppFramework\Db\DoesNotExistException;
  9. use OCP\AppFramework\Db\MultipleObjectsReturnedException;
  10. use OCP\AppFramework\Db\QBMapper;
  11. use OCP\DB\Exception;
  12. use OCP\IDBConnection;
  13. /**
  14. * @template-extends QBMapper<OpenLocalEditor>
  15. */
  16. class OpenLocalEditorMapper extends QBMapper {
  17. public function __construct(IDBConnection $db) {
  18. parent::__construct($db, 'open_local_editor', OpenLocalEditor::class);
  19. }
  20. /**
  21. * @throws DoesNotExistException
  22. * @throws MultipleObjectsReturnedException
  23. * @throws Exception
  24. */
  25. public function verifyToken(string $userId, string $pathHash, string $token): OpenLocalEditor {
  26. $qb = $this->db->getQueryBuilder();
  27. $qb->select('*')
  28. ->from($this->getTableName())
  29. ->where($qb->expr()->eq('user_id', $qb->createNamedParameter($userId)))
  30. ->andWhere($qb->expr()->eq('path_hash', $qb->createNamedParameter($pathHash)))
  31. ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token)));
  32. return $this->findEntity($qb);
  33. }
  34. public function deleteExpiredTokens(int $time): void {
  35. $qb = $this->db->getQueryBuilder();
  36. $qb->delete($this->getTableName())
  37. ->where($qb->expr()->lt('expiration_time', $qb->createNamedParameter($time)));
  38. $qb->executeStatement();
  39. }
  40. }