dropoldjobs.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * @author Arthur Schiwon <blizzz@owncloud.com>
  4. *
  5. * @copyright Copyright (c) 2015, 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 OC\Repair;
  22. use OC\Hooks\BasicEmitter;
  23. use OC\RepairStep;
  24. use OCP\BackgroundJob\IJobList;
  25. class DropOldJobs extends BasicEmitter implements RepairStep {
  26. /** @var IJobList */
  27. protected $jobList;
  28. /**
  29. * @param IJobList $jobList
  30. */
  31. public function __construct(IJobList $jobList) {
  32. $this->jobList = $jobList;
  33. }
  34. /**
  35. * Returns the step's name
  36. *
  37. * @return string
  38. */
  39. public function getName() {
  40. return 'Drop old background jobs';
  41. }
  42. /**
  43. * Run repair step.
  44. * Must throw exception on error.
  45. *
  46. * @throws \Exception in case of failure
  47. */
  48. public function run() {
  49. $oldJobs = $this->oldJobs();
  50. foreach($oldJobs as $job) {
  51. if($this->jobList->has($job['class'], $job['arguments'])) {
  52. $this->jobList->remove($job['class'], $job['arguments']);
  53. }
  54. }
  55. }
  56. /**
  57. * returns a list of old jobs as an associative array with keys 'class' and
  58. * 'arguments'.
  59. *
  60. * @return array
  61. */
  62. public function oldJobs() {
  63. return [
  64. ['class' => 'OC_Cache_FileGlobalGC', 'arguments' => null],
  65. ['class' => 'OC\Cache\FileGlobalGC', 'arguments' => null],
  66. ];
  67. }
  68. }