repair.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. /**
  3. * @author Georg Ehrke <georg@owncloud.com>
  4. * @author Joas Schilling <nickvergessen@owncloud.com>
  5. * @author Lukas Reschke <lukas@owncloud.com>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Robin Appelman <icewind@owncloud.com>
  8. * @author Thomas Müller <thomas.mueller@tmit.eu>
  9. * @author Vincent Petry <pvince81@owncloud.com>
  10. *
  11. * @copyright Copyright (c) 2015, ownCloud, Inc.
  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;
  28. use OC\Hooks\BasicEmitter;
  29. use OC\Hooks\Emitter;
  30. use OC\Repair\AssetCache;
  31. use OC\Repair\CleanTags;
  32. use OC\Repair\Collation;
  33. use OC\Repair\SqliteAutoincrement;
  34. use OC\Repair\DropOldTables;
  35. use OC\Repair\FillETags;
  36. use OC\Repair\InnoDB;
  37. use OC\Repair\RepairConfig;
  38. use OC\Repair\RepairLegacyStorages;
  39. use OC\Repair\RepairMimeTypes;
  40. use OC\Repair\SearchLuceneTables;
  41. class Repair extends BasicEmitter {
  42. /**
  43. * @var RepairStep[]
  44. **/
  45. private $repairSteps;
  46. /**
  47. * Creates a new repair step runner
  48. *
  49. * @param array $repairSteps array of RepairStep instances
  50. */
  51. public function __construct($repairSteps = array()) {
  52. $this->repairSteps = $repairSteps;
  53. }
  54. /**
  55. * Run a series of repair steps for common problems
  56. */
  57. public function run() {
  58. $self = $this;
  59. if (count($this->repairSteps) === 0) {
  60. $this->emit('\OC\Repair', 'info', array('No repair steps available'));
  61. return;
  62. }
  63. // run each repair step
  64. foreach ($this->repairSteps as $step) {
  65. $this->emit('\OC\Repair', 'step', array($step->getName()));
  66. if ($step instanceof Emitter) {
  67. $step->listen('\OC\Repair', 'warning', function ($description) use ($self) {
  68. $self->emit('\OC\Repair', 'warning', array($description));
  69. });
  70. $step->listen('\OC\Repair', 'info', function ($description) use ($self) {
  71. $self->emit('\OC\Repair', 'info', array($description));
  72. });
  73. }
  74. $step->run();
  75. }
  76. }
  77. /**
  78. * Add repair step
  79. *
  80. * @param RepairStep $repairStep repair step
  81. */
  82. public function addStep($repairStep) {
  83. $this->repairSteps[] = $repairStep;
  84. }
  85. /**
  86. * Returns the default repair steps to be run on the
  87. * command line or after an upgrade.
  88. *
  89. * @return array of RepairStep instances
  90. */
  91. public static function getRepairSteps() {
  92. return array(
  93. new RepairMimeTypes(),
  94. new RepairLegacyStorages(\OC::$server->getConfig(), \OC_DB::getConnection()),
  95. new RepairConfig(),
  96. new AssetCache(),
  97. new FillETags(\OC_DB::getConnection()),
  98. new CleanTags(\OC_DB::getConnection()),
  99. new DropOldTables(\OC_DB::getConnection()),
  100. );
  101. }
  102. /**
  103. * Returns the repair steps to be run before an
  104. * upgrade.
  105. *
  106. * @return array of RepairStep instances
  107. */
  108. public static function getBeforeUpgradeRepairSteps() {
  109. $steps = array(
  110. new InnoDB(),
  111. new Collation(\OC::$server->getConfig(), \OC_DB::getConnection()),
  112. new SqliteAutoincrement(\OC_DB::getConnection()),
  113. new SearchLuceneTables(),
  114. new RepairConfig()
  115. );
  116. //There is no need to delete all previews on every single update
  117. //only 7.0.0 through 7.0.2 generated broken previews
  118. $currentVersion = \OC::$server->getConfig()->getSystemValue('version');
  119. if (version_compare($currentVersion, '7.0.0.0', '>=') &&
  120. version_compare($currentVersion, '7.0.3.4', '<=')) {
  121. $steps[] = new \OC\Repair\Preview();
  122. }
  123. return $steps;
  124. }
  125. /**
  126. * {@inheritDoc}
  127. *
  128. * Re-declared as public to allow invocation from within the closure above in php 5.3
  129. */
  130. public function emit($scope, $method, $arguments = array()) {
  131. parent::emit($scope, $method, $arguments);
  132. }
  133. }