2018-04-13 07:58:24 -04:00
|
|
|
<?php
|
2019-12-03 13:57:53 -05:00
|
|
|
|
2018-04-13 07:58:24 -04:00
|
|
|
declare(strict_types=1);
|
2019-12-03 13:57:53 -05:00
|
|
|
|
2018-04-13 07:58:24 -04:00
|
|
|
/**
|
2024-05-27 11:39:07 -04:00
|
|
|
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2018-04-13 07:58:24 -04:00
|
|
|
*/
|
|
|
|
|
namespace OCA\DAV\Db;
|
|
|
|
|
|
2018-04-13 11:11:25 -04:00
|
|
|
use OCP\AppFramework\Db\DoesNotExistException;
|
2021-03-02 15:08:37 -05:00
|
|
|
use OCP\AppFramework\Db\QBMapper;
|
2018-04-13 07:58:24 -04:00
|
|
|
use OCP\IDBConnection;
|
|
|
|
|
|
2021-03-02 15:08:37 -05:00
|
|
|
/**
|
|
|
|
|
* @template-extends QBMapper<Direct>
|
|
|
|
|
*/
|
|
|
|
|
class DirectMapper extends QBMapper {
|
2018-04-13 10:54:24 -04:00
|
|
|
public function __construct(IDBConnection $db) {
|
2018-04-13 07:58:24 -04:00
|
|
|
parent::__construct($db, 'directlink', Direct::class);
|
|
|
|
|
}
|
2018-04-13 11:11:25 -04:00
|
|
|
|
2018-04-23 16:32:41 -04:00
|
|
|
/**
|
|
|
|
|
* @param string $token
|
|
|
|
|
* @return Direct
|
|
|
|
|
* @throws DoesNotExistException
|
|
|
|
|
*/
|
2018-04-13 11:11:25 -04:00
|
|
|
public function getByToken(string $token): Direct {
|
|
|
|
|
$qb = $this->db->getQueryBuilder();
|
|
|
|
|
|
|
|
|
|
$qb->select('*')
|
2021-03-02 15:08:37 -05:00
|
|
|
->from($this->getTableName())
|
2018-04-13 11:11:25 -04:00
|
|
|
->where(
|
|
|
|
|
$qb->expr()->eq('token', $qb->createNamedParameter($token))
|
|
|
|
|
);
|
|
|
|
|
|
2021-03-02 15:08:37 -05:00
|
|
|
return parent::findEntity($qb);
|
2018-04-13 11:11:25 -04:00
|
|
|
}
|
2018-04-23 16:32:41 -04:00
|
|
|
|
|
|
|
|
public function deleteExpired(int $expiration) {
|
|
|
|
|
$qb = $this->db->getQueryBuilder();
|
|
|
|
|
|
2021-03-02 15:08:37 -05:00
|
|
|
$qb->delete($this->getTableName())
|
2018-04-23 16:32:41 -04:00
|
|
|
->where(
|
|
|
|
|
$qb->expr()->lt('expiration', $qb->createNamedParameter($expiration))
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$qb->execute();
|
|
|
|
|
}
|
2018-04-13 07:58:24 -04:00
|
|
|
}
|