123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- namespace OCA\Files_Sharing;
- use OC\BackgroundJob\TimedJob;
- use OCP\Share\IShare;
- class ExpireSharesJob extends TimedJob {
-
- public function __construct() {
-
- $this->setInterval(24 * 60 * 60);
- }
-
- public function run($argument) {
- $connection = \OC::$server->getDatabaseConnection();
-
- $now = new \DateTime();
- $now = $now->format('Y-m-d H:i:s');
-
- $qb = $connection->getQueryBuilder();
- $qb->select('id', 'file_source', 'uid_owner', 'item_type')
- ->from('share')
- ->where(
- $qb->expr()->andX(
- $qb->expr()->orX(
- $qb->expr()->eq('share_type', $qb->expr()->literal(IShare::TYPE_LINK)),
- $qb->expr()->eq('share_type', $qb->expr()->literal(IShare::TYPE_EMAIL))
- ),
- $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'))
- )
- )
- );
- $shares = $qb->execute();
- while ($share = $shares->fetch()) {
- \OC\Share\Share::unshare($share['item_type'], $share['file_source'], IShare::TYPE_LINK, null, $share['uid_owner']);
- }
- $shares->closeCursor();
- }
- }
|