aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2024-06-18 11:27:29 +0200
committerRobin Appelman <robin@icewind.nl>2024-06-19 11:22:49 +0200
commitd3d2488fbb5ffada2fa36612da2e9e15cdb3f6b7 (patch)
tree84aae1c5bb3f55e7ccf5445fee0eaeaa59a3cf0b /lib
parent0a5983ba9aaccdfb09951e8f3c02d2c68f53e95a (diff)
downloadnextcloud-server-d3d2488fbb5ffada2fa36612da2e9e15cdb3f6b7.tar.gz
nextcloud-server-d3d2488fbb5ffada2fa36612da2e9e15cdb3f6b7.zip
feat: add setup check for needed mimetype migrations
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib')
-rw-r--r--lib/composer/composer/autoload_classmap.php1
-rw-r--r--lib/composer/composer/autoload_static.php1
-rw-r--r--lib/private/Migration/NullOutput.php35
-rw-r--r--lib/private/Repair/RepairMimeTypes.php75
4 files changed, 87 insertions, 25 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index b95db9b0d37..2cb008efda0 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -1565,6 +1565,7 @@ return array(
'OC\\MemoryInfo' => $baseDir . '/lib/private/MemoryInfo.php',
'OC\\Migration\\BackgroundRepair' => $baseDir . '/lib/private/Migration/BackgroundRepair.php',
'OC\\Migration\\ConsoleOutput' => $baseDir . '/lib/private/Migration/ConsoleOutput.php',
+ 'OC\\Migration\\NullOutput' => $baseDir . '/lib/private/Migration/NullOutput.php',
'OC\\Migration\\SimpleOutput' => $baseDir . '/lib/private/Migration/SimpleOutput.php',
'OC\\NaturalSort' => $baseDir . '/lib/private/NaturalSort.php',
'OC\\NaturalSort_DefaultCollator' => $baseDir . '/lib/private/NaturalSort_DefaultCollator.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index a96d594a64a..ea059ec21ea 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -1598,6 +1598,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\MemoryInfo' => __DIR__ . '/../../..' . '/lib/private/MemoryInfo.php',
'OC\\Migration\\BackgroundRepair' => __DIR__ . '/../../..' . '/lib/private/Migration/BackgroundRepair.php',
'OC\\Migration\\ConsoleOutput' => __DIR__ . '/../../..' . '/lib/private/Migration/ConsoleOutput.php',
+ 'OC\\Migration\\NullOutput' => __DIR__ . '/../../..' . '/lib/private/Migration/NullOutput.php',
'OC\\Migration\\SimpleOutput' => __DIR__ . '/../../..' . '/lib/private/Migration/SimpleOutput.php',
'OC\\NaturalSort' => __DIR__ . '/../../..' . '/lib/private/NaturalSort.php',
'OC\\NaturalSort_DefaultCollator' => __DIR__ . '/../../..' . '/lib/private/NaturalSort_DefaultCollator.php',
diff --git a/lib/private/Migration/NullOutput.php b/lib/private/Migration/NullOutput.php
new file mode 100644
index 00000000000..3f4cc38dba8
--- /dev/null
+++ b/lib/private/Migration/NullOutput.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+namespace OC\Migration;
+
+use OCP\Migration\IOutput;
+
+/**
+ * Class NullOutput
+ *
+ * A simple IOutput that discards all output
+ *
+ * @package OC\Migration
+ */
+class NullOutput implements IOutput {
+ public function debug(string $message): void {
+ }
+
+ public function info($message): void {
+ }
+
+ public function warning($message): void {
+ }
+
+ public function startProgress($max = 0): void {
+ }
+
+ public function advance($step = 1, $description = ''): void {
+ }
+
+ public function finishProgress(): void {
+ }
+}
diff --git a/lib/private/Repair/RepairMimeTypes.php b/lib/private/Repair/RepairMimeTypes.php
index b8254c890a7..0c2aca97c99 100644
--- a/lib/private/Repair/RepairMimeTypes.php
+++ b/lib/private/Repair/RepairMimeTypes.php
@@ -33,6 +33,7 @@
*/
namespace OC\Repair;
+use OC\Migration\NullOutput;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IConfig;
use OCP\IDBConnection;
@@ -40,18 +41,16 @@ use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
class RepairMimeTypes implements IRepairStep {
- /** @var IConfig */
- protected $config;
- /** @var IDBConnection */
- protected $connection;
+ private bool $dryRun = false;
+ private int $changeCount = 0;
/** @var int */
protected $folderMimeTypeId;
- public function __construct(IConfig $config,
- IDBConnection $connection) {
- $this->config = $config;
- $this->connection = $connection;
+ public function __construct(
+ protected IConfig $config,
+ protected IDBConnection $connection
+ ) {
}
public function getName() {
@@ -59,6 +58,10 @@ class RepairMimeTypes implements IRepairStep {
}
private function updateMimetypes($updatedMimetypes) {
+ if ($this->dryRun) {
+ $this->changeCount += count($updatedMimetypes);
+ return;
+ }
$query = $this->connection->getQueryBuilder();
$query->select('id')
->from('mimetypes')
@@ -262,77 +265,99 @@ class RepairMimeTypes implements IRepairStep {
return $this->updateMimetypes($updatedMimetypes);
}
+ public function migrationsAvailable(): bool {
+ $this->dryRun = true;
+ $this->run(new NullOutput());
+ $this->dryRun = false;
+ return $this->changeCount > 0;
+ }
+
+ private function getMimeTypeVersion(): string {
+ $serverVersion = $this->config->getSystemValueString('version', '0.0.0');
+ // 29.0.0.10 is the last version with a mimetype migration before it was moved to a separate version number
+ if (version_compare($serverVersion, '29.0.0.10', '>')) {
+ return $this->config->getAppValue('files', 'mimetype_version', '29.0.0.10');
+ } else {
+ return $serverVersion;
+ }
+ }
+
/**
* Fix mime types
*/
public function run(IOutput $out) {
- $ocVersionFromBeforeUpdate = $this->config->getSystemValueString('version', '0.0.0');
+ $serverVersion = $this->config->getSystemValueString('version', '0.0.0');
+ $mimeTypeVersion = $this->getMimeTypeVersion();
// NOTE TO DEVELOPERS: when adding new mime types, please make sure to
// add a version comparison to avoid doing it every time
- if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.14', '<') && $this->introduceImageTypes()) {
+ if (version_compare($mimeTypeVersion, '12.0.0.14', '<') && $this->introduceImageTypes()) {
$out->info('Fixed image mime types');
}
- if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.13', '<') && $this->introduceWindowsProgramTypes()) {
+ if (version_compare($mimeTypeVersion, '12.0.0.13', '<') && $this->introduceWindowsProgramTypes()) {
$out->info('Fixed windows program mime types');
}
- if (version_compare($ocVersionFromBeforeUpdate, '13.0.0.0', '<') && $this->introduceLocationTypes()) {
+ if (version_compare($mimeTypeVersion, '13.0.0.0', '<') && $this->introduceLocationTypes()) {
$out->info('Fixed geospatial mime types');
}
- if (version_compare($ocVersionFromBeforeUpdate, '13.0.0.3', '<') && $this->introduceInternetShortcutTypes()) {
+ if (version_compare($mimeTypeVersion, '13.0.0.3', '<') && $this->introduceInternetShortcutTypes()) {
$out->info('Fixed internet-shortcut mime types');
}
- if (version_compare($ocVersionFromBeforeUpdate, '13.0.0.6', '<') && $this->introduceStreamingTypes()) {
+ if (version_compare($mimeTypeVersion, '13.0.0.6', '<') && $this->introduceStreamingTypes()) {
$out->info('Fixed streaming mime types');
}
- if (version_compare($ocVersionFromBeforeUpdate, '14.0.0.8', '<') && $this->introduceVisioTypes()) {
+ if (version_compare($mimeTypeVersion, '14.0.0.8', '<') && $this->introduceVisioTypes()) {
$out->info('Fixed visio mime types');
}
- if (version_compare($ocVersionFromBeforeUpdate, '14.0.0.10', '<') && $this->introduceComicbookTypes()) {
+ if (version_compare($mimeTypeVersion, '14.0.0.10', '<') && $this->introduceComicbookTypes()) {
$out->info('Fixed comicbook mime types');
}
- if (version_compare($ocVersionFromBeforeUpdate, '20.0.0.5', '<') && $this->introduceOpenDocumentTemplates()) {
+ if (version_compare($mimeTypeVersion, '20.0.0.5', '<') && $this->introduceOpenDocumentTemplates()) {
$out->info('Fixed OpenDocument template mime types');
}
- if (version_compare($ocVersionFromBeforeUpdate, '21.0.0.7', '<') && $this->introduceOrgModeType()) {
+ if (version_compare($mimeTypeVersion, '21.0.0.7', '<') && $this->introduceOrgModeType()) {
$out->info('Fixed orgmode mime types');
}
- if (version_compare($ocVersionFromBeforeUpdate, '23.0.0.2', '<') && $this->introduceFlatOpenDocumentType()) {
+ if (version_compare($mimeTypeVersion, '23.0.0.2', '<') && $this->introduceFlatOpenDocumentType()) {
$out->info('Fixed Flat OpenDocument mime types');
}
- if (version_compare($ocVersionFromBeforeUpdate, '25.0.0.2', '<') && $this->introduceOnlyofficeFormType()) {
+ if (version_compare($mimeTypeVersion, '25.0.0.2', '<') && $this->introduceOnlyofficeFormType()) {
$out->info('Fixed ONLYOFFICE Forms OpenXML mime types');
}
- if (version_compare($ocVersionFromBeforeUpdate, '26.0.0.1', '<') && $this->introduceAsciidocType()) {
+ if (version_compare($mimeTypeVersion, '26.0.0.1', '<') && $this->introduceAsciidocType()) {
$out->info('Fixed AsciiDoc mime types');
}
- if (version_compare($ocVersionFromBeforeUpdate, '28.0.0.5', '<') && $this->introduceEnhancedMetafileFormatType()) {
+ if (version_compare($mimeTypeVersion, '28.0.0.5', '<') && $this->introduceEnhancedMetafileFormatType()) {
$out->info('Fixed Enhanced Metafile Format mime types');
}
- if (version_compare($ocVersionFromBeforeUpdate, '29.0.0.2', '<') && $this->introduceEmlAndMsgFormatType()) {
+ if (version_compare($mimeTypeVersion, '29.0.0.2', '<') && $this->introduceEmlAndMsgFormatType()) {
$out->info('Fixed eml and msg mime type');
}
- if (version_compare($ocVersionFromBeforeUpdate, '29.0.0.6', '<') && $this->introduceAacAudioType()) {
+ if (version_compare($mimeTypeVersion, '29.0.0.6', '<') && $this->introduceAacAudioType()) {
$out->info('Fixed aac mime type');
}
- if (version_compare($ocVersionFromBeforeUpdate, '29.0.0.10', '<') && $this->introduceReStructuredTextFormatType()) {
+ if (version_compare($mimeTypeVersion, '29.0.0.10', '<') && $this->introduceReStructuredTextFormatType()) {
$out->info('Fixed ReStructured Text mime type');
}
+
+ if (!$this->dryRun) {
+ $this->config->setAppValue('files', 'mimetype_version', $serverVersion);
+ }
}
}