diff --git a/apps/dav/appinfo/info.xml b/apps/dav/appinfo/info.xml index 4952fa3353..d31851fe17 100644 --- a/apps/dav/appinfo/info.xml +++ b/apps/dav/appinfo/info.xml @@ -5,7 +5,7 @@ WebDAV WebDAV endpoint WebDAV endpoint - 1.5.1 + 1.5.2 agpl owncloud.org DAV @@ -19,6 +19,10 @@ + + OCA\DAV\BackgroundJob\CleanupDirectLinksJob + + OCA\DAV\Migration\FixBirthdayCalendarComponent diff --git a/apps/dav/composer/composer/autoload_classmap.php b/apps/dav/composer/composer/autoload_classmap.php index 1f48e74ca4..50689568eb 100644 --- a/apps/dav/composer/composer/autoload_classmap.php +++ b/apps/dav/composer/composer/autoload_classmap.php @@ -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', diff --git a/apps/dav/composer/composer/autoload_static.php b/apps/dav/composer/composer/autoload_static.php index cba72bc03c..760ca3426f 100644 --- a/apps/dav/composer/composer/autoload_static.php +++ b/apps/dav/composer/composer/autoload_static.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', diff --git a/apps/dav/lib/BackgroundJob/CleanupDirectLinksJob.php b/apps/dav/lib/BackgroundJob/CleanupDirectLinksJob.php new file mode 100644 index 0000000000..ba1049071a --- /dev/null +++ b/apps/dav/lib/BackgroundJob/CleanupDirectLinksJob.php @@ -0,0 +1,50 @@ + + * + * @author Roeland Jago Douma + * + * @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 . + * + */ + +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); + } + +} diff --git a/apps/dav/lib/Db/DirectMapper.php b/apps/dav/lib/Db/DirectMapper.php index 806b145823..d0db4b8287 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(); + } }