Skip to content

Commit 1266c34

Browse files
committed
feat: add new IRepairStepExpensive interface
Expensive repair steps are non-critical repair steps that might take a long time to execute. Non-critical means that they are not required to directly be executed during migration to have a working instance, but they might be required to have a fully working instance later on. Expensive repair steps are only executed when explicitly requested by the administrator. Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 6afd7bf commit 1266c34

3 files changed

Lines changed: 49 additions & 35 deletions

File tree

core/Command/Maintenance/Repair.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,11 @@ protected function configure(): void {
5151
}
5252

5353
protected function execute(InputInterface $input, OutputInterface $output): int {
54-
$repairSteps = $this->repair::getRepairSteps();
55-
56-
if ($input->getOption('include-expensive')) {
57-
$repairSteps = array_merge($repairSteps, $this->repair::getExpensiveRepairSteps());
58-
}
54+
$includeExpensive = (bool)$input->getOption('include-expensive');
55+
$repairSteps = $this->repair::getRepairSteps($includeExpensive);
5956

6057
foreach ($repairSteps as $step) {
61-
$this->repair->addStep($step);
58+
$this->repair->addStep($step, $includeExpensive);
6259
}
6360

6461
$apps = $this->appManager->getEnabledApps();
@@ -74,7 +71,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7471
$steps = $info['repair-steps']['post-migration'];
7572
foreach ($steps as $step) {
7673
try {
77-
$this->repair->addStep($step);
74+
$this->repair->addStep($step, $includeExpensive);
7875
} catch (Exception $ex) {
7976
$output->writeln("<error>Failed to load repair step for $app: {$ex->getMessage()}</error>");
8077
}

lib/private/Repair.php

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
use OCP\IDBConnection;
6565
use OCP\Migration\IOutput;
6666
use OCP\Migration\IRepairStep;
67+
use OCP\Migration\IRepairStepExpensive;
6768
use OCP\Server;
6869
use Psr\Container\ContainerExceptionInterface;
6970
use Psr\Log\LoggerInterface;
@@ -113,10 +114,11 @@ public function run(): void {
113114
/**
114115
* Add repair step
115116
*
116-
* @param IRepairStep|class-string<IRepairStep> $repairStep repair step
117+
* @param IRepairStep|class-string<IRepairStep> $repairStep Repair step
118+
* @param bool $includeExpensive Whether to include expensive repair steps, defaults to false
117119
* @throws \Exception
118120
*/
119-
public function addStep(IRepairStep|string $repairStep): void {
121+
public function addStep(IRepairStep|string $repairStep, bool $includeExpensive = false): void {
120122
if (is_string($repairStep)) {
121123
try {
122124
$s = Server::get($repairStep);
@@ -134,24 +136,30 @@ public function addStep(IRepairStep|string $repairStep): void {
134136
}
135137
}
136138

137-
if ($s instanceof IRepairStep) {
138-
$this->repairSteps[] = $s;
139-
} else {
139+
if (!($s instanceof IRepairStep)) {
140140
throw new \Exception("Repair step '$repairStep' is not of type \\OCP\\Migration\\IRepairStep");
141141
}
142+
143+
$repairStep = $s;
144+
}
145+
146+
if (($repairStep instanceof IRepairStepExpensive) && !$includeExpensive) {
147+
$this->debug("Skipping expensive repair step '$repairStep'");
142148
} else {
143149
$this->repairSteps[] = $repairStep;
144150
}
145151
}
146152

147153
/**
148-
* Returns the default repair steps to be run on the
149-
* command line or after an upgrade.
154+
* Returns the core repair steps to be run on the command line or after an upgrade.
150155
*
156+
* @param bool $includeExpensive Whether to include expensive repair steps, defaults to false
151157
* @return list<IRepairStep>
158+
*
159+
* @since 34.0.0, the $includeExpensive parameter was added
152160
*/
153-
public static function getRepairSteps(): array {
154-
return [
161+
public static function getRepairSteps(bool $includeExpensive = false): array {
162+
$repairSteps = [
155163
new Collation(Server::get(IConfig::class), Server::get(LoggerInterface::class), Server::get(IDBConnection::class), false),
156164
Server::get(CleanTags::class),
157165
Server::get(RepairInvalidShares::class),
@@ -190,28 +198,17 @@ public static function getRepairSteps(): array {
190198
Server::get(AddMovePreviewJob::class),
191199
Server::get(ConfigKeyMigration::class),
192200
];
193-
}
194-
195-
/**
196-
* Returns expensive repair steps to be run on the
197-
* command line with a special option.
198-
*
199-
* @return list<IRepairStep>
200-
*/
201-
public static function getExpensiveRepairSteps(): array {
202-
$expensiveSteps = [
203-
Server::get(OldGroupMembershipShares::class),
204-
Server::get(RemoveBrokenProperties::class),
205-
Server::get(RepairMimeTypes::class),
206-
Server::get(DeleteSchedulingObjects::class),
207-
Server::get(RemoveObjectProperties::class),
208-
];
209201

210-
if (class_exists(CleanupShareTarget::class)) {
211-
$expensiveSteps[] = Server::get(CleanupShareTarget::class);
202+
if ($includeExpensive) {
203+
$expensiveSteps = [
204+
Server::get(OldGroupMembershipShares::class),
205+
Server::get(RemoveBrokenProperties::class),
206+
Server::get(RepairMimeTypes::class),
207+
];
208+
$repairSteps = array_merge($repairSteps, $expensiveSteps);
212209
}
213210

214-
return $expensiveSteps;
211+
return $repairSteps;
215212
}
216213

217214
/**
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/*
5+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
6+
* SPDX-License-Identifier: AGPL-3.0-or-later
7+
*/
8+
namespace OCP\Migration;
9+
10+
/**
11+
* Expensive repair steps are non-critical repair steps that might take a long time to execute.
12+
* Non-critical means that they are not required to directly be executed during migration to have a working instance,
13+
* but they might be required to have a fully working instance later on.
14+
*
15+
* Expensive repair steps are only executed when explicitly requested by the administrator.
16+
*
17+
* @since 34.0.0
18+
*/
19+
interface IRepairStepExpensive extends IRepairStep {
20+
}

0 commit comments

Comments
 (0)