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 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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\NeedsUpdateException;
  29. use OC\Repair;
  30. use OC_App;
  31. use OCP\AppFramework\Utility\ITimeFactory;
  32. use OCP\BackgroundJob\IJobList;
  33. use OCP\BackgroundJob\TimedJob;
  34. use OCP\EventDispatcher\IEventDispatcher;
  35. use Psr\Log\LoggerInterface;
  36. /**
  37. * Class BackgroundRepair
  38. *
  39. * @package OC\Migration
  40. */
  41. class BackgroundRepair extends TimedJob {
  42. public function __construct(
  43. private IEventDispatcher $dispatcher,
  44. ITimeFactory $time,
  45. private LoggerInterface $logger,
  46. private IJobList $jobList,
  47. ) {
  48. parent::__construct($time);
  49. $this->setInterval(15 * 60);
  50. }
  51. /**
  52. * @param array $argument
  53. * @throws \Exception
  54. * @throws \OC\NeedsUpdateException
  55. */
  56. protected function run($argument): void {
  57. if (!isset($argument['app']) || !isset($argument['step'])) {
  58. // remove the job - we can never execute it
  59. $this->jobList->remove($this, $this->argument);
  60. return;
  61. }
  62. $app = $argument['app'];
  63. try {
  64. $this->loadApp($app);
  65. } catch (NeedsUpdateException $ex) {
  66. // as long as the app is not yet done with it's offline migration
  67. // we better not start with the live migration
  68. return;
  69. }
  70. $step = $argument['step'];
  71. $repair = new Repair([], $this->dispatcher, \OC::$server->get(LoggerInterface::class));
  72. try {
  73. $repair->addStep($step);
  74. } catch (\Exception $ex) {
  75. $this->logger->error($ex->getMessage(), [
  76. 'app' => 'migration',
  77. 'exception' => $ex,
  78. ]);
  79. // remove the job - we can never execute it
  80. $this->jobList->remove($this, $this->argument);
  81. return;
  82. }
  83. // execute the repair step
  84. $repair->run();
  85. // remove the job once executed successfully
  86. $this->jobList->remove($this, $this->argument);
  87. }
  88. /**
  89. * @codeCoverageIgnore
  90. * @param $app
  91. * @throws NeedsUpdateException
  92. */
  93. protected function loadApp($app): void {
  94. OC_App::loadApp($app);
  95. }
  96. }