2013-11-26 17:12:48 +04:00
|
|
|
<?php
|
|
|
|
/**
|
2015-06-25 12:43:55 +03:00
|
|
|
* @author Arthur Schiwon <blizzz@owncloud.com>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Georg Ehrke <georg@owncloud.com>
|
|
|
|
* @author Joas Schilling <nickvergessen@owncloud.com>
|
|
|
|
* @author Lukas Reschke <lukas@owncloud.com>
|
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
* @author Robin Appelman <icewind@owncloud.com>
|
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
|
|
|
*
|
2016-01-12 17:02:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
2015-03-26 13:44:34 +03:00
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
2013-11-26 17:12:48 +04:00
|
|
|
*/
|
2015-02-26 13:37:37 +03:00
|
|
|
|
2013-11-26 17:12:48 +04:00
|
|
|
namespace OC;
|
|
|
|
|
2014-06-12 16:40:43 +04:00
|
|
|
use OC\Hooks\Emitter;
|
2014-10-06 14:38:59 +04:00
|
|
|
use OC\Repair\AssetCache;
|
2015-01-14 13:57:26 +03:00
|
|
|
use OC\Repair\CleanTags;
|
2014-10-06 14:38:59 +04:00
|
|
|
use OC\Repair\Collation;
|
2015-05-12 19:19:44 +03:00
|
|
|
use OC\Repair\DropOldJobs;
|
2015-10-19 17:41:43 +03:00
|
|
|
use OC\Repair\OldGroupMembershipShares;
|
2015-04-13 13:32:04 +03:00
|
|
|
use OC\Repair\RemoveGetETagEntries;
|
2016-03-11 17:26:52 +03:00
|
|
|
use OC\Repair\SharePropagation;
|
2015-03-25 20:31:49 +03:00
|
|
|
use OC\Repair\SqliteAutoincrement;
|
2015-03-02 14:02:14 +03:00
|
|
|
use OC\Repair\DropOldTables;
|
2015-01-12 17:22:02 +03:00
|
|
|
use OC\Repair\FillETags;
|
2014-10-06 14:38:59 +04:00
|
|
|
use OC\Repair\InnoDB;
|
|
|
|
use OC\Repair\RepairLegacyStorages;
|
|
|
|
use OC\Repair\RepairMimeTypes;
|
|
|
|
use OC\Repair\SearchLuceneTables;
|
2015-07-16 19:41:08 +03:00
|
|
|
use OC\Repair\UpdateOutdatedOcsIds;
|
2015-09-17 17:01:11 +03:00
|
|
|
use OC\Repair\RepairInvalidShares;
|
2016-04-22 16:35:39 +03:00
|
|
|
use OCP\Migration\IOutput;
|
|
|
|
use OCP\Migration\IRepairStep;
|
2016-04-19 16:36:11 +03:00
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher;
|
|
|
|
use Symfony\Component\EventDispatcher\GenericEvent;
|
2013-11-26 17:12:48 +04:00
|
|
|
|
2016-04-27 11:51:02 +03:00
|
|
|
class Repair implements IOutput{
|
2016-04-22 16:35:39 +03:00
|
|
|
/* @var IRepairStep[] */
|
2014-06-10 13:47:27 +04:00
|
|
|
private $repairSteps;
|
2016-04-19 16:36:11 +03:00
|
|
|
/** @var EventDispatcher */
|
|
|
|
private $dispatcher;
|
2016-04-27 13:21:31 +03:00
|
|
|
/** @var string */
|
|
|
|
private $currentStep;
|
2014-03-25 15:51:16 +04:00
|
|
|
|
2013-11-26 17:12:48 +04:00
|
|
|
/**
|
2014-03-25 15:51:16 +04:00
|
|
|
* Creates a new repair step runner
|
|
|
|
*
|
2016-04-22 16:35:39 +03:00
|
|
|
* @param IRepairStep[] $repairSteps array of RepairStep instances
|
2016-04-19 16:36:11 +03:00
|
|
|
* @param EventDispatcher $dispatcher
|
2014-03-25 15:51:16 +04:00
|
|
|
*/
|
2016-04-19 16:36:11 +03:00
|
|
|
public function __construct($repairSteps = [], EventDispatcher $dispatcher = null) {
|
2014-06-10 13:47:27 +04:00
|
|
|
$this->repairSteps = $repairSteps;
|
2016-04-19 16:36:11 +03:00
|
|
|
$this->dispatcher = $dispatcher;
|
2014-03-25 15:51:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run a series of repair steps for common problems
|
2013-11-26 17:12:48 +04:00
|
|
|
*/
|
|
|
|
public function run() {
|
2014-03-25 15:51:16 +04:00
|
|
|
$self = $this;
|
2014-06-10 13:47:27 +04:00
|
|
|
if (count($this->repairSteps) === 0) {
|
|
|
|
$this->emit('\OC\Repair', 'info', array('No repair steps available'));
|
|
|
|
return;
|
|
|
|
}
|
2014-03-25 15:51:16 +04:00
|
|
|
// run each repair step
|
2014-06-10 13:47:27 +04:00
|
|
|
foreach ($this->repairSteps as $step) {
|
2016-04-27 13:21:31 +03:00
|
|
|
$this->currentStep = $step->getName();
|
|
|
|
$this->emit('\OC\Repair', 'step', [$this->currentStep]);
|
2014-03-25 15:51:16 +04:00
|
|
|
|
2014-06-12 16:40:43 +04:00
|
|
|
if ($step instanceof Emitter) {
|
2014-06-10 13:47:27 +04:00
|
|
|
$step->listen('\OC\Repair', 'warning', function ($description) use ($self) {
|
|
|
|
$self->emit('\OC\Repair', 'warning', array($description));
|
|
|
|
});
|
|
|
|
$step->listen('\OC\Repair', 'info', function ($description) use ($self) {
|
|
|
|
$self->emit('\OC\Repair', 'info', array($description));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-04-22 16:35:39 +03:00
|
|
|
$step->run($this);
|
2014-03-25 15:51:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-10 13:47:27 +04:00
|
|
|
* Add repair step
|
2014-03-25 15:51:16 +04:00
|
|
|
*
|
2016-04-22 16:35:39 +03:00
|
|
|
* @param IRepairStep|string $repairStep repair step
|
2016-04-19 16:36:11 +03:00
|
|
|
* @throws \Exception
|
2014-03-25 15:51:16 +04:00
|
|
|
*/
|
2014-06-10 13:47:27 +04:00
|
|
|
public function addStep($repairStep) {
|
2016-04-19 16:36:11 +03:00
|
|
|
if (is_string($repairStep)) {
|
|
|
|
if (class_exists($repairStep)) {
|
|
|
|
$s = new $repairStep();
|
2016-04-22 16:35:39 +03:00
|
|
|
if ($s instanceof IRepairStep) {
|
2016-04-19 16:36:11 +03:00
|
|
|
$this->repairSteps[] = $s;
|
|
|
|
} else {
|
2016-04-22 16:35:39 +03:00
|
|
|
throw new \Exception("Repair step '$repairStep' is not of type \\OCP\\Migration\\IRepairStep");
|
2016-04-19 16:36:11 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
throw new \Exception("Repair step '$repairStep' is unknown");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$this->repairSteps[] = $repairStep;
|
|
|
|
}
|
2013-11-26 17:12:48 +04:00
|
|
|
}
|
2014-03-25 15:51:16 +04:00
|
|
|
|
2014-06-10 13:47:27 +04:00
|
|
|
/**
|
|
|
|
* Returns the default repair steps to be run on the
|
|
|
|
* command line or after an upgrade.
|
|
|
|
*
|
2016-04-22 16:35:39 +03:00
|
|
|
* @return IRepairStep[]
|
2014-06-10 13:47:27 +04:00
|
|
|
*/
|
|
|
|
public static function getRepairSteps() {
|
2015-07-16 19:41:08 +03:00
|
|
|
return [
|
2015-08-25 15:09:38 +03:00
|
|
|
new RepairMimeTypes(\OC::$server->getConfig()),
|
2015-07-06 13:34:19 +03:00
|
|
|
new RepairLegacyStorages(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()),
|
2015-01-12 17:22:02 +03:00
|
|
|
new AssetCache(),
|
2015-07-06 13:34:19 +03:00
|
|
|
new FillETags(\OC::$server->getDatabaseConnection()),
|
|
|
|
new CleanTags(\OC::$server->getDatabaseConnection()),
|
|
|
|
new DropOldTables(\OC::$server->getDatabaseConnection()),
|
2015-05-12 19:19:44 +03:00
|
|
|
new DropOldJobs(\OC::$server->getJobList()),
|
2015-07-06 13:34:19 +03:00
|
|
|
new RemoveGetETagEntries(\OC::$server->getDatabaseConnection()),
|
2015-07-16 19:41:08 +03:00
|
|
|
new UpdateOutdatedOcsIds(\OC::$server->getConfig()),
|
2015-09-17 17:01:11 +03:00
|
|
|
new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()),
|
2016-03-11 17:26:52 +03:00
|
|
|
new SharePropagation(\OC::$server->getConfig()),
|
2015-07-16 19:41:08 +03:00
|
|
|
];
|
2014-06-10 13:47:27 +04:00
|
|
|
}
|
|
|
|
|
2015-10-19 17:41:43 +03:00
|
|
|
/**
|
|
|
|
* Returns expensive repair steps to be run on the
|
|
|
|
* command line with a special option.
|
|
|
|
*
|
2016-04-22 16:35:39 +03:00
|
|
|
* @return IRepairStep[]
|
2015-10-19 17:41:43 +03:00
|
|
|
*/
|
|
|
|
public static function getExpensiveRepairSteps() {
|
|
|
|
return [
|
|
|
|
new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager()),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2014-06-10 13:47:27 +04:00
|
|
|
/**
|
|
|
|
* Returns the repair steps to be run before an
|
|
|
|
* upgrade.
|
|
|
|
*
|
2016-04-22 16:35:39 +03:00
|
|
|
* @return IRepairStep[]
|
2014-06-10 13:47:27 +04:00
|
|
|
*/
|
|
|
|
public static function getBeforeUpgradeRepairSteps() {
|
2016-01-07 12:26:00 +03:00
|
|
|
$connection = \OC::$server->getDatabaseConnection();
|
2015-12-08 10:46:41 +03:00
|
|
|
$steps = [
|
2014-10-06 14:38:59 +04:00
|
|
|
new InnoDB(),
|
2016-01-07 12:26:00 +03:00
|
|
|
new Collation(\OC::$server->getConfig(), $connection),
|
|
|
|
new SqliteAutoincrement($connection),
|
2014-11-13 15:34:11 +03:00
|
|
|
new SearchLuceneTables(),
|
2015-12-08 10:46:41 +03:00
|
|
|
];
|
2014-09-21 19:16:21 +04:00
|
|
|
|
|
|
|
//There is no need to delete all previews on every single update
|
2014-10-06 14:38:59 +04:00
|
|
|
//only 7.0.0 through 7.0.2 generated broken previews
|
|
|
|
$currentVersion = \OC::$server->getConfig()->getSystemValue('version');
|
2014-09-21 19:16:21 +04:00
|
|
|
if (version_compare($currentVersion, '7.0.0.0', '>=') &&
|
2014-11-25 17:42:02 +03:00
|
|
|
version_compare($currentVersion, '7.0.3.4', '<=')) {
|
2014-09-21 19:16:21 +04:00
|
|
|
$steps[] = new \OC\Repair\Preview();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $steps;
|
2014-06-10 13:47:27 +04:00
|
|
|
}
|
2014-06-26 16:27:41 +04:00
|
|
|
|
|
|
|
/**
|
2016-04-27 11:51:02 +03:00
|
|
|
* @param string $scope
|
|
|
|
* @param string $method
|
|
|
|
* @param array $arguments
|
2014-06-26 16:27:41 +04:00
|
|
|
*/
|
2016-04-19 16:36:11 +03:00
|
|
|
public function emit($scope, $method, array $arguments = []) {
|
|
|
|
if (!is_null($this->dispatcher)) {
|
|
|
|
$this->dispatcher->dispatch("$scope::$method",
|
|
|
|
new GenericEvent("$scope::$method", $arguments));
|
|
|
|
}
|
2014-06-26 16:27:41 +04:00
|
|
|
}
|
2016-04-22 16:35:39 +03:00
|
|
|
|
|
|
|
public function info($string) {
|
|
|
|
// for now just emit as we did in the past
|
|
|
|
$this->emit('\OC\Repair', 'info', array($string));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $message
|
|
|
|
*/
|
|
|
|
public function warning($message) {
|
|
|
|
// for now just emit as we did in the past
|
|
|
|
$this->emit('\OC\Repair', 'warning', [$message]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $max
|
|
|
|
*/
|
|
|
|
public function startProgress($max = 0) {
|
|
|
|
// for now just emit as we did in the past
|
2016-04-27 13:21:31 +03:00
|
|
|
$this->emit('\OC\Repair', 'startProgress', [$max, $this->currentStep]);
|
2016-04-22 16:35:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $step
|
2016-04-27 13:21:31 +03:00
|
|
|
* @param string $description
|
2016-04-22 16:35:39 +03:00
|
|
|
*/
|
2016-04-27 13:21:31 +03:00
|
|
|
public function advance($step = 1, $description = '') {
|
2016-04-22 16:35:39 +03:00
|
|
|
// for now just emit as we did in the past
|
2016-04-27 13:21:31 +03:00
|
|
|
$this->emit('\OC\Repair', 'advance', [$step, $description]);
|
2016-04-22 16:35:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $max
|
|
|
|
*/
|
|
|
|
public function finishProgress() {
|
|
|
|
// for now just emit as we did in the past
|
|
|
|
$this->emit('\OC\Repair', 'finishProgress', []);
|
|
|
|
}
|
2013-11-26 17:12:48 +04:00
|
|
|
}
|