diff --git a/lib/private/Files/Conversion/ConversionManager.php b/lib/private/Files/Conversion/ConversionManager.php index 7c53148f0d556..446e5717e481a 100644 --- a/lib/private/Files/Conversion/ConversionManager.php +++ b/lib/private/Files/Conversion/ConversionManager.php @@ -26,8 +26,16 @@ use Throwable; class ConversionManager implements IConversionManager { - /** @var ?IConversionProvider[] */ - private ?array $providers = null; + /** @var string[] */ + private array $preferredApps = [ + 'richdocuments', + ]; + + /** @var IConversionProvider[] */ + private array $preferredProviders = []; + + /** @var IConversionProvider[] */ + private array $providers = []; public function __construct( private Coordinator $coordinator, @@ -51,7 +59,7 @@ public function getMimeTypes(): array { array_push($mimeTypes, $provider->getSupportedMimeType()); } - return array_merge([], $mimeTypes); + return $mimeTypes; } public function convert(File $file, string $targetMimeType, ?string $destination = null): string { @@ -96,17 +104,21 @@ public function convert(File $file, string $targetMimeType, ?string $destination } public function getProviders(): array { - if ($this->providers !== null) { + if (count($this->providers) > 0) { return $this->providers; } $context = $this->coordinator->getRegistrationContext(); - $this->providers = []; - foreach ($context->getFileConversionProviders() as $providerRegistration) { $class = $providerRegistration->getService(); + $appId = $providerRegistration->getAppId(); try { + if (in_array($appId, $this->preferredApps)) { + $this->preferredProviders[$class] = $this->serverContainer->get($class); + continue; + } + $this->providers[$class] = $this->serverContainer->get($class); } catch (NotFoundExceptionInterface|ContainerExceptionInterface|Throwable $e) { $this->logger->error('Failed to load file conversion provider ' . $class, [ @@ -115,7 +127,8 @@ public function getProviders(): array { } } - return $this->providers; + // return $this->providers; + return array_merge([], $this->preferredProviders, $this->providers); } private function writeToDestination(string $destination, mixed $content): File {