repair.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. /**
  3. * @author Arthur Schiwon <blizzz@owncloud.com>
  4. * @author Georg Ehrke <georg@owncloud.com>
  5. * @author Joas Schilling <nickvergessen@owncloud.com>
  6. * @author Lukas Reschke <lukas@owncloud.com>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Robin Appelman <icewind@owncloud.com>
  9. * @author Thomas Müller <thomas.mueller@tmit.eu>
  10. * @author Vincent Petry <pvince81@owncloud.com>
  11. *
  12. * @copyright Copyright (c) 2015, ownCloud, Inc.
  13. * @license AGPL-3.0
  14. *
  15. * This code is free software: you can redistribute it and/or modify
  16. * it under the terms of the GNU Affero General Public License, version 3,
  17. * as published by the Free Software Foundation.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU Affero General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU Affero General Public License, version 3,
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>
  26. *
  27. */
  28. namespace OC;
  29. use OC\Hooks\BasicEmitter;
  30. use OC\Hooks\Emitter;
  31. use OC\Repair\AssetCache;
  32. use OC\Repair\CleanTags;
  33. use OC\Repair\Collation;
  34. use OC\Repair\DropOldJobs;
  35. use OC\Repair\RemoveGetETagEntries;
  36. use OC\Repair\SqliteAutoincrement;
  37. use OC\Repair\DropOldTables;
  38. use OC\Repair\FillETags;
  39. use OC\Repair\InnoDB;
  40. use OC\Repair\RepairConfig;
  41. use OC\Repair\RepairLegacyStorages;
  42. use OC\Repair\RepairMimeTypes;
  43. use OC\Repair\SearchLuceneTables;
  44. class Repair extends BasicEmitter {
  45. /**
  46. * @var RepairStep[]
  47. **/
  48. private $repairSteps;
  49. /**
  50. * Creates a new repair step runner
  51. *
  52. * @param array $repairSteps array of RepairStep instances
  53. */
  54. public function __construct($repairSteps = array()) {
  55. $this->repairSteps = $repairSteps;
  56. }
  57. /**
  58. * Run a series of repair steps for common problems
  59. */
  60. public function run() {
  61. $self = $this;
  62. if (count($this->repairSteps) === 0) {
  63. $this->emit('\OC\Repair', 'info', array('No repair steps available'));
  64. return;
  65. }
  66. // run each repair step
  67. foreach ($this->repairSteps as $step) {
  68. $this->emit('\OC\Repair', 'step', array($step->getName()));
  69. if ($step instanceof Emitter) {
  70. $step->listen('\OC\Repair', 'warning', function ($description) use ($self) {
  71. $self->emit('\OC\Repair', 'warning', array($description));
  72. });
  73. $step->listen('\OC\Repair', 'info', function ($description) use ($self) {
  74. $self->emit('\OC\Repair', 'info', array($description));
  75. });
  76. }
  77. $step->run();
  78. }
  79. }
  80. /**
  81. * Add repair step
  82. *
  83. * @param RepairStep $repairStep repair step
  84. */
  85. public function addStep($repairStep) {
  86. $this->repairSteps[] = $repairStep;
  87. }
  88. /**
  89. * Returns the default repair steps to be run on the
  90. * command line or after an upgrade.
  91. *
  92. * @return array of RepairStep instances
  93. */
  94. public static function getRepairSteps() {
  95. return array(
  96. new RepairMimeTypes(),
  97. new RepairLegacyStorages(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()),
  98. new RepairConfig(),
  99. new AssetCache(),
  100. new FillETags(\OC::$server->getDatabaseConnection()),
  101. new CleanTags(\OC::$server->getDatabaseConnection()),
  102. new DropOldTables(\OC::$server->getDatabaseConnection()),
  103. new DropOldJobs(\OC::$server->getJobList()),
  104. new RemoveGetETagEntries(\OC::$server->getDatabaseConnection()),
  105. );
  106. }
  107. /**
  108. * Returns the repair steps to be run before an
  109. * upgrade.
  110. *
  111. * @return array of RepairStep instances
  112. */
  113. public static function getBeforeUpgradeRepairSteps() {
  114. $steps = array(
  115. new InnoDB(),
  116. new Collation(\OC::$server->getConfig(), \OC_DB::getConnection()),
  117. new SqliteAutoincrement(\OC_DB::getConnection()),
  118. new SearchLuceneTables(),
  119. new RepairConfig()
  120. );
  121. //There is no need to delete all previews on every single update
  122. //only 7.0.0 through 7.0.2 generated broken previews
  123. $currentVersion = \OC::$server->getConfig()->getSystemValue('version');
  124. if (version_compare($currentVersion, '7.0.0.0', '>=') &&
  125. version_compare($currentVersion, '7.0.3.4', '<=')) {
  126. $steps[] = new \OC\Repair\Preview();
  127. }
  128. return $steps;
  129. }
  130. /**
  131. * {@inheritDoc}
  132. *
  133. * Re-declared as public to allow invocation from within the closure above in php 5.3
  134. */
  135. public function emit($scope, $method, array $arguments = array()) {
  136. parent::emit($scope, $method, $arguments);
  137. }
  138. }