2013-11-26 13:12:48 +00:00
|
|
|
<?php
|
2024-05-23 07:26:56 +00:00
|
|
|
|
2013-11-26 13:12:48 +00:00
|
|
|
/**
|
2024-05-23 07:26:56 +00:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2013-11-26 13:12:48 +00:00
|
|
|
*/
|
|
|
|
namespace OC;
|
|
|
|
|
2021-01-03 14:28:31 +00:00
|
|
|
use OC\DB\Connection;
|
|
|
|
use OC\DB\ConnectionAdapter;
|
2024-02-29 13:43:08 +00:00
|
|
|
use OC\Repair\AddAppConfigLazyMigration;
|
2020-10-08 13:02:51 +00:00
|
|
|
use OC\Repair\AddBruteForceCleanupJob;
|
2024-09-10 20:50:16 +00:00
|
|
|
use OC\Repair\AddCleanupDeletedUsersBackgroundJob;
|
2018-06-13 15:43:29 +00:00
|
|
|
use OC\Repair\AddCleanupUpdaterBackupsJob;
|
2023-11-16 14:02:38 +00:00
|
|
|
use OC\Repair\AddMetadataGenerationJob;
|
2023-06-28 12:59:20 +00:00
|
|
|
use OC\Repair\AddRemoveOldTasksBackgroundJob;
|
2015-01-14 10:57:26 +00:00
|
|
|
use OC\Repair\CleanTags;
|
2022-09-28 16:13:53 +00:00
|
|
|
use OC\Repair\CleanUpAbandonedApps;
|
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;
|
2022-08-22 15:59:26 +00:00
|
|
|
use OC\Repair\Events\RepairAdvanceEvent;
|
|
|
|
use OC\Repair\Events\RepairErrorEvent;
|
|
|
|
use OC\Repair\Events\RepairFinishEvent;
|
|
|
|
use OC\Repair\Events\RepairInfoEvent;
|
|
|
|
use OC\Repair\Events\RepairStartEvent;
|
|
|
|
use OC\Repair\Events\RepairStepEvent;
|
|
|
|
use OC\Repair\Events\RepairWarningEvent;
|
2016-09-23 11:38:37 +00:00
|
|
|
use OC\Repair\MoveUpdaterStepFile;
|
2017-10-23 19:26:24 +00:00
|
|
|
use OC\Repair\NC13\AddLogRotateJob;
|
2018-05-08 12:47:50 +00:00
|
|
|
use OC\Repair\NC14\AddPreviewBackgroundCleanupJob;
|
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;
|
2019-08-21 07:12:42 +00:00
|
|
|
use OC\Repair\NC16\ClearCollectionsAccessCache;
|
2019-12-20 14:03:22 +00:00
|
|
|
use OC\Repair\NC18\ResetGeneratedAvatarFlag;
|
2020-08-12 11:22:24 +00:00
|
|
|
use OC\Repair\NC20\EncryptionLegacyCipher;
|
2020-06-22 13:35:52 +00:00
|
|
|
use OC\Repair\NC20\EncryptionMigration;
|
2020-08-24 08:12:25 +00:00
|
|
|
use OC\Repair\NC20\ShippedDashboardEnable;
|
2020-11-02 23:00:05 +00:00
|
|
|
use OC\Repair\NC21\AddCheckForUserCertificatesJob;
|
2020-12-07 15:36:49 +00:00
|
|
|
use OC\Repair\NC21\ValidatePhoneNumber;
|
2022-08-22 15:59:26 +00:00
|
|
|
use OC\Repair\NC22\LookupServerSendCheck;
|
|
|
|
use OC\Repair\NC24\AddTokenCleanupJob;
|
2022-11-23 15:04:42 +00:00
|
|
|
use OC\Repair\NC25\AddMissingSecretJob;
|
2024-07-11 18:53:37 +00:00
|
|
|
use OC\Repair\NC30\RemoveLegacyDatadirFile;
|
2015-10-19 14:41:43 +00:00
|
|
|
use OC\Repair\OldGroupMembershipShares;
|
2022-08-22 15:59:26 +00:00
|
|
|
use OC\Repair\Owncloud\CleanPreviews;
|
2017-07-27 09:27:25 +00:00
|
|
|
use OC\Repair\Owncloud\DropAccountTermsTable;
|
2022-08-22 15:59:26 +00:00
|
|
|
use OC\Repair\Owncloud\MigrateOauthTables;
|
|
|
|
use OC\Repair\Owncloud\MoveAvatars;
|
2017-05-11 12:04:53 +00:00
|
|
|
use OC\Repair\Owncloud\SaveAccountsTableData;
|
2022-08-22 15:59:26 +00:00
|
|
|
use OC\Repair\Owncloud\UpdateLanguageCodes;
|
2024-11-28 03:16:58 +00:00
|
|
|
use OC\Repair\RemoveBrokenProperties;
|
2019-04-15 19:19:32 +00:00
|
|
|
use OC\Repair\RemoveLinkShares;
|
2021-01-29 16:00:18 +00:00
|
|
|
use OC\Repair\RepairDavShares;
|
2015-09-17 14:01:11 +00:00
|
|
|
use OC\Repair\RepairInvalidShares;
|
2024-07-10 13:29:45 +00:00
|
|
|
use OC\Repair\RepairLogoDimension;
|
2018-11-06 14:43:53 +00:00
|
|
|
use OC\Repair\RepairMimeTypes;
|
2018-01-26 16:46:42 +00:00
|
|
|
use OC\Template\JSCombiner;
|
2024-05-08 18:38:51 +00:00
|
|
|
use OCA\DAV\Migration\DeleteSchedulingObjects;
|
2022-08-22 15:59:26 +00:00
|
|
|
use OCP\AppFramework\QueryException;
|
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
|
|
|
use OCP\Collaboration\Resources\IManager;
|
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
2024-09-17 12:03:35 +00:00
|
|
|
use OCP\IAppConfig;
|
|
|
|
use OCP\IConfig;
|
|
|
|
use OCP\IDBConnection;
|
2022-08-22 15:59:26 +00:00
|
|
|
use OCP\Migration\IOutput;
|
|
|
|
use OCP\Migration\IRepairStep;
|
2024-05-30 12:33:12 +00:00
|
|
|
use OCP\Notification\IManager as INotificationManager;
|
2021-02-01 13:56:56 +00:00
|
|
|
use Psr\Log\LoggerInterface;
|
2021-11-30 07:56:41 +00:00
|
|
|
use Throwable;
|
2013-11-26 13:12:48 +00:00
|
|
|
|
2018-11-06 14:43:53 +00:00
|
|
|
class Repair implements IOutput {
|
|
|
|
/** @var IRepairStep[] */
|
2024-01-30 11:14:52 +00:00
|
|
|
private array $repairSteps = [];
|
2018-11-06 14:43:53 +00:00
|
|
|
|
2022-09-28 16:13:53 +00:00
|
|
|
private string $currentStep;
|
2014-03-25 11:51:16 +00:00
|
|
|
|
2024-01-30 11:14:52 +00:00
|
|
|
public function __construct(
|
|
|
|
private IEventDispatcher $dispatcher,
|
|
|
|
private LoggerInterface $logger,
|
|
|
|
) {
|
|
|
|
}
|
2021-02-01 13:56:56 +00:00
|
|
|
|
2024-01-30 11:14:52 +00:00
|
|
|
/** @param IRepairStep[] $repairSteps */
|
|
|
|
public function setRepairSteps(array $repairSteps): void {
|
2014-06-10 09:47:27 +00:00
|
|
|
$this->repairSteps = $repairSteps;
|
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) {
|
2022-08-22 15:59:26 +00:00
|
|
|
$this->dispatcher->dispatchTyped(new RepairInfoEvent('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();
|
2022-08-22 15:59:26 +00:00
|
|
|
$this->dispatcher->dispatchTyped(new RepairStepEvent($this->currentStep));
|
2021-01-13 18:00:45 +00:00
|
|
|
try {
|
|
|
|
$step->run($this);
|
|
|
|
} catch (\Exception $e) {
|
2021-02-01 13:56:56 +00:00
|
|
|
$this->logger->error('Exception while executing repair step ' . $step->getName(), ['exception' => $e]);
|
2022-08-22 15:59:26 +00:00
|
|
|
$this->dispatcher->dispatchTyped(new RepairErrorEvent($e->getMessage()));
|
2021-01-13 18:00:45 +00:00
|
|
|
}
|
2014-03-25 11:51:16 +00:00
|
|
|
}
|
2024-06-18 09:55:08 +00:00
|
|
|
|
|
|
|
$this->repairSteps = [];
|
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 {
|
2022-08-22 15:59:26 +00:00
|
|
|
$s = \OC::$server->get($repairStep);
|
2016-05-03 13:16:39 +00:00
|
|
|
} catch (QueryException $e) {
|
|
|
|
if (class_exists($repairStep)) {
|
2021-11-30 07:56:41 +00:00
|
|
|
try {
|
|
|
|
// Last resort: hope there are no constructor arguments
|
|
|
|
$s = new $repairStep();
|
|
|
|
} catch (Throwable $inner) {
|
|
|
|
// Well, it was worth a try
|
|
|
|
throw new \Exception("Repair step '$repairStep' can't be instantiated: " . $e->getMessage(), 0, $e);
|
|
|
|
}
|
2016-04-19 13:36:11 +00:00
|
|
|
} else {
|
2021-11-30 09:57:49 +00:00
|
|
|
throw new \Exception("Repair step '$repairStep' is unknown", 0, $e);
|
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
|
|
|
*/
|
2022-09-28 16:13:53 +00:00
|
|
|
public static function getRepairSteps(): array {
|
2015-07-16 16:41:08 +00:00
|
|
|
return [
|
2022-03-17 16:26:27 +00:00
|
|
|
new Collation(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class), \OC::$server->getDatabaseConnection(), false),
|
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-09-23 11:38:37 +00:00
|
|
|
new MoveUpdaterStepFile(\OC::$server->getConfig()),
|
2020-12-07 13:30:08 +00:00
|
|
|
new MoveAvatars(
|
|
|
|
\OC::$server->getJobList(),
|
|
|
|
\OC::$server->getConfig()
|
|
|
|
),
|
|
|
|
new CleanPreviews(
|
|
|
|
\OC::$server->getJobList(),
|
|
|
|
\OC::$server->getUserManager(),
|
|
|
|
\OC::$server->getConfig()
|
|
|
|
),
|
2021-12-16 15:46:03 +00:00
|
|
|
new MigrateOauthTables(\OC::$server->get(Connection::class)),
|
2020-12-07 13:30:08 +00:00
|
|
|
new UpdateLanguageCodes(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()),
|
2017-10-23 19:26:24 +00:00
|
|
|
new AddLogRotateJob(\OC::$server->getJobList()),
|
2023-06-06 09:09:24 +00:00
|
|
|
new ClearFrontendCaches(\OC::$server->getMemCacheFactory(), \OCP\Server::get(JSCombiner::class)),
|
2022-09-19 17:03:27 +00:00
|
|
|
\OCP\Server::get(ClearGeneratedAvatarCache::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()),
|
2022-03-17 16:26:27 +00:00
|
|
|
new CleanupCardDAVPhotoCache(\OC::$server->getConfig(), \OC::$server->getAppDataDir('dav-photocache'), \OC::$server->get(LoggerInterface::class)),
|
2019-02-12 08:26:46 +00:00
|
|
|
new AddClenupLoginFlowV2BackgroundJob(\OC::$server->getJobList()),
|
2023-08-29 22:12:25 +00:00
|
|
|
new RemoveLinkShares(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig(), \OC::$server->getGroupManager(), \OC::$server->get(INotificationManager::class), \OCP\Server::get(ITimeFactory::class)),
|
2023-06-06 09:09:24 +00:00
|
|
|
new ClearCollectionsAccessCache(\OC::$server->getConfig(), \OCP\Server::get(IManager::class)),
|
2022-09-19 17:03:27 +00:00
|
|
|
\OCP\Server::get(ResetGeneratedAvatarFlag::class),
|
|
|
|
\OCP\Server::get(EncryptionLegacyCipher::class),
|
|
|
|
\OCP\Server::get(EncryptionMigration::class),
|
|
|
|
\OCP\Server::get(ShippedDashboardEnable::class),
|
|
|
|
\OCP\Server::get(AddBruteForceCleanupJob::class),
|
|
|
|
\OCP\Server::get(AddCheckForUserCertificatesJob::class),
|
|
|
|
\OCP\Server::get(RepairDavShares::class),
|
|
|
|
\OCP\Server::get(LookupServerSendCheck::class),
|
|
|
|
\OCP\Server::get(AddTokenCleanupJob::class),
|
2022-09-28 16:13:53 +00:00
|
|
|
\OCP\Server::get(CleanUpAbandonedApps::class),
|
2022-11-23 15:04:42 +00:00
|
|
|
\OCP\Server::get(AddMissingSecretJob::class),
|
2023-06-28 12:59:20 +00:00
|
|
|
\OCP\Server::get(AddRemoveOldTasksBackgroundJob::class),
|
2023-11-16 14:02:38 +00:00
|
|
|
\OCP\Server::get(AddMetadataGenerationJob::class),
|
2024-02-29 13:43:08 +00:00
|
|
|
\OCP\Server::get(AddAppConfigLazyMigration::class),
|
2024-07-10 13:29:45 +00:00
|
|
|
\OCP\Server::get(RepairLogoDimension::class),
|
2024-07-11 18:53:37 +00:00
|
|
|
\OCP\Server::get(RemoveLegacyDatadirFile::class),
|
2024-09-10 20:50:16 +00:00
|
|
|
\OCP\Server::get(AddCleanupDeletedUsersBackgroundJob::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 [
|
2020-12-07 15:36:49 +00:00
|
|
|
new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager()),
|
2024-11-28 03:16:58 +00:00
|
|
|
new RemoveBrokenProperties(\OCP\Server::get(IDBConnection::class)),
|
2024-09-17 12:03:35 +00:00
|
|
|
new RepairMimeTypes(
|
|
|
|
\OCP\Server::get(IConfig::class),
|
|
|
|
\OCP\Server::get(IAppConfig::class),
|
|
|
|
\OCP\Server::get(IDBConnection::class)
|
|
|
|
),
|
2020-12-07 15:36:49 +00:00
|
|
|
\OC::$server->get(ValidatePhoneNumber::class),
|
2024-05-08 18:38:51 +00:00
|
|
|
\OC::$server->get(DeleteSchedulingObjects::class),
|
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() {
|
2021-01-03 14:28:31 +00:00
|
|
|
/** @var ConnectionAdapter $connectionAdapter */
|
|
|
|
$connectionAdapter = \OC::$server->get(ConnectionAdapter::class);
|
2020-10-05 13:12:57 +00:00
|
|
|
$config = \OC::$server->getConfig();
|
|
|
|
$steps = [
|
2022-03-17 16:26:27 +00:00
|
|
|
new Collation(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class), $connectionAdapter, true),
|
2021-01-03 14:28:31 +00:00
|
|
|
new SaveAccountsTableData($connectionAdapter, $config),
|
2021-01-29 16:00:18 +00:00
|
|
|
new DropAccountTermsTable($connectionAdapter),
|
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
|
|
|
|
2023-10-31 11:06:09 +00:00
|
|
|
public function debug(string $message): void {
|
|
|
|
}
|
|
|
|
|
2014-06-26 12:27:41 +00:00
|
|
|
/**
|
2022-08-22 15:59:26 +00:00
|
|
|
* @param string $message
|
2014-06-26 12:27:41 +00:00
|
|
|
*/
|
2022-08-22 15:59:26 +00:00
|
|
|
public function info($message) {
|
2016-04-22 13:35:39 +00:00
|
|
|
// for now just emit as we did in the past
|
2022-08-22 15:59:26 +00:00
|
|
|
$this->dispatcher->dispatchTyped(new RepairInfoEvent($message));
|
2016-04-22 13:35:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $message
|
|
|
|
*/
|
|
|
|
public function warning($message) {
|
|
|
|
// for now just emit as we did in the past
|
2022-08-22 15:59:26 +00:00
|
|
|
$this->dispatcher->dispatchTyped(new RepairWarningEvent($message));
|
2016-04-22 13:35:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $max
|
|
|
|
*/
|
|
|
|
public function startProgress($max = 0) {
|
|
|
|
// for now just emit as we did in the past
|
2022-08-22 15:59:26 +00:00
|
|
|
$this->dispatcher->dispatchTyped(new RepairStartEvent($max, $this->currentStep));
|
2016-04-22 13:35:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-08-25 14:26:31 +00:00
|
|
|
* @param int $step number of step to advance
|
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
|
2022-08-22 15:59:26 +00:00
|
|
|
$this->dispatcher->dispatchTyped(new RepairAdvanceEvent($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
|
2022-08-22 15:59:26 +00:00
|
|
|
$this->dispatcher->dispatchTyped(new RepairFinishEvent());
|
2016-04-22 13:35:39 +00:00
|
|
|
}
|
2013-11-26 13:12:48 +00:00
|
|
|
}
|