2626use Throwable ;
2727
2828class ConversionManager implements IConversionManager {
29- /** @var ?IConversionProvider[] */
30- private ?array $ providers = null ;
29+ /** @var string[] */
30+ private array $ preferredApps = [
31+ 'richdocuments ' ,
32+ ];
33+
34+ /** @var IConversionProvider[] */
35+ private array $ preferredProviders = [];
36+
37+ /** @var IConversionProvider[] */
38+ private array $ providers = [];
3139
3240 public function __construct (
3341 private Coordinator $ coordinator ,
@@ -48,10 +56,10 @@ public function getMimeTypes(): array {
4856 $ mimeTypes = [];
4957
5058 foreach ($ this ->getProviders () as $ provider ) {
51- array_push ( $ mimeTypes, $ provider ->getSupportedMimeType () );
59+ $ mimeTypes[] = $ provider ->getSupportedMimeType ();
5260 }
5361
54- return array_merge ([], $ mimeTypes) ;
62+ return $ mimeTypes ;
5563 }
5664
5765 public function convert (File $ file , string $ targetMimeType , ?string $ destination = null ): string {
@@ -61,7 +69,7 @@ public function convert(File $file, string $targetMimeType, ?string $destination
6169
6270 // Operate in mebibytes
6371 $ fileSize = $ file ->getSize () / (1024 * 1024 );
64- $ threshold = $ this ->config ->getValue ('max_conversion_filesize ' , 100 );
72+ $ threshold = $ this ->config ->getValue ('max_file_conversion_filesize ' , 100 );
6573 if ($ fileSize > $ threshold ) {
6674 throw new GenericFileException ('File is too large to convert ' );
6775 }
@@ -96,17 +104,21 @@ public function convert(File $file, string $targetMimeType, ?string $destination
96104 }
97105
98106 public function getProviders (): array {
99- if ($ this ->providers !== null ) {
107+ if (count ( $ this ->providers ) > 0 ) {
100108 return $ this ->providers ;
101109 }
102110
103111 $ context = $ this ->coordinator ->getRegistrationContext ();
104- $ this ->providers = [];
105-
106112 foreach ($ context ->getFileConversionProviders () as $ providerRegistration ) {
107113 $ class = $ providerRegistration ->getService ();
114+ $ appId = $ providerRegistration ->getAppId ();
108115
109116 try {
117+ if (in_array ($ appId , $ this ->preferredApps )) {
118+ $ this ->preferredProviders [$ class ] = $ this ->serverContainer ->get ($ class );
119+ continue ;
120+ }
121+
110122 $ this ->providers [$ class ] = $ this ->serverContainer ->get ($ class );
111123 } catch (NotFoundExceptionInterface |ContainerExceptionInterface |Throwable $ e ) {
112124 $ this ->logger ->error ('Failed to load file conversion provider ' . $ class , [
@@ -115,7 +127,7 @@ public function getProviders(): array {
115127 }
116128 }
117129
118- return $ this ->providers ;
130+ return array_merge ([], $ this ->preferredProviders , $ this -> providers ) ;
119131 }
120132
121133 private function writeToDestination (string $ destination , mixed $ content ): File {
0 commit comments