DropOldJobs.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Thomas Müller <thomas.mueller@tmit.eu>
  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 OC\Repair;
  25. use OCP\BackgroundJob\IJobList;
  26. use OCP\Migration\IOutput;
  27. use OCP\Migration\IRepairStep;
  28. class DropOldJobs implements IRepairStep {
  29. /** @var IJobList */
  30. protected $jobList;
  31. /**
  32. * @param IJobList $jobList
  33. */
  34. public function __construct(IJobList $jobList) {
  35. $this->jobList = $jobList;
  36. }
  37. /**
  38. * Returns the step's name
  39. *
  40. * @return string
  41. */
  42. public function getName() {
  43. return 'Drop old background jobs';
  44. }
  45. /**
  46. * Run repair step.
  47. * Must throw exception on error.
  48. *
  49. * @throws \Exception in case of failure
  50. */
  51. public function run(IOutput $output) {
  52. $oldJobs = $this->oldJobs();
  53. foreach($oldJobs as $job) {
  54. if($this->jobList->has($job['class'], $job['arguments'])) {
  55. $this->jobList->remove($job['class'], $job['arguments']);
  56. }
  57. }
  58. }
  59. /**
  60. * returns a list of old jobs as an associative array with keys 'class' and
  61. * 'arguments'.
  62. *
  63. * @return array
  64. */
  65. public function oldJobs() {
  66. return [
  67. ['class' => 'OC_Cache_FileGlobalGC', 'arguments' => null],
  68. ['class' => 'OC\Cache\FileGlobalGC', 'arguments' => null],
  69. ['class' => 'OCA\Files\BackgroundJob\DeleteOrphanedTagsJob', 'arguments' => null],
  70. ['class' => 'OCA\Files_sharing\Lib\DeleteOrphanedSharesJob', 'arguments' => null],
  71. ['class' => 'OCA\Files_sharing\ExpireSharesJob', 'arguments' => null],
  72. ['class' => 'OCA\user_ldap\lib\Jobs', 'arguments' => null],
  73. ['class' => '\OCA\User_LDAP\Jobs\CleanUp', 'arguments' => null],
  74. ];
  75. }
  76. }