2013-11-26 13:12:48 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 15:07:57 +00:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2016-05-26 17:56:05 +00:00
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2015-03-26 10:44:34 +00:00
|
|
|
* @author Georg Ehrke <georg@owncloud.com>
|
2016-07-21 15:07:57 +00:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2016-05-26 17:56:05 +00:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2015-03-26 10:44:34 +00:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2016-07-21 16:13:36 +00:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2016-07-21 15:07:57 +00:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2015-03-26 10:44:34 +00:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
|
|
|
*
|
|
|
|
* @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 13:12:48 +00:00
|
|
|
*/
|
2015-02-26 10:37:37 +00:00
|
|
|
|
2013-11-26 13:12:48 +00:00
|
|
|
namespace OC;
|
|
|
|
|
2017-04-23 20:10:17 +00:00
|
|
|
use OC\App\AppStore\Bundles\BundleFetcher;
|
2015-01-14 10:57:26 +00:00
|
|
|
use OC\Repair\CleanTags;
|
2014-10-06 10:38:59 +00:00
|
|
|
use OC\Repair\Collation;
|
2016-09-23 11:38:37 +00:00
|
|
|
use OC\Repair\MoveUpdaterStepFile;
|
2016-11-16 10:40:52 +00:00
|
|
|
use OC\Repair\NC11\CleanPreviews;
|
2016-12-13 11:09:31 +00:00
|
|
|
use OC\Repair\NC11\FixMountStorages;
|
2016-09-12 07:53:31 +00:00
|
|
|
use OC\Repair\NC11\MoveAvatars;
|
2017-04-23 20:10:17 +00:00
|
|
|
use OC\Repair\NC12\InstallCoreBundle;
|
2016-09-12 16:15:22 +00:00
|
|
|
use OC\Repair\NC12\UpdateLanguageCodes;
|
2015-10-19 14:41:43 +00:00
|
|
|
use OC\Repair\OldGroupMembershipShares;
|
2017-05-11 12:04:53 +00:00
|
|
|
use OC\Repair\Owncloud\SaveAccountsTableData;
|
2016-06-13 11:14:38 +00:00
|
|
|
use OC\Repair\RemoveRootShares;
|
2017-06-21 21:50:20 +00:00
|
|
|
use OC\Repair\NC13\RepairInvalidPaths;
|
2015-03-25 17:31:49 +00:00
|
|
|
use OC\Repair\SqliteAutoincrement;
|
2014-10-06 10:38:59 +00:00
|
|
|
use OC\Repair\RepairMimeTypes;
|
2015-09-17 14:01:11 +00:00
|
|
|
use OC\Repair\RepairInvalidShares;
|
2016-05-03 13:16:39 +00:00
|
|
|
use OCP\AppFramework\QueryException;
|
2016-04-22 13:35:39 +00:00
|
|
|
use OCP\Migration\IOutput;
|
|
|
|
use OCP\Migration\IRepairStep;
|
2016-04-19 13:36:11 +00:00
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher;
|
|
|
|
use Symfony\Component\EventDispatcher\GenericEvent;
|
2013-11-26 13:12:48 +00:00
|
|
|
|
2016-04-27 08:51:02 +00:00
|
|
|
class Repair implements IOutput{
|
2016-04-22 13:35:39 +00:00
|
|
|
/* @var IRepairStep[] */
|
2014-06-10 09:47:27 +00:00
|
|
|
private $repairSteps;
|
2016-04-19 13:36:11 +00:00
|
|
|
/** @var EventDispatcher */
|
|
|
|
private $dispatcher;
|
2016-04-27 10:21:31 +00:00
|
|
|
/** @var string */
|
|
|
|
private $currentStep;
|
2014-03-25 11:51:16 +00:00
|
|
|
|
2013-11-26 13:12:48 +00:00
|
|
|
/**
|
2014-03-25 11:51:16 +00:00
|
|
|
* Creates a new repair step runner
|
|
|
|
*
|
2016-04-22 13:35:39 +00:00
|
|
|
* @param IRepairStep[] $repairSteps array of RepairStep instances
|
2016-04-19 13:36:11 +00:00
|
|
|
* @param EventDispatcher $dispatcher
|
2014-03-25 11:51:16 +00:00
|
|
|
*/
|
2016-04-19 13:36:11 +00:00
|
|
|
public function __construct($repairSteps = [], EventDispatcher $dispatcher = null) {
|
2014-06-10 09:47:27 +00:00
|
|
|
$this->repairSteps = $repairSteps;
|
2016-04-19 13:36:11 +00:00
|
|
|
$this->dispatcher = $dispatcher;
|
2014-03-25 11:51:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run a series of repair steps for common problems
|
2013-11-26 13:12:48 +00:00
|
|
|
*/
|
|
|
|
public function run() {
|
2014-06-10 09:47:27 +00:00
|
|
|
if (count($this->repairSteps) === 0) {
|
|
|
|
$this->emit('\OC\Repair', 'info', array('No repair steps available'));
|
|
|
|
return;
|
|
|
|
}
|
2014-03-25 11:51:16 +00:00
|
|
|
// run each repair step
|
2014-06-10 09:47:27 +00:00
|
|
|
foreach ($this->repairSteps as $step) {
|
2016-04-27 10:21:31 +00:00
|
|
|
$this->currentStep = $step->getName();
|
|
|
|
$this->emit('\OC\Repair', 'step', [$this->currentStep]);
|
2016-04-22 13:35:39 +00:00
|
|
|
$step->run($this);
|
2014-03-25 11:51:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-10 09:47:27 +00:00
|
|
|
* Add repair step
|
2014-03-25 11:51:16 +00:00
|
|
|
*
|
2016-04-22 13:35:39 +00:00
|
|
|
* @param IRepairStep|string $repairStep repair step
|
2016-04-19 13:36:11 +00:00
|
|
|
* @throws \Exception
|
2014-03-25 11:51:16 +00:00
|
|
|
*/
|
2014-06-10 09:47:27 +00:00
|
|
|
public function addStep($repairStep) {
|
2016-04-19 13:36:11 +00:00
|
|
|
if (is_string($repairStep)) {
|
2016-05-03 13:16:39 +00:00
|
|
|
try {
|
|
|
|
$s = \OC::$server->query($repairStep);
|
|
|
|
} catch (QueryException $e) {
|
|
|
|
if (class_exists($repairStep)) {
|
|
|
|
$s = new $repairStep();
|
2016-04-19 13:36:11 +00:00
|
|
|
} else {
|
2016-05-03 13:16:39 +00:00
|
|
|
throw new \Exception("Repair step '$repairStep' is unknown");
|
2016-04-19 13:36:11 +00:00
|
|
|
}
|
2016-05-03 13:16:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($s instanceof IRepairStep) {
|
|
|
|
$this->repairSteps[] = $s;
|
2016-04-19 13:36:11 +00:00
|
|
|
} else {
|
2016-05-03 13:16:39 +00:00
|
|
|
throw new \Exception("Repair step '$repairStep' is not of type \\OCP\\Migration\\IRepairStep");
|
2016-04-19 13:36:11 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$this->repairSteps[] = $repairStep;
|
|
|
|
}
|
2013-11-26 13:12:48 +00:00
|
|
|
}
|
2014-03-25 11:51:16 +00:00
|
|
|
|
2014-06-10 09:47:27 +00:00
|
|
|
/**
|
|
|
|
* Returns the default repair steps to be run on the
|
|
|
|
* command line or after an upgrade.
|
|
|
|
*
|
2016-04-22 13:35:39 +00:00
|
|
|
* @return IRepairStep[]
|
2014-06-10 09:47:27 +00:00
|
|
|
*/
|
|
|
|
public static function getRepairSteps() {
|
2015-07-16 16:41:08 +00:00
|
|
|
return [
|
2016-10-18 09:10:55 +00:00
|
|
|
new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->getDatabaseConnection(), false),
|
2015-08-25 12:09:38 +00:00
|
|
|
new RepairMimeTypes(\OC::$server->getConfig()),
|
2016-06-14 10:30:22 +00:00
|
|
|
new CleanTags(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager()),
|
2015-09-17 14:01:11 +00:00
|
|
|
new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()),
|
2016-06-17 08:53:55 +00:00
|
|
|
new RemoveRootShares(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager(), \OC::$server->getLazyRootFolder()),
|
2016-09-23 11:38:37 +00:00
|
|
|
new MoveUpdaterStepFile(\OC::$server->getConfig()),
|
2016-09-12 07:53:31 +00:00
|
|
|
new MoveAvatars(
|
2016-09-14 19:59:33 +00:00
|
|
|
\OC::$server->getJobList(),
|
2016-11-29 15:05:09 +00:00
|
|
|
\OC::$server->getConfig()
|
2016-09-12 07:53:31 +00:00
|
|
|
),
|
2016-11-16 10:40:52 +00:00
|
|
|
new CleanPreviews(
|
|
|
|
\OC::$server->getJobList(),
|
2016-11-19 19:26:53 +00:00
|
|
|
\OC::$server->getUserManager(),
|
|
|
|
\OC::$server->getConfig()
|
2016-11-16 10:40:52 +00:00
|
|
|
),
|
2016-12-13 11:09:31 +00:00
|
|
|
new FixMountStorages(\OC::$server->getDatabaseConnection()),
|
2017-03-03 11:20:02 +00:00
|
|
|
new UpdateLanguageCodes(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()),
|
2017-04-23 20:10:17 +00:00
|
|
|
new InstallCoreBundle(
|
|
|
|
\OC::$server->query(BundleFetcher::class),
|
|
|
|
\OC::$server->getConfig(),
|
|
|
|
\OC::$server->query(Installer::class)
|
2017-06-20 14:31:52 +00:00
|
|
|
),
|
2017-06-29 12:45:08 +00:00
|
|
|
new RepairInvalidPaths(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig())
|
2015-07-16 16:41:08 +00:00
|
|
|
];
|
2014-06-10 09:47:27 +00:00
|
|
|
}
|
|
|
|
|
2015-10-19 14:41:43 +00:00
|
|
|
/**
|
|
|
|
* Returns expensive repair steps to be run on the
|
|
|
|
* command line with a special option.
|
|
|
|
*
|
2016-04-22 13:35:39 +00:00
|
|
|
* @return IRepairStep[]
|
2015-10-19 14:41:43 +00:00
|
|
|
*/
|
|
|
|
public static function getExpensiveRepairSteps() {
|
|
|
|
return [
|
2017-06-20 14:31:52 +00:00
|
|
|
new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager())
|
2015-10-19 14:41:43 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2014-06-10 09:47:27 +00:00
|
|
|
/**
|
|
|
|
* Returns the repair steps to be run before an
|
|
|
|
* upgrade.
|
|
|
|
*
|
2016-04-22 13:35:39 +00:00
|
|
|
* @return IRepairStep[]
|
2014-06-10 09:47:27 +00:00
|
|
|
*/
|
|
|
|
public static function getBeforeUpgradeRepairSteps() {
|
2016-01-07 09:26:00 +00:00
|
|
|
$connection = \OC::$server->getDatabaseConnection();
|
2017-05-11 12:04:53 +00:00
|
|
|
$config = \OC::$server->getConfig();
|
2015-12-08 07:46:41 +00:00
|
|
|
$steps = [
|
2016-10-18 09:10:55 +00:00
|
|
|
new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), $connection, true),
|
2016-01-07 09:26:00 +00:00
|
|
|
new SqliteAutoincrement($connection),
|
2017-05-11 12:04:53 +00:00
|
|
|
new SaveAccountsTableData($connection, $config),
|
2015-12-08 07:46:41 +00:00
|
|
|
];
|
2014-09-21 15:16:21 +00:00
|
|
|
|
|
|
|
return $steps;
|
2014-06-10 09:47:27 +00:00
|
|
|
}
|
2014-06-26 12:27:41 +00:00
|
|
|
|
|
|
|
/**
|
2016-04-27 08:51:02 +00:00
|
|
|
* @param string $scope
|
|
|
|
* @param string $method
|
|
|
|
* @param array $arguments
|
2014-06-26 12:27:41 +00:00
|
|
|
*/
|
2016-04-19 13:36:11 +00: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 12:27:41 +00:00
|
|
|
}
|
2016-04-22 13:35:39 +00: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 10:21:31 +00:00
|
|
|
$this->emit('\OC\Repair', 'startProgress', [$max, $this->currentStep]);
|
2016-04-22 13:35:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $step
|
2016-04-27 10:21:31 +00:00
|
|
|
* @param string $description
|
2016-04-22 13:35:39 +00:00
|
|
|
*/
|
2016-04-27 10:21:31 +00:00
|
|
|
public function advance($step = 1, $description = '') {
|
2016-04-22 13:35:39 +00:00
|
|
|
// for now just emit as we did in the past
|
2016-04-27 10:21:31 +00:00
|
|
|
$this->emit('\OC\Repair', 'advance', [$step, $description]);
|
2016-04-22 13:35:39 +00: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 13:12:48 +00:00
|
|
|
}
|