Skip to content

Commit 91ecdc7

Browse files
Merge pull request #45966 from nextcloud/backport/45930/stable29
[stable29] fix: move repair mimetype repair step to the expensive steps
2 parents 96c622f + 523346e commit 91ecdc7

11 files changed

Lines changed: 142 additions & 28 deletions

File tree

apps/settings/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
'OCA\\Settings\\SetupChecks\\LegacySSEKeyFormat' => $baseDir . '/../lib/SetupChecks/LegacySSEKeyFormat.php',
103103
'OCA\\Settings\\SetupChecks\\MaintenanceWindowStart' => $baseDir . '/../lib/SetupChecks/MaintenanceWindowStart.php',
104104
'OCA\\Settings\\SetupChecks\\MemcacheConfigured' => $baseDir . '/../lib/SetupChecks/MemcacheConfigured.php',
105+
'OCA\\Settings\\SetupChecks\\MimeTypeMigrationAvailable' => $baseDir . '/../lib/SetupChecks/MimeTypeMigrationAvailable.php',
105106
'OCA\\Settings\\SetupChecks\\MysqlUnicodeSupport' => $baseDir . '/../lib/SetupChecks/MysqlUnicodeSupport.php',
106107
'OCA\\Settings\\SetupChecks\\OcxProviders' => $baseDir . '/../lib/SetupChecks/OcxProviders.php',
107108
'OCA\\Settings\\SetupChecks\\OverwriteCliUrl' => $baseDir . '/../lib/SetupChecks/OverwriteCliUrl.php',

apps/settings/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ class ComposerStaticInitSettings
117117
'OCA\\Settings\\SetupChecks\\LegacySSEKeyFormat' => __DIR__ . '/..' . '/../lib/SetupChecks/LegacySSEKeyFormat.php',
118118
'OCA\\Settings\\SetupChecks\\MaintenanceWindowStart' => __DIR__ . '/..' . '/../lib/SetupChecks/MaintenanceWindowStart.php',
119119
'OCA\\Settings\\SetupChecks\\MemcacheConfigured' => __DIR__ . '/..' . '/../lib/SetupChecks/MemcacheConfigured.php',
120+
'OCA\\Settings\\SetupChecks\\MimeTypeMigrationAvailable' => __DIR__ . '/..' . '/../lib/SetupChecks/MimeTypeMigrationAvailable.php',
120121
'OCA\\Settings\\SetupChecks\\MysqlUnicodeSupport' => __DIR__ . '/..' . '/../lib/SetupChecks/MysqlUnicodeSupport.php',
121122
'OCA\\Settings\\SetupChecks\\OcxProviders' => __DIR__ . '/..' . '/../lib/SetupChecks/OcxProviders.php',
122123
'OCA\\Settings\\SetupChecks\\OverwriteCliUrl' => __DIR__ . '/..' . '/../lib/SetupChecks/OverwriteCliUrl.php',

apps/settings/lib/AppInfo/Application.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
use OCA\Settings\SetupChecks\LegacySSEKeyFormat;
7272
use OCA\Settings\SetupChecks\MaintenanceWindowStart;
7373
use OCA\Settings\SetupChecks\MemcacheConfigured;
74+
use OCA\Settings\SetupChecks\MimeTypeMigrationAvailable;
7475
use OCA\Settings\SetupChecks\MysqlUnicodeSupport;
7576
use OCA\Settings\SetupChecks\OcxProviders;
7677
use OCA\Settings\SetupChecks\OverwriteCliUrl;
@@ -202,6 +203,7 @@ public function register(IRegistrationContext $context): void {
202203
$context->registerSetupCheck(LegacySSEKeyFormat::class);
203204
$context->registerSetupCheck(MaintenanceWindowStart::class);
204205
$context->registerSetupCheck(MemcacheConfigured::class);
206+
$context->registerSetupCheck(MimeTypeMigrationAvailable::class);
205207
$context->registerSetupCheck(MysqlUnicodeSupport::class);
206208
$context->registerSetupCheck(OcxProviders::class);
207209
$context->registerSetupCheck(OverwriteCliUrl::class);
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
namespace OCA\Settings\SetupChecks;
10+
11+
use OC\Repair\RepairMimeTypes;
12+
use OCP\IL10N;
13+
use OCP\L10N\IFactory;
14+
use OCP\SetupCheck\ISetupCheck;
15+
use OCP\SetupCheck\SetupResult;
16+
17+
class MimeTypeMigrationAvailable implements ISetupCheck {
18+
private IL10N $l10n;
19+
20+
public function __construct(
21+
IFactory $l10nFactory,
22+
private RepairMimeTypes $repairMimeTypes,
23+
) {
24+
$this->l10n = $l10nFactory->get('core');
25+
}
26+
27+
public function getCategory(): string {
28+
return 'system';
29+
}
30+
31+
public function getName(): string {
32+
return $this->l10n->t('Mimetype migrations available');
33+
}
34+
35+
public function run(): SetupResult {
36+
if ($this->repairMimeTypes->migrationsAvailable()) {
37+
return SetupResult::warning(
38+
$this->l10n->t('One or more mimetype migrations are available. Occasionally new mimetypes are added to better handle certain file types. Migrating the mimetypes take a long time on larger instances so this is not done automatically during upgrades. Use the command `occ maintenance:repair --include-expensive` to perform the migrations.'),
39+
);
40+
} else {
41+
return SetupResult::success('None');
42+
}
43+
}
44+
}

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,6 +1565,7 @@
15651565
'OC\\MemoryInfo' => $baseDir . '/lib/private/MemoryInfo.php',
15661566
'OC\\Migration\\BackgroundRepair' => $baseDir . '/lib/private/Migration/BackgroundRepair.php',
15671567
'OC\\Migration\\ConsoleOutput' => $baseDir . '/lib/private/Migration/ConsoleOutput.php',
1568+
'OC\\Migration\\NullOutput' => $baseDir . '/lib/private/Migration/NullOutput.php',
15681569
'OC\\Migration\\SimpleOutput' => $baseDir . '/lib/private/Migration/SimpleOutput.php',
15691570
'OC\\NaturalSort' => $baseDir . '/lib/private/NaturalSort.php',
15701571
'OC\\NaturalSort_DefaultCollator' => $baseDir . '/lib/private/NaturalSort_DefaultCollator.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,6 +1598,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
15981598
'OC\\MemoryInfo' => __DIR__ . '/../../..' . '/lib/private/MemoryInfo.php',
15991599
'OC\\Migration\\BackgroundRepair' => __DIR__ . '/../../..' . '/lib/private/Migration/BackgroundRepair.php',
16001600
'OC\\Migration\\ConsoleOutput' => __DIR__ . '/../../..' . '/lib/private/Migration/ConsoleOutput.php',
1601+
'OC\\Migration\\NullOutput' => __DIR__ . '/../../..' . '/lib/private/Migration/NullOutput.php',
16011602
'OC\\Migration\\SimpleOutput' => __DIR__ . '/../../..' . '/lib/private/Migration/SimpleOutput.php',
16021603
'OC\\NaturalSort' => __DIR__ . '/../../..' . '/lib/private/NaturalSort.php',
16031604
'OC\\NaturalSort_DefaultCollator' => __DIR__ . '/../../..' . '/lib/private/NaturalSort_DefaultCollator.php',
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
4+
* SPDX-License-Identifier: AGPL-3.0-only
5+
*/
6+
namespace OC\Migration;
7+
8+
use OCP\Migration\IOutput;
9+
10+
/**
11+
* Class NullOutput
12+
*
13+
* A simple IOutput that discards all output
14+
*
15+
* @package OC\Migration
16+
*/
17+
class NullOutput implements IOutput {
18+
public function debug(string $message): void {
19+
}
20+
21+
public function info($message): void {
22+
}
23+
24+
public function warning($message): void {
25+
}
26+
27+
public function startProgress($max = 0): void {
28+
}
29+
30+
public function advance($step = 1, $description = ''): void {
31+
}
32+
33+
public function finishProgress(): void {
34+
}
35+
}

lib/private/Repair.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ public function addStep($repairStep) {
173173
public static function getRepairSteps(): array {
174174
return [
175175
new Collation(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class), \OC::$server->getDatabaseConnection(), false),
176-
new RepairMimeTypes(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()),
177176
new CleanTags(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager()),
178177
new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()),
179178
new MoveUpdaterStepFile(\OC::$server->getConfig()),
@@ -224,6 +223,7 @@ public static function getRepairSteps(): array {
224223
public static function getExpensiveRepairSteps() {
225224
return [
226225
new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager()),
226+
new RepairMimeTypes(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()),
227227
\OC::$server->get(ValidatePhoneNumber::class),
228228
\OC::$server->get(DeleteSchedulingObjects::class),
229229
];

lib/private/Repair/RepairMimeTypes.php

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,32 +33,35 @@
3333
*/
3434
namespace OC\Repair;
3535

36+
use OC\Migration\NullOutput;
3637
use OCP\DB\QueryBuilder\IQueryBuilder;
3738
use OCP\IConfig;
3839
use OCP\IDBConnection;
3940
use OCP\Migration\IOutput;
4041
use OCP\Migration\IRepairStep;
4142

4243
class RepairMimeTypes implements IRepairStep {
43-
/** @var IConfig */
44-
protected $config;
45-
/** @var IDBConnection */
46-
protected $connection;
44+
private bool $dryRun = false;
45+
private int $changeCount = 0;
4746

4847
/** @var int */
4948
protected $folderMimeTypeId;
5049

51-
public function __construct(IConfig $config,
52-
IDBConnection $connection) {
53-
$this->config = $config;
54-
$this->connection = $connection;
50+
public function __construct(
51+
protected IConfig $config,
52+
protected IDBConnection $connection
53+
) {
5554
}
5655

5756
public function getName() {
5857
return 'Repair mime types';
5958
}
6059

6160
private function updateMimetypes($updatedMimetypes) {
61+
if ($this->dryRun) {
62+
$this->changeCount += count($updatedMimetypes);
63+
return;
64+
}
6265
$query = $this->connection->getQueryBuilder();
6366
$query->select('id')
6467
->from('mimetypes')
@@ -262,77 +265,97 @@ private function introduceReStructuredTextFormatType() {
262265
return $this->updateMimetypes($updatedMimetypes);
263266
}
264267

268+
public function migrationsAvailable(): bool {
269+
$this->dryRun = true;
270+
$this->run(new NullOutput());
271+
$this->dryRun = false;
272+
return $this->changeCount > 0;
273+
}
274+
275+
private function getMimeTypeVersion(): string {
276+
$mimeVersion = $this->config->getAppValue('files', 'mimetype_version', '');
277+
if ($mimeVersion) {
278+
return $mimeVersion;
279+
}
280+
return $this->config->getSystemValueString('version', '0.0.0');
281+
}
282+
265283
/**
266284
* Fix mime types
267285
*/
268286
public function run(IOutput $out) {
269-
$ocVersionFromBeforeUpdate = $this->config->getSystemValueString('version', '0.0.0');
287+
$serverVersion = $this->config->getSystemValueString('version', '0.0.0');
288+
$mimeTypeVersion = $this->getMimeTypeVersion();
270289

271290
// NOTE TO DEVELOPERS: when adding new mime types, please make sure to
272291
// add a version comparison to avoid doing it every time
273292

274-
if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.14', '<') && $this->introduceImageTypes()) {
293+
if (version_compare($mimeTypeVersion, '12.0.0.14', '<') && $this->introduceImageTypes()) {
275294
$out->info('Fixed image mime types');
276295
}
277296

278-
if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.13', '<') && $this->introduceWindowsProgramTypes()) {
297+
if (version_compare($mimeTypeVersion, '12.0.0.13', '<') && $this->introduceWindowsProgramTypes()) {
279298
$out->info('Fixed windows program mime types');
280299
}
281300

282-
if (version_compare($ocVersionFromBeforeUpdate, '13.0.0.0', '<') && $this->introduceLocationTypes()) {
301+
if (version_compare($mimeTypeVersion, '13.0.0.0', '<') && $this->introduceLocationTypes()) {
283302
$out->info('Fixed geospatial mime types');
284303
}
285304

286-
if (version_compare($ocVersionFromBeforeUpdate, '13.0.0.3', '<') && $this->introduceInternetShortcutTypes()) {
305+
if (version_compare($mimeTypeVersion, '13.0.0.3', '<') && $this->introduceInternetShortcutTypes()) {
287306
$out->info('Fixed internet-shortcut mime types');
288307
}
289308

290-
if (version_compare($ocVersionFromBeforeUpdate, '13.0.0.6', '<') && $this->introduceStreamingTypes()) {
309+
if (version_compare($mimeTypeVersion, '13.0.0.6', '<') && $this->introduceStreamingTypes()) {
291310
$out->info('Fixed streaming mime types');
292311
}
293312

294-
if (version_compare($ocVersionFromBeforeUpdate, '14.0.0.8', '<') && $this->introduceVisioTypes()) {
313+
if (version_compare($mimeTypeVersion, '14.0.0.8', '<') && $this->introduceVisioTypes()) {
295314
$out->info('Fixed visio mime types');
296315
}
297316

298-
if (version_compare($ocVersionFromBeforeUpdate, '14.0.0.10', '<') && $this->introduceComicbookTypes()) {
317+
if (version_compare($mimeTypeVersion, '14.0.0.10', '<') && $this->introduceComicbookTypes()) {
299318
$out->info('Fixed comicbook mime types');
300319
}
301320

302-
if (version_compare($ocVersionFromBeforeUpdate, '20.0.0.5', '<') && $this->introduceOpenDocumentTemplates()) {
321+
if (version_compare($mimeTypeVersion, '20.0.0.5', '<') && $this->introduceOpenDocumentTemplates()) {
303322
$out->info('Fixed OpenDocument template mime types');
304323
}
305324

306-
if (version_compare($ocVersionFromBeforeUpdate, '21.0.0.7', '<') && $this->introduceOrgModeType()) {
325+
if (version_compare($mimeTypeVersion, '21.0.0.7', '<') && $this->introduceOrgModeType()) {
307326
$out->info('Fixed orgmode mime types');
308327
}
309328

310-
if (version_compare($ocVersionFromBeforeUpdate, '23.0.0.2', '<') && $this->introduceFlatOpenDocumentType()) {
329+
if (version_compare($mimeTypeVersion, '23.0.0.2', '<') && $this->introduceFlatOpenDocumentType()) {
311330
$out->info('Fixed Flat OpenDocument mime types');
312331
}
313332

314-
if (version_compare($ocVersionFromBeforeUpdate, '25.0.0.2', '<') && $this->introduceOnlyofficeFormType()) {
333+
if (version_compare($mimeTypeVersion, '25.0.0.2', '<') && $this->introduceOnlyofficeFormType()) {
315334
$out->info('Fixed ONLYOFFICE Forms OpenXML mime types');
316335
}
317336

318-
if (version_compare($ocVersionFromBeforeUpdate, '26.0.0.1', '<') && $this->introduceAsciidocType()) {
337+
if (version_compare($mimeTypeVersion, '26.0.0.1', '<') && $this->introduceAsciidocType()) {
319338
$out->info('Fixed AsciiDoc mime types');
320339
}
321340

322-
if (version_compare($ocVersionFromBeforeUpdate, '28.0.0.5', '<') && $this->introduceEnhancedMetafileFormatType()) {
341+
if (version_compare($mimeTypeVersion, '28.0.0.5', '<') && $this->introduceEnhancedMetafileFormatType()) {
323342
$out->info('Fixed Enhanced Metafile Format mime types');
324343
}
325344

326-
if (version_compare($ocVersionFromBeforeUpdate, '29.0.0.2', '<') && $this->introduceEmlAndMsgFormatType()) {
345+
if (version_compare($mimeTypeVersion, '29.0.0.2', '<') && $this->introduceEmlAndMsgFormatType()) {
327346
$out->info('Fixed eml and msg mime type');
328347
}
329348

330-
if (version_compare($ocVersionFromBeforeUpdate, '29.0.0.6', '<') && $this->introduceAacAudioType()) {
349+
if (version_compare($mimeTypeVersion, '29.0.0.6', '<') && $this->introduceAacAudioType()) {
331350
$out->info('Fixed aac mime type');
332351
}
333352

334-
if (version_compare($ocVersionFromBeforeUpdate, '29.0.0.10', '<') && $this->introduceReStructuredTextFormatType()) {
353+
if (version_compare($mimeTypeVersion, '29.0.0.10', '<') && $this->introduceReStructuredTextFormatType()) {
335354
$out->info('Fixed ReStructured Text mime type');
336355
}
356+
357+
if (!$this->dryRun) {
358+
$this->config->setAppValue('files', 'mimetype_version', $serverVersion);
359+
}
337360
}
338361
}

lib/private/Updater.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ public function upgrade(): bool {
122122
$installedVersion = $this->config->getSystemValueString('version', '0.0.0');
123123
$currentVersion = implode('.', \OCP\Util::getVersion());
124124

125+
if ($this->config->getAppValue('files', 'mimetype_version', '') === '') {
126+
$this->config->setAppValue('files', 'mimetype_version', $installedVersion);
127+
}
128+
125129
$this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, ['app' => 'core']);
126130

127131
$success = true;

0 commit comments

Comments
 (0)