summaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/Db
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2018-04-23 22:32:41 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2018-04-26 10:35:37 +0200
commitb6c58e75b754fc7a5f6873b51934be16a8365d8f (patch)
tree088d56a227ea0ec9990e4a8884a54008b378c734 /apps/dav/lib/Db
parent042340ccf6e7d6408390b91f6904de0425bb3c07 (diff)
downloadnextcloud-server-b6c58e75b754fc7a5f6873b51934be16a8365d8f.tar.gz
nextcloud-server-b6c58e75b754fc7a5f6873b51934be16a8365d8f.zip
Add backgroundjob to cleanup expired direct links
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/dav/lib/Db')
-rw-r--r--apps/dav/lib/Db/DirectMapper.php18
1 files changed, 17 insertions, 1 deletions
diff --git a/apps/dav/lib/Db/DirectMapper.php b/apps/dav/lib/Db/DirectMapper.php
index 806b145823e..d0db4b82879 100644
--- a/apps/dav/lib/Db/DirectMapper.php
+++ b/apps/dav/lib/Db/DirectMapper.php
@@ -34,6 +34,11 @@ class DirectMapper extends Mapper {
parent::__construct($db, 'directlink', Direct::class);
}
+ /**
+ * @param string $token
+ * @return Direct
+ * @throws DoesNotExistException
+ */
public function getByToken(string $token): Direct {
$qb = $this->db->getQueryBuilder();
@@ -48,9 +53,20 @@ class DirectMapper extends Mapper {
$cursor->closeCursor();
if ($data === false) {
- throw new DoesNotExistException();
+ throw new DoesNotExistException('Direct link with token does not exist');
}
return Direct::fromRow($data);
}
+
+ public function deleteExpired(int $expiration) {
+ $qb = $this->db->getQueryBuilder();
+
+ $qb->delete('directlink')
+ ->where(
+ $qb->expr()->lt('expiration', $qb->createNamedParameter($expiration))
+ );
+
+ $qb->execute();
+ }
}