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.

76 lines
2.1 KiB

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