You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ExpireSharesJob.php 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OCA\Files_Sharing;
  25. use OC\BackgroundJob\TimedJob;
  26. use OCP\Share\IShare;
  27. /**
  28. * Delete all shares that are expired
  29. */
  30. class ExpireSharesJob extends TimedJob {
  31. /**
  32. * sets the correct interval for this timed job
  33. */
  34. public function __construct() {
  35. // Run once a day
  36. $this->setInterval(24 * 60 * 60);
  37. }
  38. /**
  39. * Makes the background job do its work
  40. *
  41. * @param array $argument unused argument
  42. */
  43. public function run($argument) {
  44. $connection = \OC::$server->getDatabaseConnection();
  45. //Current time
  46. $now = new \DateTime();
  47. $now = $now->format('Y-m-d H:i:s');
  48. /*
  49. * Expire file link shares only (for now)
  50. */
  51. $qb = $connection->getQueryBuilder();
  52. $qb->select('id', 'file_source', 'uid_owner', 'item_type')
  53. ->from('share')
  54. ->where(
  55. $qb->expr()->andX(
  56. $qb->expr()->eq('share_type', $qb->expr()->literal(IShare::TYPE_LINK)),
  57. $qb->expr()->lte('expiration', $qb->expr()->literal($now)),
  58. $qb->expr()->orX(
  59. $qb->expr()->eq('item_type', $qb->expr()->literal('file')),
  60. $qb->expr()->eq('item_type', $qb->expr()->literal('folder'))
  61. )
  62. )
  63. );
  64. $shares = $qb->execute();
  65. while ($share = $shares->fetch()) {
  66. \OC\Share\Share::unshare($share['item_type'], $share['file_source'], IShare::TYPE_LINK, null, $share['uid_owner']);
  67. }
  68. $shares->closeCursor();
  69. }
  70. }