CleanupFileLocks.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Max Kovalenko <mxss1998@yandex.ru>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  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\BackgroundJob;
  25. use OC\Lock\DBLockingProvider;
  26. use OCP\AppFramework\Utility\ITimeFactory;
  27. use OCP\BackgroundJob\TimedJob;
  28. /**
  29. * Clean up all file locks that are expired for the DB file locking provider
  30. */
  31. class CleanupFileLocks extends TimedJob {
  32. /**
  33. * Default interval in minutes
  34. *
  35. * @var int $defaultIntervalMin
  36. **/
  37. protected $defaultIntervalMin = 5;
  38. /**
  39. * sets the correct interval for this timed job
  40. */
  41. public function __construct(ITimeFactory $time) {
  42. parent::__construct($time);
  43. $this->interval = $this->defaultIntervalMin * 60;
  44. }
  45. /**
  46. * Makes the background job do its work
  47. *
  48. * @param array $argument unused argument
  49. * @throws \Exception
  50. */
  51. public function run($argument) {
  52. $lockingProvider = \OC::$server->getLockingProvider();
  53. if ($lockingProvider instanceof DBLockingProvider) {
  54. $lockingProvider->cleanExpiredLocks();
  55. }
  56. }
  57. }