diff options
author | Morris Jobke <hey@morrisjobke.de> | 2020-11-19 23:20:47 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-19 23:20:47 +0100 |
commit | 46f406a8be63086eecd2130002ac3f130544958f (patch) | |
tree | 6b89e558393341444cecabba9edba34b15be6a1a /apps/files_sharing/lib | |
parent | 700449882ab3c7d0c5c6f91befe95ab1b60491a9 (diff) | |
parent | 220bc1f21878c550e0d1ab32265f604fc9542f87 (diff) | |
download | nextcloud-server-46f406a8be63086eecd2130002ac3f130544958f.tar.gz nextcloud-server-46f406a8be63086eecd2130002ac3f130544958f.zip |
Merge pull request #24017 from nextcloud/enh/share_expiration
Make the expire shares cron job actually expire the shares
Diffstat (limited to 'apps/files_sharing/lib')
-rw-r--r-- | apps/files_sharing/lib/ExpireSharesJob.php | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/apps/files_sharing/lib/ExpireSharesJob.php b/apps/files_sharing/lib/ExpireSharesJob.php index 5e48dd9ffd7..eb13a13daa9 100644 --- a/apps/files_sharing/lib/ExpireSharesJob.php +++ b/apps/files_sharing/lib/ExpireSharesJob.php @@ -24,7 +24,11 @@ namespace OCA\Files_Sharing; -use OC\BackgroundJob\TimedJob; +use OCP\AppFramework\Utility\ITimeFactory; +use OCP\BackgroundJob\TimedJob; +use OCP\IDBConnection; +use OCP\Share\Exceptions\ShareNotFound; +use OCP\Share\IManager; use OCP\Share\IShare; /** @@ -32,22 +36,29 @@ use OCP\Share\IShare; */ class ExpireSharesJob extends TimedJob { - /** - * sets the correct interval for this timed job - */ - public function __construct() { + /** @var IManager */ + private $shareManager; + + /** @var IDBConnection */ + private $db; + + public function __construct(ITimeFactory $time, IManager $shareManager, IDBConnection $db) { + $this->shareManager = $shareManager; + $this->db = $db; + + parent::__construct($time); + // Run once a day $this->setInterval(24 * 60 * 60); } + /** * Makes the background job do its work * * @param array $argument unused argument */ public function run($argument) { - $connection = \OC::$server->getDatabaseConnection(); - //Current time $now = new \DateTime(); $now = $now->format('Y-m-d H:i:s'); @@ -55,8 +66,8 @@ class ExpireSharesJob extends TimedJob { /* * Expire file link shares only (for now) */ - $qb = $connection->getQueryBuilder(); - $qb->select('id', 'file_source', 'uid_owner', 'item_type') + $qb = $this->db->getQueryBuilder(); + $qb->select('id', 'share_type') ->from('share') ->where( $qb->expr()->andX( @@ -74,7 +85,20 @@ class ExpireSharesJob extends TimedJob { $shares = $qb->execute(); while ($share = $shares->fetch()) { - \OC\Share\Share::unshare($share['item_type'], $share['file_source'], IShare::TYPE_LINK, null, $share['uid_owner']); + if ((int)$share['share_type'] === IShare::TYPE_LINK) { + $id = 'ocinternal'; + } elseif ((int)$share['share_type'] === IShare::TYPE_EMAIL) { + $id = 'ocMailShare'; + } + + $id .= ':' . $share['id']; + + try { + $share = $this->shareManager->getShareById($id); + $this->shareManager->deleteShare($share); + } catch (ShareNotFound $e) { + // Normally the share gets automatically expired on fetching it + } } $shares->closeCursor(); } |