Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions apps/dav/lib/Db/DirectMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@
namespace OCA\DAV\Db;

use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\Mapper;
use OCP\AppFramework\Db\QBMapper;
use OCP\IDBConnection;

class DirectMapper extends Mapper {
/**
* @template-extends QBMapper<Direct>
*/
class DirectMapper extends QBMapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'directlink', Direct::class);
}
Expand All @@ -44,26 +47,18 @@ public function getByToken(string $token): Direct {
$qb = $this->db->getQueryBuilder();

$qb->select('*')
->from('directlink')
->from($this->getTableName())
->where(
$qb->expr()->eq('token', $qb->createNamedParameter($token))
);

$cursor = $qb->execute();
$data = $cursor->fetch();
$cursor->closeCursor();

if ($data === false) {
throw new DoesNotExistException('Direct link with token does not exist');
}

return Direct::fromRow($data);
return parent::findEntity($qb);
}

public function deleteExpired(int $expiration) {
$qb = $this->db->getQueryBuilder();

$qb->delete('directlink')
$qb->delete($this->getTableName())
->where(
$qb->expr()->lt('expiration', $qb->createNamedParameter($expiration))
);
Expand Down
2 changes: 2 additions & 0 deletions apps/dav/tests/unit/Controller/DirectControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ public function testGetUrlValid() {
$this->assertSame(101, $direct->getFileId());
$this->assertSame('superduperlongtoken', $direct->getToken());
$this->assertSame(42 + 60 * 60 * 8, $direct->getExpiration());

return $direct;
});

$this->urlGenerator->method('getAbsoluteURL')
Expand Down