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.

ExpireVersions.php 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 Jörn Friedrich Dreyer <jfd@butonic.de>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. * @author Victor Dubiniuk <dubiniuk@owncloud.com>
  10. *
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. namespace OCA\Files_Versions\BackgroundJob;
  27. use OCA\Files_Versions\Expiration;
  28. use OCA\Files_Versions\Storage;
  29. use OCP\IUser;
  30. use OCP\IUserManager;
  31. class ExpireVersions extends \OC\BackgroundJob\TimedJob {
  32. public const ITEMS_PER_SESSION = 1000;
  33. /**
  34. * @var Expiration
  35. */
  36. private $expiration;
  37. /**
  38. * @var IUserManager
  39. */
  40. private $userManager;
  41. public function __construct(IUserManager $userManager, Expiration $expiration) {
  42. // Run once per 30 minutes
  43. $this->setInterval(60 * 30);
  44. $this->expiration = $expiration;
  45. $this->userManager = $userManager;
  46. }
  47. protected function run($argument) {
  48. $maxAge = $this->expiration->getMaxAgeAsTimestamp();
  49. if (!$maxAge) {
  50. return;
  51. }
  52. $this->userManager->callForSeenUsers(function (IUser $user) {
  53. $uid = $user->getUID();
  54. if (!$this->setupFS($uid)) {
  55. return;
  56. }
  57. Storage::expireOlderThanMaxForUser($uid);
  58. });
  59. }
  60. /**
  61. * Act on behalf on trash item owner
  62. * @param string $user
  63. * @return boolean
  64. */
  65. protected function setupFS($user) {
  66. \OC_Util::tearDownFS();
  67. \OC_Util::setupFS($user);
  68. // Check if this user has a versions directory
  69. $view = new \OC\Files\View('/' . $user);
  70. if (!$view->is_dir('/files_versions')) {
  71. return false;
  72. }
  73. return true;
  74. }
  75. }