|
|
@ -7,6 +7,7 @@ |
|
|
|
*/ |
|
|
|
namespace OCA\Files_Sharing; |
|
|
|
|
|
|
|
use Exception; |
|
|
|
use OCP\AppFramework\Utility\ITimeFactory; |
|
|
|
use OCP\BackgroundJob\TimedJob; |
|
|
|
use OCP\DB\QueryBuilder\IQueryBuilder; |
|
|
@ -14,6 +15,8 @@ use OCP\IDBConnection; |
|
|
|
use OCP\Share\Exceptions\ShareNotFound; |
|
|
|
use OCP\Share\IManager; |
|
|
|
use OCP\Share\IShare; |
|
|
|
use OCP\Share\IProviderFactory; |
|
|
|
use Psr\Log\LoggerInterface; |
|
|
|
|
|
|
|
/** |
|
|
|
* Delete all shares that are expired |
|
|
@ -23,7 +26,9 @@ class ExpireSharesJob extends TimedJob { |
|
|
|
public function __construct( |
|
|
|
ITimeFactory $time, |
|
|
|
private IManager $shareManager, |
|
|
|
private IProviderFactory $factory, |
|
|
|
private IDBConnection $db, |
|
|
|
private LoggerInterface $logger, |
|
|
|
) { |
|
|
|
parent::__construct($time); |
|
|
|
|
|
|
@ -44,14 +49,13 @@ class ExpireSharesJob extends TimedJob { |
|
|
|
$now = $now->format('Y-m-d H:i:s'); |
|
|
|
|
|
|
|
/* |
|
|
|
* Expire file link shares only (for now) |
|
|
|
* Expire all shares |
|
|
|
*/ |
|
|
|
$qb = $this->db->getQueryBuilder(); |
|
|
|
$qb->select('id', 'share_type') |
|
|
|
->from('share') |
|
|
|
->where( |
|
|
|
$qb->expr()->andX( |
|
|
|
$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()->in('item_type', $qb->createNamedParameter(['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY)) |
|
|
|
) |
|
|
@ -59,19 +63,24 @@ class ExpireSharesJob extends TimedJob { |
|
|
|
|
|
|
|
$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 { |
|
|
|
$provider = $this->factory->getProviderForType((int)$share['share_type'])->identifier(); // returns something like ocinternal, ocMailShare
|
|
|
|
$id = $provider . ':' . $share['id']; |
|
|
|
$share = $this->shareManager->getShareById($id); |
|
|
|
$this->shareManager->deleteShare($share); |
|
|
|
} catch (ShareNotFound $e) { |
|
|
|
// Normally the share gets automatically expired on fetching it
|
|
|
|
$this->logger->debug('Got share not found for share with id {share_id} of type {share_type}. Got {e}', [ |
|
|
|
'share_id' => $share['id'], |
|
|
|
'share_type' => $share['share_type'], |
|
|
|
'error' => $e, |
|
|
|
]); |
|
|
|
} catch (Exception $e ) { |
|
|
|
$this->logger->error('Something unexpected happened while trying to expire a share with id {share_id} of type {share_type}. Got {e}', [ |
|
|
|
'share_id' => $share['id'], |
|
|
|
'share_type' => $share['share_type'], |
|
|
|
'error' => $e, |
|
|
|
]); |
|
|
|
} |
|
|
|
} |
|
|
|
$shares->closeCursor(); |
|
|
|