Merge pull request #25896 from nextcloud/techdept/qbmapper

Move DirectMapper to QBMapper
This commit is contained in:
Roeland Jago Douma 2021-03-03 14:58:51 +01:00 committed by GitHub
commit 0829fea5e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 13 deletions

View File

@ -27,10 +27,13 @@ declare(strict_types=1);
namespace OCA\DAV\Db; namespace OCA\DAV\Db;
use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\Mapper; use OCP\AppFramework\Db\QBMapper;
use OCP\IDBConnection; use OCP\IDBConnection;
class DirectMapper extends Mapper { /**
* @template-extends QBMapper<Direct>
*/
class DirectMapper extends QBMapper {
public function __construct(IDBConnection $db) { public function __construct(IDBConnection $db) {
parent::__construct($db, 'directlink', Direct::class); parent::__construct($db, 'directlink', Direct::class);
} }
@ -44,26 +47,18 @@ class DirectMapper extends Mapper {
$qb = $this->db->getQueryBuilder(); $qb = $this->db->getQueryBuilder();
$qb->select('*') $qb->select('*')
->from('directlink') ->from($this->getTableName())
->where( ->where(
$qb->expr()->eq('token', $qb->createNamedParameter($token)) $qb->expr()->eq('token', $qb->createNamedParameter($token))
); );
$cursor = $qb->execute(); return parent::findEntity($qb);
$data = $cursor->fetch();
$cursor->closeCursor();
if ($data === false) {
throw new DoesNotExistException('Direct link with token does not exist');
}
return Direct::fromRow($data);
} }
public function deleteExpired(int $expiration) { public function deleteExpired(int $expiration) {
$qb = $this->db->getQueryBuilder(); $qb = $this->db->getQueryBuilder();
$qb->delete('directlink') $qb->delete($this->getTableName())
->where( ->where(
$qb->expr()->lt('expiration', $qb->createNamedParameter($expiration)) $qb->expr()->lt('expiration', $qb->createNamedParameter($expiration))
); );

View File

@ -142,6 +142,8 @@ class DirectControllerTest extends TestCase {
$this->assertSame(101, $direct->getFileId()); $this->assertSame(101, $direct->getFileId());
$this->assertSame('superduperlongtoken', $direct->getToken()); $this->assertSame('superduperlongtoken', $direct->getToken());
$this->assertSame(42 + 60 * 60 * 8, $direct->getExpiration()); $this->assertSame(42 + 60 * 60 * 8, $direct->getExpiration());
return $direct;
}); });
$this->urlGenerator->method('getAbsoluteURL') $this->urlGenerator->method('getAbsoluteURL')