Add backgroundjob to cleanup expired direct links
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
parent
042340ccf6
commit
b6c58e75b7
|
@ -5,7 +5,7 @@
|
|||
<name>WebDAV</name>
|
||||
<summary>WebDAV endpoint</summary>
|
||||
<description>WebDAV endpoint</description>
|
||||
<version>1.5.1</version>
|
||||
<version>1.5.2</version>
|
||||
<licence>agpl</licence>
|
||||
<author>owncloud.org</author>
|
||||
<namespace>DAV</namespace>
|
||||
|
@ -19,6 +19,10 @@
|
|||
<nextcloud min-version="14" max-version="14" />
|
||||
</dependencies>
|
||||
|
||||
<background-jobs>
|
||||
<job>OCA\DAV\BackgroundJob\CleanupDirectLinksJob</job>
|
||||
</background-jobs>
|
||||
|
||||
<repair-steps>
|
||||
<post-migration>
|
||||
<step>OCA\DAV\Migration\FixBirthdayCalendarComponent</step>
|
||||
|
|
|
@ -11,6 +11,7 @@ return array(
|
|||
'OCA\\DAV\\Avatars\\AvatarHome' => $baseDir . '/../lib/Avatars/AvatarHome.php',
|
||||
'OCA\\DAV\\Avatars\\AvatarNode' => $baseDir . '/../lib/Avatars/AvatarNode.php',
|
||||
'OCA\\DAV\\Avatars\\RootCollection' => $baseDir . '/../lib/Avatars/RootCollection.php',
|
||||
'OCA\\DAV\\BackgroundJob\\CleanupDirectLinksJob' => $baseDir . '/../lib/BackgroundJob/CleanupDirectLinksJob.php',
|
||||
'OCA\\DAV\\BackgroundJob\\GenerateBirthdayCalendarBackgroundJob' => $baseDir . '/../lib/BackgroundJob/GenerateBirthdayCalendarBackgroundJob.php',
|
||||
'OCA\\DAV\\CalDAV\\Activity\\Backend' => $baseDir . '/../lib/CalDAV/Activity/Backend.php',
|
||||
'OCA\\DAV\\CalDAV\\Activity\\Filter\\Calendar' => $baseDir . '/../lib/CalDAV/Activity/Filter/Calendar.php',
|
||||
|
|
|
@ -26,6 +26,7 @@ class ComposerStaticInitDAV
|
|||
'OCA\\DAV\\Avatars\\AvatarHome' => __DIR__ . '/..' . '/../lib/Avatars/AvatarHome.php',
|
||||
'OCA\\DAV\\Avatars\\AvatarNode' => __DIR__ . '/..' . '/../lib/Avatars/AvatarNode.php',
|
||||
'OCA\\DAV\\Avatars\\RootCollection' => __DIR__ . '/..' . '/../lib/Avatars/RootCollection.php',
|
||||
'OCA\\DAV\\BackgroundJob\\CleanupDirectLinksJob' => __DIR__ . '/..' . '/../lib/BackgroundJob/CleanupDirectLinksJob.php',
|
||||
'OCA\\DAV\\BackgroundJob\\GenerateBirthdayCalendarBackgroundJob' => __DIR__ . '/..' . '/../lib/BackgroundJob/GenerateBirthdayCalendarBackgroundJob.php',
|
||||
'OCA\\DAV\\CalDAV\\Activity\\Backend' => __DIR__ . '/..' . '/../lib/CalDAV/Activity/Backend.php',
|
||||
'OCA\\DAV\\CalDAV\\Activity\\Filter\\Calendar' => __DIR__ . '/..' . '/../lib/CalDAV/Activity/Filter/Calendar.php',
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\DAV\BackgroundJob;
|
||||
|
||||
use OC\BackgroundJob\TimedJob;
|
||||
use OCA\DAV\Db\DirectMapper;
|
||||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
|
||||
class CleanupDirectLinksJob extends TimedJob {
|
||||
/** @var ITimeFactory */
|
||||
private $timeFactory;
|
||||
|
||||
/** @var DirectMapper */
|
||||
private $mapper;
|
||||
|
||||
public function __construct(ITimeFactory $timeFactory, DirectMapper $mapper) {
|
||||
$this->setInterval(60*60*24);
|
||||
|
||||
$this->timeFactory = $timeFactory;
|
||||
$this->mapper = $mapper;
|
||||
}
|
||||
|
||||
protected function run($argument) {
|
||||
// Delete all shares expired 24 hours ago
|
||||
$this->mapper->deleteExpired($this->timeFactory->getTime() - 60*60*24);
|
||||
}
|
||||
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue