2013-11-26 17:12:48 +04:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 18:07:57 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2020-03-31 11:49:10 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Daniel Kesselberg <mail@danielkesselberg.de>
|
2017-11-06 22:15:27 +03:00
|
|
|
* @author Georg Ehrke <oc.list@georgehrke.com>
|
2016-07-21 18:07:57 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
|
|
|
|
* @author Julius Härtl <jus@bitgrid.net>
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Michael Weimann <mail@michael-weimann.eu>
|
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,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2015-03-26 13:44:34 +03:00
|
|
|
*
|
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;
|
|
|
|
|
2020-12-07 16:30:08 +03:00
|
|
|
use OC\App\AppStore\Bundles\BundleFetcher;
|
2019-01-20 13:13:41 +03:00
|
|
|
use OC\Avatar\AvatarManager;
|
2018-06-13 18:43:29 +03:00
|
|
|
use OC\Repair\AddCleanupUpdaterBackupsJob;
|
2015-01-14 13:57:26 +03:00
|
|
|
use OC\Repair\CleanTags;
|
2018-01-26 19:46:42 +03:00
|
|
|
use OC\Repair\ClearFrontendCaches;
|
2019-02-01 23:13:06 +03:00
|
|
|
use OC\Repair\ClearGeneratedAvatarCache;
|
2014-10-06 14:38:59 +04:00
|
|
|
use OC\Repair\Collation;
|
2016-09-23 14:38:37 +03:00
|
|
|
use OC\Repair\MoveUpdaterStepFile;
|
2020-12-07 16:30:08 +03:00
|
|
|
use OC\Repair\Owncloud\CleanPreviews;
|
2016-12-13 14:09:31 +03:00
|
|
|
use OC\Repair\NC11\FixMountStorages;
|
2020-12-07 16:30:08 +03:00
|
|
|
use OC\Repair\Owncloud\MoveAvatars;
|
|
|
|
use OC\Repair\Owncloud\InstallCoreBundle;
|
|
|
|
use OC\Repair\Owncloud\UpdateLanguageCodes;
|
2017-10-23 22:26:24 +03:00
|
|
|
use OC\Repair\NC13\AddLogRotateJob;
|
2018-05-08 15:47:50 +03:00
|
|
|
use OC\Repair\NC14\AddPreviewBackgroundCleanupJob;
|
2019-02-12 11:26:46 +03:00
|
|
|
use OC\Repair\NC16\AddClenupLoginFlowV2BackgroundJob;
|
2019-02-01 23:13:06 +03:00
|
|
|
use OC\Repair\NC16\CleanupCardDAVPhotoCache;
|
2019-08-21 10:12:42 +03:00
|
|
|
use OC\Repair\NC16\ClearCollectionsAccessCache;
|
2019-12-20 17:03:22 +03:00
|
|
|
use OC\Repair\NC18\ResetGeneratedAvatarFlag;
|
2020-08-12 14:22:24 +03:00
|
|
|
use OC\Repair\NC20\EncryptionLegacyCipher;
|
2020-06-22 16:35:52 +03:00
|
|
|
use OC\Repair\NC20\EncryptionMigration;
|
2020-08-24 11:12:25 +03:00
|
|
|
use OC\Repair\NC20\ShippedDashboardEnable;
|
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;
|
2019-04-15 22:19:32 +03:00
|
|
|
use OC\Repair\RemoveLinkShares;
|
2021-01-29 19:00:18 +03:00
|
|
|
use OC\Repair\RepairDavShares;
|
2015-09-17 17:01:11 +03:00
|
|
|
use OC\Repair\RepairInvalidShares;
|
2018-11-06 17:43:53 +03:00
|
|
|
use OC\Repair\RepairMimeTypes;
|
|
|
|
use OC\Repair\SqliteAutoincrement;
|
2018-01-26 19:46:42 +03:00
|
|
|
use OC\Template\JSCombiner;
|
|
|
|
use OC\Template\SCSSCacher;
|
2019-02-01 23:13:06 +03:00
|
|
|
use OCP\AppFramework\QueryException;
|
2019-04-15 22:19:32 +03:00
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
2019-08-21 10:12:42 +03:00
|
|
|
use OCP\Collaboration\Resources\IManager;
|
2019-02-01 23:13:06 +03:00
|
|
|
use OCP\Migration\IOutput;
|
|
|
|
use OCP\Migration\IRepairStep;
|
2019-02-02 20:07:48 +03:00
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
2016-04-19 16:36:11 +03:00
|
|
|
use Symfony\Component\EventDispatcher\GenericEvent;
|
2013-11-26 17:12:48 +04:00
|
|
|
|
2018-11-06 17:43:53 +03:00
|
|
|
class Repair implements IOutput {
|
|
|
|
|
|
|
|
/** @var IRepairStep[] */
|
2014-06-10 13:47:27 +04:00
|
|
|
private $repairSteps;
|
2018-11-06 17:43:53 +03:00
|
|
|
|
2019-02-02 20:07:48 +03:00
|
|
|
/** @var EventDispatcherInterface */
|
2016-04-19 16:36:11 +03:00
|
|
|
private $dispatcher;
|
2018-11-06 17:43:53 +03:00
|
|
|
|
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
|
2019-02-02 20:07:48 +03:00
|
|
|
* @param EventDispatcherInterface $dispatcher
|
2014-03-25 15:51:16 +04:00
|
|
|
*/
|
2019-02-06 22:56:17 +03:00
|
|
|
public function __construct(array $repairSteps, EventDispatcherInterface $dispatcher) {
|
2014-06-10 13:47:27 +04:00
|
|
|
$this->repairSteps = $repairSteps;
|
2018-11-06 17:43:53 +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) {
|
2020-03-26 11:30:18 +03:00
|
|
|
$this->emit('\OC\Repair', 'info', ['No repair steps available']);
|
2018-11-06 17:43:53 +03:00
|
|
|
|
2014-06-10 13:47:27 +04:00
|
|
|
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),
|
2020-11-06 12:26:41 +03:00
|
|
|
new RepairMimeTypes(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()),
|
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-09-23 14:38:37 +03:00
|
|
|
new MoveUpdaterStepFile(\OC::$server->getConfig()),
|
2020-12-07 16:30:08 +03:00
|
|
|
new MoveAvatars(
|
|
|
|
\OC::$server->getJobList(),
|
|
|
|
\OC::$server->getConfig()
|
|
|
|
),
|
|
|
|
new CleanPreviews(
|
|
|
|
\OC::$server->getJobList(),
|
|
|
|
\OC::$server->getUserManager(),
|
|
|
|
\OC::$server->getConfig()
|
|
|
|
),
|
2016-12-13 14:09:31 +03:00
|
|
|
new FixMountStorages(\OC::$server->getDatabaseConnection()),
|
2020-12-07 16:30:08 +03:00
|
|
|
new UpdateLanguageCodes(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()),
|
|
|
|
new InstallCoreBundle(
|
|
|
|
\OC::$server->query(BundleFetcher::class),
|
|
|
|
\OC::$server->getConfig(),
|
|
|
|
\OC::$server->query(Installer::class)
|
|
|
|
),
|
2017-10-23 22:26:24 +03:00
|
|
|
new AddLogRotateJob(\OC::$server->getJobList()),
|
2018-05-08 15:47:50 +03:00
|
|
|
new ClearFrontendCaches(\OC::$server->getMemCacheFactory(), \OC::$server->query(SCSSCacher::class), \OC::$server->query(JSCombiner::class)),
|
2018-11-06 17:43:53 +03:00
|
|
|
new ClearGeneratedAvatarCache(\OC::$server->getConfig(), \OC::$server->query(AvatarManager::class)),
|
2018-05-08 15:47:50 +03:00
|
|
|
new AddPreviewBackgroundCleanupJob(\OC::$server->getJobList()),
|
2018-06-13 18:43:29 +03:00
|
|
|
new AddCleanupUpdaterBackupsJob(\OC::$server->getJobList()),
|
2019-02-06 22:39:15 +03:00
|
|
|
new CleanupCardDAVPhotoCache(\OC::$server->getConfig(), \OC::$server->getAppDataDir('dav-photocache'), \OC::$server->getLogger()),
|
2019-02-12 11:26:46 +03:00
|
|
|
new AddClenupLoginFlowV2BackgroundJob(\OC::$server->getJobList()),
|
2019-04-15 22:19:32 +03:00
|
|
|
new RemoveLinkShares(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig(), \OC::$server->getGroupManager(), \OC::$server->getNotificationManager(), \OC::$server->query(ITimeFactory::class)),
|
2019-08-21 10:12:42 +03:00
|
|
|
new ClearCollectionsAccessCache(\OC::$server->getConfig(), \OC::$server->query(IManager::class)),
|
2019-12-20 17:03:22 +03:00
|
|
|
\OC::$server->query(ResetGeneratedAvatarFlag::class),
|
2020-08-12 14:22:24 +03:00
|
|
|
\OC::$server->query(EncryptionLegacyCipher::class),
|
2020-06-22 16:35:52 +03:00
|
|
|
\OC::$server->query(EncryptionMigration::class),
|
2020-08-24 11:12:25 +03:00
|
|
|
\OC::$server->get(ShippedDashboardEnable::class),
|
2021-02-17 17:26:06 +03:00
|
|
|
\OC::$server->get(RepairDavShares::class)
|
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 [
|
2018-11-06 17:43:53 +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();
|
2018-11-06 17:43:53 +03:00
|
|
|
$config = \OC::$server->getConfig();
|
|
|
|
$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),
|
2021-02-17 17:26:06 +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
|
2020-03-26 11:30:18 +03:00
|
|
|
$this->emit('\OC\Repair', 'info', [$string]);
|
2016-04-22 16:35:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
}
|