2013-11-26 17:12:48 +04:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 18:07:57 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Georg Ehrke <georg@owncloud.com>
|
2016-07-21 18:07:57 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2016-07-21 19:13:36 +03:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2016-07-21 18:07:57 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2015-03-26 13:44:34 +03: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 17:12:48 +04:00
|
|
|
*/
|
2015-02-26 13:37:37 +03:00
|
|
|
|
2013-11-26 17:12:48 +04:00
|
|
|
namespace OC;
|
|
|
|
|
2017-04-23 23:10:17 +03:00
|
|
|
use OC\App\AppStore\Bundles\BundleFetcher;
|
2017-07-27 17:52:28 +03:00
|
|
|
use OC\Files\AppData\Factory;
|
2015-01-14 13:57:26 +03:00
|
|
|
use OC\Repair\CleanTags;
|
2014-10-06 14:38:59 +04:00
|
|
|
use OC\Repair\Collation;
|
2016-09-23 14:38:37 +03:00
|
|
|
use OC\Repair\MoveUpdaterStepFile;
|
2016-11-16 13:40:52 +03:00
|
|
|
use OC\Repair\NC11\CleanPreviews;
|
2016-12-13 14:09:31 +03:00
|
|
|
use OC\Repair\NC11\FixMountStorages;
|
2016-09-12 10:53:31 +03:00
|
|
|
use OC\Repair\NC11\MoveAvatars;
|
2017-04-23 23:10:17 +03:00
|
|
|
use OC\Repair\NC12\InstallCoreBundle;
|
2016-09-12 19:15:22 +03:00
|
|
|
use OC\Repair\NC12\UpdateLanguageCodes;
|
2017-08-29 11:56:14 +03:00
|
|
|
use OC\Repair\NC12\RepairIdentityProofKeyFolders;
|
2017-10-23 22:26:24 +03:00
|
|
|
use OC\Repair\NC13\AddLogRotateJob;
|
2015-10-19 17:41:43 +03:00
|
|
|
use OC\Repair\OldGroupMembershipShares;
|
2017-07-27 12:27:25 +03:00
|
|
|
use OC\Repair\Owncloud\DropAccountTermsTable;
|
2017-05-11 15:04:53 +03:00
|
|
|
use OC\Repair\Owncloud\SaveAccountsTableData;
|
2016-06-13 14:14:38 +03:00
|
|
|
use OC\Repair\RemoveRootShares;
|
2017-06-22 00:50:20 +03:00
|
|
|
use OC\Repair\NC13\RepairInvalidPaths;
|
2015-03-25 20:31:49 +03:00
|
|
|
use OC\Repair\SqliteAutoincrement;
|
2014-10-06 14:38:59 +04:00
|
|
|
use OC\Repair\RepairMimeTypes;
|
2015-09-17 17:01:11 +03:00
|
|
|
use OC\Repair\RepairInvalidShares;
|
2016-05-03 16:16:39 +03:00
|
|
|
use OCP\AppFramework\QueryException;
|
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-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]);
|
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)) {
|
2016-05-03 16:16:39 +03:00
|
|
|
try {
|
|
|
|
$s = \OC::$server->query($repairStep);
|
|
|
|
} catch (QueryException $e) {
|
|
|
|
if (class_exists($repairStep)) {
|
|
|
|
$s = new $repairStep();
|
2016-04-19 16:36:11 +03:00
|
|
|
} else {
|
2016-05-03 16:16:39 +03:00
|
|
|
throw new \Exception("Repair step '$repairStep' is unknown");
|
2016-04-19 16:36:11 +03:00
|
|
|
}
|
2016-05-03 16:16:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($s instanceof IRepairStep) {
|
|
|
|
$this->repairSteps[] = $s;
|
2016-04-19 16:36:11 +03:00
|
|
|
} else {
|
2016-05-03 16:16: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 {
|
|
|
|
$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 [
|
2016-10-18 12:10:55 +03:00
|
|
|
new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->getDatabaseConnection(), false),
|
2015-08-25 15:09:38 +03:00
|
|
|
new RepairMimeTypes(\OC::$server->getConfig()),
|
2016-06-14 13:30:22 +03:00
|
|
|
new CleanTags(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager()),
|
2015-09-17 17:01:11 +03:00
|
|
|
new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()),
|
2016-06-17 11:53:55 +03:00
|
|
|
new RemoveRootShares(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager(), \OC::$server->getLazyRootFolder()),
|
2016-09-23 14:38:37 +03:00
|
|
|
new MoveUpdaterStepFile(\OC::$server->getConfig()),
|
2016-09-12 10:53:31 +03:00
|
|
|
new MoveAvatars(
|
2016-09-14 22:59:33 +03:00
|
|
|
\OC::$server->getJobList(),
|
2016-11-29 18:05:09 +03:00
|
|
|
\OC::$server->getConfig()
|
2016-09-12 10:53:31 +03:00
|
|
|
),
|
2016-11-16 13:40:52 +03:00
|
|
|
new CleanPreviews(
|
|
|
|
\OC::$server->getJobList(),
|
2016-11-19 22:26:53 +03:00
|
|
|
\OC::$server->getUserManager(),
|
|
|
|
\OC::$server->getConfig()
|
2016-11-16 13:40:52 +03:00
|
|
|
),
|
2016-12-13 14:09:31 +03:00
|
|
|
new FixMountStorages(\OC::$server->getDatabaseConnection()),
|
2017-03-03 14:20:02 +03:00
|
|
|
new UpdateLanguageCodes(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()),
|
2017-04-23 23:10:17 +03:00
|
|
|
new InstallCoreBundle(
|
|
|
|
\OC::$server->query(BundleFetcher::class),
|
|
|
|
\OC::$server->getConfig(),
|
|
|
|
\OC::$server->query(Installer::class)
|
2017-06-20 17:31:52 +03:00
|
|
|
),
|
2017-07-27 17:52:28 +03:00
|
|
|
new RepairInvalidPaths(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()),
|
|
|
|
new RepairIdentityProofKeyFolders(\OC::$server->getConfig(), \OC::$server->query(Factory::class), \OC::$server->getRootFolder()),
|
2017-10-23 22:26:24 +03:00
|
|
|
new AddLogRotateJob(\OC::$server->getJobList()),
|
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 [
|
2017-06-20 17:31:52 +03:00
|
|
|
new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager())
|
2015-10-19 17:41:43 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
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();
|
2017-05-11 15:04:53 +03:00
|
|
|
$config = \OC::$server->getConfig();
|
2015-12-08 10:46:41 +03:00
|
|
|
$steps = [
|
2016-10-18 12:10:55 +03:00
|
|
|
new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), $connection, true),
|
2016-01-07 12:26:00 +03:00
|
|
|
new SqliteAutoincrement($connection),
|
2017-05-11 15:04:53 +03:00
|
|
|
new SaveAccountsTableData($connection, $config),
|
2017-07-27 12:27:25 +03:00
|
|
|
new DropAccountTermsTable($connection),
|
2015-12-08 10:46:41 +03:00
|
|
|
];
|
2014-09-21 19:16:21 +04:00
|
|
|
|
|
|
|
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
|
|
|
}
|