repair.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * @author Morris Jobke <hey@morrisjobke.de>
  4. * @author Robin Appelman <icewind@owncloud.com>
  5. * @author Thomas Müller <thomas.mueller@tmit.eu>
  6. * @author Vincent Petry <pvince81@owncloud.com>
  7. *
  8. * @copyright Copyright (c) 2015, 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 Symfony\Component\Console\Command\Command;
  26. use Symfony\Component\Console\Input\InputInterface;
  27. use Symfony\Component\Console\Input\InputOption;
  28. use Symfony\Component\Console\Output\OutputInterface;
  29. class Repair extends Command {
  30. /**
  31. * @var \OC\Repair $repair
  32. */
  33. protected $repair;
  34. /** @var \OCP\IConfig */
  35. protected $config;
  36. /**
  37. * @param \OC\Repair $repair
  38. * @param \OCP\IConfig $config
  39. */
  40. public function __construct(\OC\Repair $repair, \OCP\IConfig $config) {
  41. $this->repair = $repair;
  42. $this->config = $config;
  43. parent::__construct();
  44. }
  45. protected function configure() {
  46. $this
  47. ->setName('maintenance:repair')
  48. ->setDescription('repair this installation')
  49. ->addOption(
  50. 'include-expensive',
  51. null,
  52. InputOption::VALUE_NONE,
  53. 'Use this option when you want to include resource and load expensive tasks'
  54. )
  55. ;
  56. }
  57. protected function execute(InputInterface $input, OutputInterface $output) {
  58. $includeExpensive = $input->getOption('include-expensive');
  59. if ($includeExpensive) {
  60. foreach ($this->repair->getExpensiveRepairSteps() as $step) {
  61. $this->repair->addStep($step);
  62. }
  63. }
  64. $maintenanceMode = $this->config->getSystemValue('maintenance', false);
  65. $this->config->setSystemValue('maintenance', true);
  66. $this->repair->listen('\OC\Repair', 'step', function ($description) use ($output) {
  67. $output->writeln(' - ' . $description);
  68. });
  69. $this->repair->listen('\OC\Repair', 'info', function ($description) use ($output) {
  70. $output->writeln(' - ' . $description);
  71. });
  72. $this->repair->listen('\OC\Repair', 'warning', function ($description) use ($output) {
  73. $output->writeln(' - WARNING: ' . $description);
  74. });
  75. $this->repair->listen('\OC\Repair', 'error', function ($description) use ($output) {
  76. $output->writeln(' - ERROR: ' . $description);
  77. });
  78. $this->repair->run();
  79. $this->config->setSystemValue('maintenance', $maintenanceMode);
  80. }
  81. }