PushKeyMapper.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2023 Thomas Citharel <nextcloud@tcit.fr>
  5. *
  6. * @author Thomas Citharel <nextcloud@tcit.fr>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\DAV\Db;
  25. use OCP\AppFramework\Db\DoesNotExistException;
  26. use OCP\AppFramework\Db\QBMapper;
  27. use OCP\IDBConnection;
  28. /**
  29. * @template-extends QBMapper<PushKey>
  30. */
  31. class PushKeyMapper extends QBMapper {
  32. public function __construct(IDBConnection $db) {
  33. parent::__construct($db, 'push_transports', PushKey::class);
  34. }
  35. /**
  36. * @return PushKey[]
  37. * @throws DoesNotExistException
  38. */
  39. public function getForPrincipal(string $principalUri): array {
  40. $qb = $this->db->getQueryBuilder();
  41. $qb->select('*')
  42. ->from($this->getTableName())
  43. ->where(
  44. $qb->expr()->eq('principalUri', $qb->createNamedParameter($principalUri))
  45. )
  46. ->andWhere($qb->expr()->eq('uri', $qb->createNamedParameter(null)))
  47. ;
  48. return parent::findEntities($qb);
  49. }
  50. /**
  51. * @return PushKey[]
  52. * @throws DoesNotExistException
  53. */
  54. public function getForUri(string $principalUri, string $uri): array {
  55. $qb = $this->db->getQueryBuilder();
  56. $qb->select('*')
  57. ->from($this->getTableName())
  58. ->where(
  59. $qb->expr()->eq('principalUri', $qb->createNamedParameter($principalUri))
  60. )
  61. ->andWhere($qb->expr()->eq('uri', $qb->createNamedParameter($uri)))
  62. ;
  63. return parent::findEntities($qb);
  64. }
  65. }