2013-11-26 13:12:48 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 15:07:57 +00:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2017-11-06 14:56:42 +00:00
|
|
|
* @author Bjoern Schiessle <bjoern@schiessle.org>
|
2017-11-06 19:15:27 +00:00
|
|
|
* @author Georg Ehrke <oc.list@georgehrke.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;
|
|
|
|
|
2019-01-20 10:13:41 +00:00
|
|
|
use OC\Avatar\AvatarManager;
|
2018-06-13 15:43:29 +00:00
|
|
|
use OC\Repair\AddCleanupUpdaterBackupsJob;
|
2015-01-14 10:57:26 +00:00
|
|
|
use OC\Repair\CleanTags;
|
2018-01-26 16:46:42 +00:00
|
|
|
use OC\Repair\ClearFrontendCaches;
|
2019-02-01 20:13:06 +00:00
|
|
|
use OC\Repair\ClearGeneratedAvatarCache;
|
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-12-13 11:09:31 +00:00
|
|
|
use OC\Repair\NC11\FixMountStorages;
|
2017-10-23 19:26:24 +00:00
|
|
|
use OC\Repair\NC13\AddLogRotateJob;
|
2018-11-06 14:43:53 +00:00
|
|
|
use OC\Repair\NC13\RepairInvalidPaths;
|
2018-05-08 12:47:50 +00:00
|
|
|
use OC\Repair\NC14\AddPreviewBackgroundCleanupJob;
|
2018-07-05 10:27:36 +00:00
|
|
|
use OC\Repair\NC14\RepairPendingCronJobs;
|
2018-10-26 16:27:39 +00:00
|
|
|
use OC\Repair\NC15\SetVcardDatabaseUID;
|
2019-02-12 08:26:46 +00:00
|
|
|
use OC\Repair\NC16\AddClenupLoginFlowV2BackgroundJob;
|
2019-02-01 20:13:06 +00:00
|
|
|
use OC\Repair\NC16\CleanupCardDAVPhotoCache;
|
2015-10-19 14:41:43 +00:00
|
|
|
use OC\Repair\OldGroupMembershipShares;
|
2017-07-27 09:27:25 +00:00
|
|
|
use OC\Repair\Owncloud\DropAccountTermsTable;
|
2017-05-11 12:04:53 +00:00
|
|
|
use OC\Repair\Owncloud\SaveAccountsTableData;
|
2019-04-15 19:19:32 +00:00
|
|
|
use OC\Repair\RemoveLinkShares;
|
2016-06-13 11:14:38 +00:00
|
|
|
use OC\Repair\RemoveRootShares;
|
2015-09-17 14:01:11 +00:00
|
|
|
use OC\Repair\RepairInvalidShares;
|
2018-11-06 14:43:53 +00:00
|
|
|
use OC\Repair\RepairMimeTypes;
|
|
|
|
use OC\Repair\SqliteAutoincrement;
|
2018-01-26 16:46:42 +00:00
|
|
|
use OC\Template\JSCombiner;
|
|
|
|
use OC\Template\SCSSCacher;
|
2019-02-01 20:13:06 +00:00
|
|
|
use OCP\AppFramework\QueryException;
|
2019-04-15 19:19:32 +00:00
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
2019-02-01 20:13:06 +00:00
|
|
|
use OCP\Migration\IOutput;
|
|
|
|
use OCP\Migration\IRepairStep;
|
2019-02-02 17:07:48 +00:00
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
2016-04-19 13:36:11 +00:00
|
|
|
use Symfony\Component\EventDispatcher\GenericEvent;
|
2013-11-26 13:12:48 +00:00
|
|
|
|
2018-11-06 14:43:53 +00:00
|
|
|
class Repair implements IOutput {
|
|
|
|
|
|
|
|
/** @var IRepairStep[] */
|
2014-06-10 09:47:27 +00:00
|
|
|
private $repairSteps;
|
2018-11-06 14:43:53 +00:00
|
|
|
|
2019-02-02 17:07:48 +00:00
|
|
|
/** @var EventDispatcherInterface */
|
2016-04-19 13:36:11 +00:00
|
|
|
private $dispatcher;
|
2018-11-06 14:43:53 +00:00
|
|
|
|
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
|
2019-02-02 17:07:48 +00:00
|
|
|
* @param EventDispatcherInterface $dispatcher
|
2014-03-25 11:51:16 +00:00
|
|
|
*/
|
2019-02-06 19:56:17 +00:00
|
|
|
public function __construct(array $repairSteps, EventDispatcherInterface $dispatcher) {
|
2014-06-10 09:47:27 +00:00
|
|
|
$this->repairSteps = $repairSteps;
|
2018-11-06 14:43:53 +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'));
|
2018-11-06 14:43:53 +00:00
|
|
|
|
2014-06-10 09:47:27 +00:00
|
|
|
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-12-13 11:09:31 +00:00
|
|
|
new FixMountStorages(\OC::$server->getDatabaseConnection()),
|
2017-07-27 14:52:28 +00:00
|
|
|
new RepairInvalidPaths(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()),
|
2017-10-23 19:26:24 +00:00
|
|
|
new AddLogRotateJob(\OC::$server->getJobList()),
|
2018-05-08 12:47:50 +00:00
|
|
|
new ClearFrontendCaches(\OC::$server->getMemCacheFactory(), \OC::$server->query(SCSSCacher::class), \OC::$server->query(JSCombiner::class)),
|
2018-11-06 14:43:53 +00:00
|
|
|
new ClearGeneratedAvatarCache(\OC::$server->getConfig(), \OC::$server->query(AvatarManager::class)),
|
2018-05-08 12:47:50 +00:00
|
|
|
new AddPreviewBackgroundCleanupJob(\OC::$server->getJobList()),
|
2018-06-13 15:43:29 +00:00
|
|
|
new AddCleanupUpdaterBackupsJob(\OC::$server->getJobList()),
|
2018-07-05 10:27:36 +00:00
|
|
|
new RepairPendingCronJobs(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()),
|
2019-02-01 20:13:06 +00:00
|
|
|
new SetVcardDatabaseUID(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig(), \OC::$server->getLogger()),
|
2019-02-06 19:39:15 +00:00
|
|
|
new CleanupCardDAVPhotoCache(\OC::$server->getConfig(), \OC::$server->getAppDataDir('dav-photocache'), \OC::$server->getLogger()),
|
2019-02-12 08:26:46 +00:00
|
|
|
new AddClenupLoginFlowV2BackgroundJob(\OC::$server->getJobList()),
|
2019-04-15 19:19:32 +00:00
|
|
|
new RemoveLinkShares(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig(), \OC::$server->getGroupManager(), \OC::$server->getNotificationManager(), \OC::$server->query(ITimeFactory::class)),
|
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 [
|
2018-11-06 14:43:53 +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();
|
2018-11-06 14:43:53 +00:00
|
|
|
$config = \OC::$server->getConfig();
|
|
|
|
$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),
|
2018-11-06 14:43:53 +00:00
|
|
|
new DropAccountTermsTable($connection)
|
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
|
|
|
}
|