1
0

ChangesMapper.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 OC\Updater;
  8. use OCP\AppFramework\Db\DoesNotExistException;
  9. use OCP\AppFramework\Db\QBMapper;
  10. use OCP\DB\QueryBuilder\IQueryBuilder;
  11. use OCP\IDBConnection;
  12. /**
  13. * @template-extends QBMapper<Changes>
  14. */
  15. class ChangesMapper extends QBMapper {
  16. public const TABLE_NAME = 'whats_new';
  17. public function __construct(IDBConnection $db) {
  18. parent::__construct($db, self::TABLE_NAME);
  19. }
  20. /**
  21. * @throws DoesNotExistException
  22. */
  23. public function getChanges(string $version): Changes {
  24. /* @var $qb IQueryBuilder */
  25. $qb = $this->db->getQueryBuilder();
  26. $result = $qb->select('*')
  27. ->from(self::TABLE_NAME)
  28. ->where($qb->expr()->eq('version', $qb->createNamedParameter($version)))
  29. ->executeQuery();
  30. $data = $result->fetch();
  31. $result->closeCursor();
  32. if ($data === false) {
  33. throw new DoesNotExistException('Changes info is not present');
  34. }
  35. return Changes::fromRow($data);
  36. }
  37. }