RemoveOrphaned.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. namespace OC\Settings;
  24. use OC\BackgroundJob\JobList;
  25. use OC\BackgroundJob\TimedJob;
  26. use OC\NeedsUpdateException;
  27. use OCP\BackgroundJob\IJobList;
  28. use OCP\ILogger;
  29. /**
  30. * Class RemoveOrphaned
  31. *
  32. * @package OC\Settings
  33. */
  34. class RemoveOrphaned extends TimedJob {
  35. /** @var IJobList */
  36. private $jobList;
  37. /** @var ILogger */
  38. private $logger;
  39. /** @var Manager */
  40. private $manager;
  41. public function __construct(Manager $manager = null) {
  42. if($manager !== null) {
  43. $this->manager = $manager;
  44. } else {
  45. // fix DI for Jobs
  46. $this->manager = \OC::$server->getSettingsManager();
  47. }
  48. }
  49. /**
  50. * run the job, then remove it from the job list
  51. *
  52. * @param JobList $jobList
  53. * @param ILogger $logger
  54. */
  55. public function execute($jobList, ILogger $logger = null) {
  56. // add an interval of 15 mins
  57. $this->setInterval(15*60);
  58. $this->jobList = $jobList;
  59. $this->logger = $logger;
  60. parent::execute($jobList, $logger);
  61. }
  62. /**
  63. * @param array $argument
  64. * @throws \Exception
  65. * @throws \OC\NeedsUpdateException
  66. */
  67. protected function run($argument) {
  68. try {
  69. \OC_App::loadApps();
  70. } catch (NeedsUpdateException $ex) {
  71. // only run when apps are up to date
  72. return;
  73. }
  74. $this->manager->checkForOrphanedClassNames();
  75. // remove the job once executed successfully
  76. $this->jobList->remove($this);
  77. }
  78. }