BackgroundRepair.php 2.7 KB

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