|
|
|
|
@ -27,10 +27,13 @@ declare(strict_types=1);
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
@ -44,26 +47,18 @@ class DirectMapper extends Mapper {
|
|
|
|
|
$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))
|
|
|
|
|
);
|
|
|
|
|
|