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.

107 lines
3.3 KiB

10 years ago
10 years ago
  1. <?php
  2. /**
  3. * @author Joas Schilling <nickvergessen@owncloud.com>
  4. * @author Morris Jobke <hey@morrisjobke.de>
  5. * @author Robin Appelman <icewind@owncloud.com>
  6. * @author Vincent Petry <pvince81@owncloud.com>
  7. *
  8. * @copyright Copyright (c) 2016, ownCloud, Inc.
  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\Core\Command\Maintenance;
  25. use Exception;
  26. use Symfony\Component\Console\Command\Command;
  27. use Symfony\Component\Console\Input\InputInterface;
  28. use Symfony\Component\Console\Input\InputOption;
  29. use Symfony\Component\Console\Output\OutputInterface;
  30. class Repair extends Command {
  31. /** @var \OC\Repair $repair */
  32. protected $repair;
  33. /** @var \OCP\IConfig */
  34. protected $config;
  35. /**
  36. * @param \OC\Repair $repair
  37. * @param \OCP\IConfig $config
  38. */
  39. public function __construct(\OC\Repair $repair, \OCP\IConfig $config) {
  40. $this->repair = $repair;
  41. $this->config = $config;
  42. parent::__construct();
  43. }
  44. protected function configure() {
  45. $this
  46. ->setName('maintenance:repair')
  47. ->setDescription('repair this installation')
  48. ->addOption(
  49. 'include-expensive',
  50. null,
  51. InputOption::VALUE_NONE,
  52. 'Use this option when you want to include resource and load expensive tasks');
  53. }
  54. protected function execute(InputInterface $input, OutputInterface $output) {
  55. $includeExpensive = $input->getOption('include-expensive');
  56. if ($includeExpensive) {
  57. foreach ($this->repair->getExpensiveRepairSteps() as $step) {
  58. $this->repair->addStep($step);
  59. }
  60. }
  61. $apps = \OC::$server->getAppManager()->getInstalledApps();
  62. foreach ($apps as $app) {
  63. if (!\OC_App::isEnabled($app)) {
  64. continue;
  65. }
  66. $info = \OC_App::getAppInfo($app);
  67. if (!is_array($info)) {
  68. continue;
  69. }
  70. $steps = $info['repair-steps']['post-migration'];
  71. foreach ($steps as $step) {
  72. try {
  73. $this->repair->addStep($step);
  74. } catch (Exception $ex) {
  75. $output->writeln("<error>Failed to load repair step for $app: {$ex->getMessage()}</error>");
  76. }
  77. }
  78. }
  79. $maintenanceMode = $this->config->getSystemValue('maintenance', false);
  80. $this->config->setSystemValue('maintenance', true);
  81. $this->repair->listen('\OC\Repair', 'step', function ($description) use ($output) {
  82. $output->writeln(' - ' . $description);
  83. });
  84. $this->repair->listen('\OC\Repair', 'info', function ($description) use ($output) {
  85. $output->writeln(' - ' . $description);
  86. });
  87. $this->repair->listen('\OC\Repair', 'warning', function ($description) use ($output) {
  88. $output->writeln(' - WARNING: ' . $description);
  89. });
  90. $this->repair->listen('\OC\Repair', 'error', function ($description) use ($output) {
  91. $output->writeln(' - ERROR: ' . $description);
  92. });
  93. $this->repair->run();
  94. $this->config->setSystemValue('maintenance', $maintenanceMode);
  95. }
  96. }