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.

BackgroundRepair.php 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Daniel Kesselberg <mail@danielkesselberg.de>
  7. * @author Lukas Reschke <lukas@statuscode.ch>
  8. * @author Robin Appelman <robin@icewind.nl>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. * @author Thomas Müller <thomas.mueller@tmit.eu>
  11. *
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. namespace OC\Migration;
  28. use OC\BackgroundJob\JobList;
  29. use OC\BackgroundJob\TimedJob;
  30. use OC\NeedsUpdateException;
  31. use OC\Repair;
  32. use OC_App;
  33. use OCP\BackgroundJob\IJobList;
  34. use OCP\ILogger;
  35. use Psr\Log\LoggerInterface;
  36. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  37. /**
  38. * Class BackgroundRepair
  39. *
  40. * @package OC\Migration
  41. */
  42. class BackgroundRepair extends TimedJob {
  43. /** @var IJobList */
  44. private $jobList;
  45. /** @var ILogger */
  46. private $logger;
  47. /** @var EventDispatcherInterface */
  48. private $dispatcher;
  49. public function __construct(EventDispatcherInterface $dispatcher) {
  50. $this->dispatcher = $dispatcher;
  51. }
  52. /**
  53. * run the job, then remove it from the job list
  54. *
  55. * @param JobList $jobList
  56. * @param ILogger|null $logger
  57. */
  58. public function execute($jobList, ILogger $logger = null) {
  59. // add an interval of 15 mins
  60. $this->setInterval(15 * 60);
  61. $this->jobList = $jobList;
  62. $this->logger = $logger;
  63. parent::execute($jobList, $logger);
  64. }
  65. /**
  66. * @param array $argument
  67. * @throws \Exception
  68. * @throws \OC\NeedsUpdateException
  69. */
  70. protected function run($argument) {
  71. if (!isset($argument['app']) || !isset($argument['step'])) {
  72. // remove the job - we can never execute it
  73. $this->jobList->remove($this, $this->argument);
  74. return;
  75. }
  76. $app = $argument['app'];
  77. try {
  78. $this->loadApp($app);
  79. } catch (NeedsUpdateException $ex) {
  80. // as long as the app is not yet done with it's offline migration
  81. // we better not start with the live migration
  82. return;
  83. }
  84. $step = $argument['step'];
  85. $repair = new Repair([], $this->dispatcher, \OC::$server->get(LoggerInterface::class));
  86. try {
  87. $repair->addStep($step);
  88. } catch (\Exception $ex) {
  89. $this->logger->logException($ex, [
  90. 'app' => 'migration'
  91. ]);
  92. // remove the job - we can never execute it
  93. $this->jobList->remove($this, $this->argument);
  94. return;
  95. }
  96. // execute the repair step
  97. $repair->run();
  98. // remove the job once executed successfully
  99. $this->jobList->remove($this, $this->argument);
  100. }
  101. /**
  102. * @codeCoverageIgnore
  103. * @param $app
  104. * @throws NeedsUpdateException
  105. */
  106. protected function loadApp($app) {
  107. OC_App::loadApp($app);
  108. }
  109. }