Skip to content

Commit 1ea4c49

Browse files
committed
refactor: Update repairs jobs
Signed-off-by: Carl Schwan <[email protected]>
1 parent 584c229 commit 1ea4c49

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+178
-362
lines changed

apps/dav/lib/Migration/RemoveObjectProperties.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,16 @@ class RemoveObjectProperties implements IRepairStep {
1616
private const ME_CARD_PROPERTY = '{http://calendarserver.org/ns/}me-card';
1717
private const CALENDAR_TRANSP_PROPERTY = '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp';
1818

19-
/**
20-
* RemoveObjectProperties constructor.
21-
*
22-
* @param IDBConnection $connection
23-
*/
2419
public function __construct(
25-
private IDBConnection $connection,
20+
private readonly IDBConnection $connection,
2621
) {
2722
}
2823

29-
/**
30-
* @inheritdoc
31-
*/
32-
public function getName() {
24+
public function getName(): string {
3325
return 'Remove invalid object properties';
3426
}
3527

36-
/**
37-
* @inheritdoc
38-
*/
39-
public function run(IOutput $output) {
28+
public function run(IOutput $output): void {
4029
$query = $this->connection->getQueryBuilder();
4130
$updated = $query->delete('properties')
4231
->where($query->expr()->in('propertyname', $query->createNamedParameter([self::RESOURCE_TYPE_PROPERTY, self::ME_CARD_PROPERTY, self::CALENDAR_TRANSP_PROPERTY], IQueryBuilder::PARAM_STR_ARRAY)))

core/Command/Maintenance/Repair.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct(
3939
parent::__construct();
4040
}
4141

42-
protected function configure() {
42+
protected function configure(): void {
4343
$this
4444
->setName('maintenance:repair')
4545
->setDescription('repair this installation')
@@ -81,20 +81,18 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8181
}
8282
}
8383

84-
85-
8684
$maintenanceMode = $this->config->getSystemValueBool('maintenance');
8785
$this->config->setSystemValue('maintenance', true);
8886

8987
$this->progress = new ProgressBar($output);
9088
$this->output = $output;
91-
$this->dispatcher->addListener(RepairStartEvent::class, [$this, 'handleRepairFeedBack']);
92-
$this->dispatcher->addListener(RepairAdvanceEvent::class, [$this, 'handleRepairFeedBack']);
93-
$this->dispatcher->addListener(RepairFinishEvent::class, [$this, 'handleRepairFeedBack']);
94-
$this->dispatcher->addListener(RepairStepEvent::class, [$this, 'handleRepairFeedBack']);
95-
$this->dispatcher->addListener(RepairInfoEvent::class, [$this, 'handleRepairFeedBack']);
96-
$this->dispatcher->addListener(RepairWarningEvent::class, [$this, 'handleRepairFeedBack']);
97-
$this->dispatcher->addListener(RepairErrorEvent::class, [$this, 'handleRepairFeedBack']);
89+
$this->dispatcher->addListener(RepairStartEvent::class, $this->handleRepairFeedBack(...));
90+
$this->dispatcher->addListener(RepairAdvanceEvent::class, $this->handleRepairFeedBack(...));
91+
$this->dispatcher->addListener(RepairFinishEvent::class, $this->handleRepairFeedBack(...));
92+
$this->dispatcher->addListener(RepairStepEvent::class, $this->handleRepairFeedBack(...));
93+
$this->dispatcher->addListener(RepairInfoEvent::class, $this->handleRepairFeedBack(...));
94+
$this->dispatcher->addListener(RepairWarningEvent::class, $this->handleRepairFeedBack(...));
95+
$this->dispatcher->addListener(RepairErrorEvent::class, $this->handleRepairFeedBack(...));
9896

9997
$this->repair->run();
10098

lib/private/Files/Search/SearchQuery.php

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
use OCP\IUser;
1313

1414
class SearchQuery implements ISearchQuery {
15+
/**
16+
* @param ISearchOrder[] $order
17+
*/
1518
public function __construct(
1619
private ISearchOperator $searchOperation,
1720
private int $limit,
@@ -22,38 +25,26 @@ public function __construct(
2225
) {
2326
}
2427

25-
/**
26-
* @return ISearchOperator
27-
*/
28-
public function getSearchOperation() {
28+
public function getSearchOperation(): ISearchOperator {
2929
return $this->searchOperation;
3030
}
3131

32-
/**
33-
* @return int
34-
*/
35-
public function getLimit() {
32+
public function getLimit(): int {
3633
return $this->limit;
3734
}
3835

39-
/**
40-
* @return int
41-
*/
42-
public function getOffset() {
36+
public function getOffset(): int {
4337
return $this->offset;
4438
}
4539

4640
/**
4741
* @return ISearchOrder[]
4842
*/
49-
public function getOrder() {
43+
public function getOrder(): array {
5044
return $this->order;
5145
}
5246

53-
/**
54-
* @return ?IUser
55-
*/
56-
public function getUser() {
47+
public function getUser(): ?IUser {
5748
return $this->user;
5849
}
5950

lib/private/Profiler/FileProfilerStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ class FileProfilerStorage {
3030
*
3131
* Example : "file:/path/to/the/storage/folder"
3232
*
33+
* @param string $folder Folder where profiler data are stored.
3334
* @throws \RuntimeException
3435
*/
3536
public function __construct(
36-
/** @var string $folder Folder where profiler data are stored. */
3737
private string $folder,
3838
) {
3939
if (!is_dir($this->folder) && @mkdir($this->folder, 0777, true) === false && !is_dir($this->folder)) {

lib/private/Remote/Credentials.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,17 @@
99
use OCP\Remote\ICredentials;
1010

1111
class Credentials implements ICredentials {
12-
/**
13-
* @param string $user
14-
* @param string $password
15-
*/
1612
public function __construct(
17-
private $user,
18-
private $password,
13+
private string $user,
14+
private string $password,
1915
) {
2016
}
2117

22-
/**
23-
* @return string
24-
*/
25-
public function getUsername() {
18+
public function getUsername(): string {
2619
return $this->user;
2720
}
2821

29-
/**
30-
* @return string
31-
*/
32-
public function getPassword() {
22+
public function getPassword(): string {
3323
return $this->password;
3424
}
3525
}

lib/private/Repair.php

Lines changed: 41 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88
namespace OC;
99

10-
use OC\DB\ConnectionAdapter;
1110
use OC\Repair\AddBruteForceCleanupJob;
1211
use OC\Repair\AddCleanupDeletedUsersBackgroundJob;
1312
use OC\Repair\AddCleanupUpdaterBackupsJob;
@@ -57,49 +56,39 @@
5756
use OC\Repair\RepairInvalidShares;
5857
use OC\Repair\RepairLogoDimension;
5958
use OC\Repair\RepairMimeTypes;
60-
use OC\Template\JSCombiner;
6159
use OCA\DAV\Migration\DeleteSchedulingObjects;
6260
use OCA\DAV\Migration\RemoveObjectProperties;
63-
use OCP\AppFramework\QueryException;
64-
use OCP\AppFramework\Utility\ITimeFactory;
65-
use OCP\BackgroundJob\IJobList;
66-
use OCP\Collaboration\Resources\IManager;
6761
use OCP\EventDispatcher\IEventDispatcher;
68-
use OCP\Files\AppData\IAppDataFactory;
69-
use OCP\IAppConfig;
70-
use OCP\ICacheFactory;
7162
use OCP\IConfig;
7263
use OCP\IDBConnection;
73-
use OCP\IGroupManager;
74-
use OCP\IUserManager;
7564
use OCP\Migration\IOutput;
7665
use OCP\Migration\IRepairStep;
77-
use OCP\Notification\IManager as INotificationManager;
7866
use OCP\Server;
67+
use Psr\Container\ContainerExceptionInterface;
7968
use Psr\Log\LoggerInterface;
8069
use Throwable;
8170

8271
class Repair implements IOutput {
83-
/** @var IRepairStep[] */
72+
/** @var list<IRepairStep> */
8473
private array $repairSteps = [];
8574

8675
private string $currentStep;
8776

8877
public function __construct(
89-
private IEventDispatcher $dispatcher,
90-
private LoggerInterface $logger,
78+
private readonly IEventDispatcher $dispatcher,
79+
private readonly LoggerInterface $logger,
9180
) {
9281
}
9382

94-
/** @param IRepairStep[] $repairSteps */
83+
/** @param list<IRepairStep> $repairSteps */
9584
public function setRepairSteps(array $repairSteps): void {
9685
$this->repairSteps = $repairSteps;
9786
}
9887

9988
/**
10089
* Run a series of repair steps for common problems
10190
*/
102-
public function run() {
91+
public function run(): void {
10392
if (count($this->repairSteps) === 0) {
10493
$this->dispatcher->dispatchTyped(new RepairInfoEvent('No repair steps available'));
10594

@@ -123,19 +112,19 @@ public function run() {
123112
/**
124113
* Add repair step
125114
*
126-
* @param IRepairStep|string $repairStep repair step
115+
* @param IRepairStep|class-string<IRepairStep> $repairStep repair step
127116
* @throws \Exception
128117
*/
129-
public function addStep($repairStep) {
118+
public function addStep(IRepairStep|string $repairStep): void {
130119
if (is_string($repairStep)) {
131120
try {
132121
$s = Server::get($repairStep);
133-
} catch (QueryException $e) {
122+
} catch (ContainerExceptionInterface $e) {
134123
if (class_exists($repairStep)) {
135124
try {
136125
// Last resort: hope there are no constructor arguments
137126
$s = new $repairStep();
138-
} catch (Throwable $inner) {
127+
} catch (Throwable) {
139128
// Well, it was worth a try
140129
throw new \Exception("Repair step '$repairStep' can't be instantiated: " . $e->getMessage(), 0, $e);
141130
}
@@ -158,35 +147,28 @@ public function addStep($repairStep) {
158147
* Returns the default repair steps to be run on the
159148
* command line or after an upgrade.
160149
*
161-
* @return IRepairStep[]
150+
* @return list<IRepairStep>
162151
*/
163152
public static function getRepairSteps(): array {
164153
return [
165154
new Collation(Server::get(IConfig::class), Server::get(LoggerInterface::class), Server::get(IDBConnection::class), false),
166-
new CleanTags(Server::get(IDBConnection::class), Server::get(IUserManager::class)),
167-
new RepairInvalidShares(Server::get(IConfig::class), Server::get(IDBConnection::class)),
168-
new MoveUpdaterStepFile(Server::get(IConfig::class)),
169-
new MoveAvatars(
170-
Server::get(IJobList::class),
171-
Server::get(IConfig::class)
172-
),
173-
new CleanPreviews(
174-
Server::get(IJobList::class),
175-
Server::get(IUserManager::class),
176-
Server::get(IConfig::class)
177-
),
155+
Server::get(CleanTags::class),
156+
Server::get(RepairInvalidShares::class),
157+
Server::get(MoveUpdaterStepFile::class),
158+
Server::get(MoveAvatars::class),
159+
Server::get(CleanPreviews::class),
178160
Server::get(MigratePropertiesTable::class),
179161
Server::get(MigrateOauthTables::class),
180-
new UpdateLanguageCodes(Server::get(IDBConnection::class), Server::get(IConfig::class)),
181-
new AddLogRotateJob(Server::get(IJobList::class)),
182-
new ClearFrontendCaches(Server::get(ICacheFactory::class), Server::get(JSCombiner::class)),
162+
Server::get(UpdateLanguageCodes::class),
163+
Server::get(AddLogRotateJob::class),
164+
Server::get(ClearFrontendCaches::class),
183165
Server::get(ClearGeneratedAvatarCache::class),
184-
new AddPreviewBackgroundCleanupJob(Server::get(IJobList::class)),
185-
new AddCleanupUpdaterBackupsJob(Server::get(IJobList::class)),
186-
new CleanupCardDAVPhotoCache(Server::get(IConfig::class), Server::get(IAppDataFactory::class), Server::get(LoggerInterface::class)),
187-
new AddClenupLoginFlowV2BackgroundJob(Server::get(IJobList::class)),
188-
new RemoveLinkShares(Server::get(IDBConnection::class), Server::get(IConfig::class), Server::get(IGroupManager::class), Server::get(INotificationManager::class), Server::get(ITimeFactory::class)),
189-
new ClearCollectionsAccessCache(Server::get(IConfig::class), Server::get(IManager::class)),
166+
Server::get(AddPreviewBackgroundCleanupJob::class),
167+
Server::get(AddCleanupUpdaterBackupsJob::class),
168+
Server::get(CleanupCardDAVPhotoCache::class),
169+
Server::get(AddClenupLoginFlowV2BackgroundJob::class),
170+
Server::get(RemoveLinkShares::class),
171+
Server::get(ClearCollectionsAccessCache::class),
190172
Server::get(ResetGeneratedAvatarFlag::class),
191173
Server::get(EncryptionLegacyCipher::class),
192174
Server::get(EncryptionMigration::class),
@@ -213,17 +195,13 @@ public static function getRepairSteps(): array {
213195
* Returns expensive repair steps to be run on the
214196
* command line with a special option.
215197
*
216-
* @return IRepairStep[]
198+
* @return list<IRepairStep>
217199
*/
218-
public static function getExpensiveRepairSteps() {
200+
public static function getExpensiveRepairSteps(): array {
219201
return [
220-
new OldGroupMembershipShares(Server::get(IDBConnection::class), Server::get(IGroupManager::class)),
221-
new RemoveBrokenProperties(Server::get(IDBConnection::class)),
222-
new RepairMimeTypes(
223-
Server::get(IConfig::class),
224-
Server::get(IAppConfig::class),
225-
Server::get(IDBConnection::class)
226-
),
202+
Server::get(OldGroupMembershipShares::class),
203+
Server::get(RemoveBrokenProperties::class),
204+
Server::get(RepairMimeTypes::class),
227205
Server::get(DeleteSchedulingObjects::class),
228206
Server::get(RemoveObjectProperties::class),
229207
];
@@ -233,19 +211,14 @@ public static function getExpensiveRepairSteps() {
233211
* Returns the repair steps to be run before an
234212
* upgrade.
235213
*
236-
* @return IRepairStep[]
214+
* @return list<IRepairStep>
237215
*/
238-
public static function getBeforeUpgradeRepairSteps() {
239-
/** @var ConnectionAdapter $connectionAdapter */
240-
$connectionAdapter = Server::get(ConnectionAdapter::class);
241-
$config = Server::get(IConfig::class);
242-
$steps = [
243-
new Collation(Server::get(IConfig::class), Server::get(LoggerInterface::class), $connectionAdapter, true),
244-
new SaveAccountsTableData($connectionAdapter, $config),
245-
new DropAccountTermsTable($connectionAdapter),
216+
public static function getBeforeUpgradeRepairSteps(): array {
217+
return [
218+
new Collation(Server::get(IConfig::class), Server::get(LoggerInterface::class), Server::get(IDBConnection::class), true),
219+
Server::get(SaveAccountsTableData::class),
220+
Server::get(DropAccountTermsTable::class),
246221
];
247-
248-
return $steps;
249222
}
250223

251224
public function debug(string $message): void {
@@ -254,23 +227,23 @@ public function debug(string $message): void {
254227
/**
255228
* @param string $message
256229
*/
257-
public function info($message) {
230+
public function info($message): void {
258231
// for now just emit as we did in the past
259232
$this->dispatcher->dispatchTyped(new RepairInfoEvent($message));
260233
}
261234

262235
/**
263236
* @param string $message
264237
*/
265-
public function warning($message) {
238+
public function warning($message): void {
266239
// for now just emit as we did in the past
267240
$this->dispatcher->dispatchTyped(new RepairWarningEvent($message));
268241
}
269242

270243
/**
271244
* @param int $max
272245
*/
273-
public function startProgress($max = 0) {
246+
public function startProgress($max = 0): void {
274247
// for now just emit as we did in the past
275248
$this->dispatcher->dispatchTyped(new RepairStartEvent($max, $this->currentStep));
276249
}
@@ -279,15 +252,12 @@ public function startProgress($max = 0) {
279252
* @param int $step number of step to advance
280253
* @param string $description
281254
*/
282-
public function advance($step = 1, $description = '') {
255+
public function advance($step = 1, $description = ''): void {
283256
// for now just emit as we did in the past
284257
$this->dispatcher->dispatchTyped(new RepairAdvanceEvent($step, $description));
285258
}
286259

287-
/**
288-
* @param int $max
289-
*/
290-
public function finishProgress() {
260+
public function finishProgress(): void {
291261
// for now just emit as we did in the past
292262
$this->dispatcher->dispatchTyped(new RepairFinishEvent());
293263
}

0 commit comments

Comments
 (0)