Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Repair.php 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Georg Ehrke <georg@owncloud.com>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Lukas Reschke <lukas@statuscode.ch>
  9. * @author Morris Jobke <hey@morrisjobke.de>
  10. * @author Robin Appelman <robin@icewind.nl>
  11. * @author Roeland Jago Douma <roeland@famdouma.nl>
  12. * @author Thomas Müller <thomas.mueller@tmit.eu>
  13. * @author Vincent Petry <pvince81@owncloud.com>
  14. *
  15. * @license AGPL-3.0
  16. *
  17. * This code is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU Affero General Public License, version 3,
  19. * as published by the Free Software Foundation.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Affero General Public License, version 3,
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>
  28. *
  29. */
  30. namespace OC;
  31. use OC\Repair\AssetCache;
  32. use OC\Repair\AvatarPermissions;
  33. use OC\Repair\CleanTags;
  34. use OC\Repair\Collation;
  35. use OC\Repair\DropOldJobs;
  36. use OC\Repair\MoveUpdaterStepFile;
  37. use OC\Repair\NC11\CleanPreviews;
  38. use OC\Repair\NC11\FixMountStorages;
  39. use OC\Repair\NC11\MoveAvatars;
  40. use OC\Repair\OldGroupMembershipShares;
  41. use OC\Repair\RemoveGetETagEntries;
  42. use OC\Repair\RemoveOldShares;
  43. use OC\Repair\RemoveRootShares;
  44. use OC\Repair\SharePropagation;
  45. use OC\Repair\SqliteAutoincrement;
  46. use OC\Repair\DropOldTables;
  47. use OC\Repair\FillETags;
  48. use OC\Repair\InnoDB;
  49. use OC\Repair\RepairMimeTypes;
  50. use OC\Repair\SearchLuceneTables;
  51. use OC\Repair\UpdateOutdatedOcsIds;
  52. use OC\Repair\RepairInvalidShares;
  53. use OC\Repair\RepairUnmergedShares;
  54. use OCP\AppFramework\QueryException;
  55. use OCP\Migration\IOutput;
  56. use OCP\Migration\IRepairStep;
  57. use Symfony\Component\EventDispatcher\EventDispatcher;
  58. use Symfony\Component\EventDispatcher\GenericEvent;
  59. class Repair implements IOutput{
  60. /* @var IRepairStep[] */
  61. private $repairSteps;
  62. /** @var EventDispatcher */
  63. private $dispatcher;
  64. /** @var string */
  65. private $currentStep;
  66. /**
  67. * Creates a new repair step runner
  68. *
  69. * @param IRepairStep[] $repairSteps array of RepairStep instances
  70. * @param EventDispatcher $dispatcher
  71. */
  72. public function __construct($repairSteps = [], EventDispatcher $dispatcher = null) {
  73. $this->repairSteps = $repairSteps;
  74. $this->dispatcher = $dispatcher;
  75. }
  76. /**
  77. * Run a series of repair steps for common problems
  78. */
  79. public function run() {
  80. if (count($this->repairSteps) === 0) {
  81. $this->emit('\OC\Repair', 'info', array('No repair steps available'));
  82. return;
  83. }
  84. // run each repair step
  85. foreach ($this->repairSteps as $step) {
  86. $this->currentStep = $step->getName();
  87. $this->emit('\OC\Repair', 'step', [$this->currentStep]);
  88. $step->run($this);
  89. }
  90. }
  91. /**
  92. * Add repair step
  93. *
  94. * @param IRepairStep|string $repairStep repair step
  95. * @throws \Exception
  96. */
  97. public function addStep($repairStep) {
  98. if (is_string($repairStep)) {
  99. try {
  100. $s = \OC::$server->query($repairStep);
  101. } catch (QueryException $e) {
  102. if (class_exists($repairStep)) {
  103. $s = new $repairStep();
  104. } else {
  105. throw new \Exception("Repair step '$repairStep' is unknown");
  106. }
  107. }
  108. if ($s instanceof IRepairStep) {
  109. $this->repairSteps[] = $s;
  110. } else {
  111. throw new \Exception("Repair step '$repairStep' is not of type \\OCP\\Migration\\IRepairStep");
  112. }
  113. } else {
  114. $this->repairSteps[] = $repairStep;
  115. }
  116. }
  117. /**
  118. * Returns the default repair steps to be run on the
  119. * command line or after an upgrade.
  120. *
  121. * @return IRepairStep[]
  122. */
  123. public static function getRepairSteps() {
  124. return [
  125. new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->getDatabaseConnection(), false),
  126. new RepairMimeTypes(\OC::$server->getConfig()),
  127. new AssetCache(),
  128. new FillETags(\OC::$server->getDatabaseConnection()),
  129. new CleanTags(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager()),
  130. new DropOldTables(\OC::$server->getDatabaseConnection()),
  131. new DropOldJobs(\OC::$server->getJobList()),
  132. new RemoveGetETagEntries(\OC::$server->getDatabaseConnection()),
  133. new UpdateOutdatedOcsIds(\OC::$server->getConfig()),
  134. new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()),
  135. new SharePropagation(\OC::$server->getConfig()),
  136. new RemoveOldShares(\OC::$server->getDatabaseConnection()),
  137. new AvatarPermissions(\OC::$server->getDatabaseConnection()),
  138. new RemoveRootShares(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager(), \OC::$server->getLazyRootFolder()),
  139. new RepairUnmergedShares(
  140. \OC::$server->getConfig(),
  141. \OC::$server->getDatabaseConnection(),
  142. \OC::$server->getUserManager(),
  143. \OC::$server->getGroupManager()
  144. ),
  145. new MoveUpdaterStepFile(\OC::$server->getConfig()),
  146. new MoveAvatars(
  147. \OC::$server->getJobList(),
  148. \OC::$server->getConfig()
  149. ),
  150. new CleanPreviews(
  151. \OC::$server->getJobList(),
  152. \OC::$server->getUserManager(),
  153. \OC::$server->getConfig()
  154. ),
  155. new FixMountStorages(\OC::$server->getDatabaseConnection()),
  156. ];
  157. }
  158. /**
  159. * Returns expensive repair steps to be run on the
  160. * command line with a special option.
  161. *
  162. * @return IRepairStep[]
  163. */
  164. public static function getExpensiveRepairSteps() {
  165. return [
  166. new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager()),
  167. ];
  168. }
  169. /**
  170. * Returns the repair steps to be run before an
  171. * upgrade.
  172. *
  173. * @return IRepairStep[]
  174. */
  175. public static function getBeforeUpgradeRepairSteps() {
  176. $connection = \OC::$server->getDatabaseConnection();
  177. $steps = [
  178. new InnoDB(),
  179. new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), $connection, true),
  180. new SqliteAutoincrement($connection),
  181. new SearchLuceneTables(),
  182. ];
  183. //There is no need to delete all previews on every single update
  184. //only 7.0.0 through 7.0.2 generated broken previews
  185. $currentVersion = \OC::$server->getConfig()->getSystemValue('version');
  186. if (version_compare($currentVersion, '7.0.0.0', '>=') &&
  187. version_compare($currentVersion, '7.0.3.4', '<=')) {
  188. $steps[] = new \OC\Repair\Preview();
  189. }
  190. return $steps;
  191. }
  192. /**
  193. * @param string $scope
  194. * @param string $method
  195. * @param array $arguments
  196. */
  197. public function emit($scope, $method, array $arguments = []) {
  198. if (!is_null($this->dispatcher)) {
  199. $this->dispatcher->dispatch("$scope::$method",
  200. new GenericEvent("$scope::$method", $arguments));
  201. }
  202. }
  203. public function info($string) {
  204. // for now just emit as we did in the past
  205. $this->emit('\OC\Repair', 'info', array($string));
  206. }
  207. /**
  208. * @param string $message
  209. */
  210. public function warning($message) {
  211. // for now just emit as we did in the past
  212. $this->emit('\OC\Repair', 'warning', [$message]);
  213. }
  214. /**
  215. * @param int $max
  216. */
  217. public function startProgress($max = 0) {
  218. // for now just emit as we did in the past
  219. $this->emit('\OC\Repair', 'startProgress', [$max, $this->currentStep]);
  220. }
  221. /**
  222. * @param int $step
  223. * @param string $description
  224. */
  225. public function advance($step = 1, $description = '') {
  226. // for now just emit as we did in the past
  227. $this->emit('\OC\Repair', 'advance', [$step, $description]);
  228. }
  229. /**
  230. * @param int $max
  231. */
  232. public function finishProgress() {
  233. // for now just emit as we did in the past
  234. $this->emit('\OC\Repair', 'finishProgress', []);
  235. }
  236. }