aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/lib/ExpireSharesJob.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_sharing/lib/ExpireSharesJob.php')
-rw-r--r--apps/files_sharing/lib/ExpireSharesJob.php78
1 files changed, 40 insertions, 38 deletions
diff --git a/apps/files_sharing/lib/ExpireSharesJob.php b/apps/files_sharing/lib/ExpireSharesJob.php
index 39965336bff..b1c6c592e80 100644
--- a/apps/files_sharing/lib/ExpireSharesJob.php
+++ b/apps/files_sharing/lib/ExpireSharesJob.php
@@ -1,51 +1,44 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * 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, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
-
namespace OCA\Files_Sharing;
-use OC\BackgroundJob\TimedJob;
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\BackgroundJob\TimedJob;
+use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\IDBConnection;
+use OCP\Share\Exceptions\ShareNotFound;
+use OCP\Share\IManager;
+use OCP\Share\IShare;
/**
* Delete all shares that are expired
*/
class ExpireSharesJob extends TimedJob {
- /**
- * sets the correct interval for this timed job
- */
- public function __construct() {
+ public function __construct(
+ ITimeFactory $time,
+ private IManager $shareManager,
+ private IDBConnection $db,
+ ) {
+ parent::__construct($time);
+
// Run once a day
$this->setInterval(24 * 60 * 60);
+ $this->setTimeSensitivity(self::TIME_INSENSITIVE);
}
+
/**
* 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');
@@ -53,25 +46,34 @@ 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(
- $qb->expr()->eq('share_type', $qb->expr()->literal(\OCP\Share::SHARE_TYPE_LINK)),
+ $qb->expr()->in('share_type', $qb->createNamedParameter([IShare::TYPE_LINK, IShare::TYPE_EMAIL], IQueryBuilder::PARAM_INT_ARRAY)),
$qb->expr()->lte('expiration', $qb->expr()->literal($now)),
- $qb->expr()->orX(
- $qb->expr()->eq('item_type', $qb->expr()->literal('file')),
- $qb->expr()->eq('item_type', $qb->expr()->literal('folder'))
- )
+ $qb->expr()->in('item_type', $qb->createNamedParameter(['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY))
)
);
- $shares = $qb->execute();
- while($share = $shares->fetch()) {
- \OC\Share\Share::unshare($share['item_type'], $share['file_source'], \OCP\Share::SHARE_TYPE_LINK, null, $share['uid_owner']);
+ $shares = $qb->executeQuery();
+ while ($share = $shares->fetch()) {
+ 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();
}
-
}