3434namespace OC \Repair ;
3535
3636use OC \Migration \NullOutput ;
37+ use OCP \DB \Exception ;
38+ use OCP \DB \IResult ;
3739use OCP \DB \QueryBuilder \IQueryBuilder ;
3840use OCP \IConfig ;
3941use OCP \IDBConnection ;
@@ -45,23 +47,27 @@ class RepairMimeTypes implements IRepairStep {
4547 private int $ changeCount = 0 ;
4648
4749 /** @var int */
48- protected $ folderMimeTypeId ;
50+ protected int $ folderMimeTypeId ;
4951
5052 public function __construct (
5153 protected IConfig $ config ,
5254 protected IDBConnection $ connection
5355 ) {
5456 }
5557
56- public function getName () {
58+ public function getName (): string {
5759 return 'Repair mime types ' ;
5860 }
5961
60- private function updateMimetypes ($ updatedMimetypes ) {
62+ /**
63+ * @throws Exception
64+ */
65+ private function updateMimetypes ($ updatedMimetypes ): IResult |int |null {
6166 if ($ this ->dryRun ) {
6267 $ this ->changeCount += count ($ updatedMimetypes );
63- return ;
68+ return null ;
6469 }
70+
6571 $ query = $ this ->connection ->getQueryBuilder ();
6672 $ query ->select ('id ' )
6773 ->from ('mimetypes ' )
@@ -109,7 +115,21 @@ private function updateMimetypes($updatedMimetypes) {
109115 return $ count ;
110116 }
111117
112- private function introduceAsciidocType () {
118+ /**
119+ * @throws Exception
120+ */
121+ private function introduceExcalidrawType (): IResult |int |null {
122+ $ updatedMimetypes = [
123+ 'excalidraw ' => 'application/vnd.excalidraw+json ' ,
124+ ];
125+
126+ return $ this ->updateMimetypes ($ updatedMimetypes );
127+ }
128+
129+ /**
130+ * @throws Exception
131+ */
132+ private function introduceAsciidocType (): IResult |int |null {
113133 $ updatedMimetypes = [
114134 'adoc ' => 'text/asciidoc ' ,
115135 'asciidoc ' => 'text/asciidoc ' ,
@@ -118,7 +138,10 @@ private function introduceAsciidocType() {
118138 return $ this ->updateMimetypes ($ updatedMimetypes );
119139 }
120140
121- private function introduceImageTypes () {
141+ /**
142+ * @throws Exception
143+ */
144+ private function introduceImageTypes (): IResult |int |null {
122145 $ updatedMimetypes = [
123146 'jp2 ' => 'image/jp2 ' ,
124147 'webp ' => 'image/webp ' ,
@@ -127,7 +150,10 @@ private function introduceImageTypes() {
127150 return $ this ->updateMimetypes ($ updatedMimetypes );
128151 }
129152
130- private function introduceWindowsProgramTypes () {
153+ /**
154+ * @throws Exception
155+ */
156+ private function introduceWindowsProgramTypes (): IResult |int |null {
131157 $ updatedMimetypes = [
132158 'htaccess ' => 'text/plain ' ,
133159 'bat ' => 'application/x-msdos-program ' ,
@@ -137,7 +163,10 @@ private function introduceWindowsProgramTypes() {
137163 return $ this ->updateMimetypes ($ updatedMimetypes );
138164 }
139165
140- private function introduceLocationTypes () {
166+ /**
167+ * @throws Exception
168+ */
169+ private function introduceLocationTypes (): IResult |int |null {
141170 $ updatedMimetypes = [
142171 'gpx ' => 'application/gpx+xml ' ,
143172 'kml ' => 'application/vnd.google-earth.kml+xml ' ,
@@ -148,7 +177,10 @@ private function introduceLocationTypes() {
148177 return $ this ->updateMimetypes ($ updatedMimetypes );
149178 }
150179
151- private function introduceInternetShortcutTypes () {
180+ /**
181+ * @throws Exception
182+ */
183+ private function introduceInternetShortcutTypes (): IResult |int |null {
152184 $ updatedMimetypes = [
153185 'url ' => 'application/internet-shortcut ' ,
154186 'webloc ' => 'application/internet-shortcut '
@@ -157,7 +189,10 @@ private function introduceInternetShortcutTypes() {
157189 return $ this ->updateMimetypes ($ updatedMimetypes );
158190 }
159191
160- private function introduceStreamingTypes () {
192+ /**
193+ * @throws Exception
194+ */
195+ private function introduceStreamingTypes (): IResult |int |null {
161196 $ updatedMimetypes = [
162197 'm3u ' => 'audio/mpegurl ' ,
163198 'm3u8 ' => 'audio/mpegurl ' ,
@@ -167,7 +202,10 @@ private function introduceStreamingTypes() {
167202 return $ this ->updateMimetypes ($ updatedMimetypes );
168203 }
169204
170- private function introduceVisioTypes () {
205+ /**
206+ * @throws Exception
207+ */
208+ private function introduceVisioTypes (): IResult |int |null {
171209 $ updatedMimetypes = [
172210 'vsdm ' => 'application/vnd.visio ' ,
173211 'vsdx ' => 'application/vnd.visio ' ,
@@ -180,7 +218,10 @@ private function introduceVisioTypes() {
180218 return $ this ->updateMimetypes ($ updatedMimetypes );
181219 }
182220
183- private function introduceComicbookTypes () {
221+ /**
222+ * @throws Exception
223+ */
224+ private function introduceComicbookTypes (): IResult |int |null {
184225 $ updatedMimetypes = [
185226 'cb7 ' => 'application/comicbook+7z ' ,
186227 'cba ' => 'application/comicbook+ace ' ,
@@ -193,7 +234,10 @@ private function introduceComicbookTypes() {
193234 return $ this ->updateMimetypes ($ updatedMimetypes );
194235 }
195236
196- private function introduceOpenDocumentTemplates () {
237+ /**
238+ * @throws Exception
239+ */
240+ private function introduceOpenDocumentTemplates (): IResult |int |null {
197241 $ updatedMimetypes = [
198242 'ott ' => 'application/vnd.oasis.opendocument.text-template ' ,
199243 'ots ' => 'application/vnd.oasis.opendocument.spreadsheet-template ' ,
@@ -204,7 +248,10 @@ private function introduceOpenDocumentTemplates() {
204248 return $ this ->updateMimetypes ($ updatedMimetypes );
205249 }
206250
207- private function introduceFlatOpenDocumentType () {
251+ /**
252+ * @throws Exception
253+ */
254+ private function introduceFlatOpenDocumentType (): IResult |int |null {
208255 $ updatedMimetypes = [
209256 "fodt " => "application/vnd.oasis.opendocument.text-flat-xml " ,
210257 "fods " => "application/vnd.oasis.opendocument.spreadsheet-flat-xml " ,
@@ -215,15 +262,21 @@ private function introduceFlatOpenDocumentType() {
215262 return $ this ->updateMimetypes ($ updatedMimetypes );
216263 }
217264
218- private function introduceOrgModeType () {
265+ /**
266+ * @throws Exception
267+ */
268+ private function introduceOrgModeType (): IResult |int |null {
219269 $ updatedMimetypes = [
220270 'org ' => 'text/org '
221271 ];
222272
223273 return $ this ->updateMimetypes ($ updatedMimetypes );
224274 }
225275
226- private function introduceOnlyofficeFormType () {
276+ /**
277+ * @throws Exception
278+ */
279+ private function introduceOnlyofficeFormType (): IResult |int |null {
227280 $ updatedMimetypes = [
228281 "oform " => "application/vnd.openxmlformats-officedocument.wordprocessingml.document.oform " ,
229282 "docxf " => "application/vnd.openxmlformats-officedocument.wordprocessingml.document.docxf " ,
@@ -232,15 +285,21 @@ private function introduceOnlyofficeFormType() {
232285 return $ this ->updateMimetypes ($ updatedMimetypes );
233286 }
234287
235- private function introduceEnhancedMetafileFormatType () {
288+ /**
289+ * @throws Exception
290+ */
291+ private function introduceEnhancedMetafileFormatType (): IResult |int |null {
236292 $ updatedMimetypes = [
237293 'emf ' => 'image/emf ' ,
238294 ];
239295
240296 return $ this ->updateMimetypes ($ updatedMimetypes );
241297 }
242298
243- private function introduceEmlAndMsgFormatType () {
299+ /**
300+ * @throws Exception
301+ */
302+ private function introduceEmlAndMsgFormatType (): IResult |int |null {
244303 $ updatedMimetypes = [
245304 'eml ' => 'message/rfc822 ' ,
246305 'msg ' => 'application/vnd.ms-outlook ' ,
@@ -249,6 +308,9 @@ private function introduceEmlAndMsgFormatType() {
249308 return $ this ->updateMimetypes ($ updatedMimetypes );
250309 }
251310
311+ /**
312+ * @throws Exception
313+ */
252314 public function migrationsAvailable (): bool {
253315 $ this ->dryRun = true ;
254316 $ this ->run (new NullOutput ());
@@ -266,8 +328,10 @@ private function getMimeTypeVersion(): string {
266328
267329 /**
268330 * Fix mime types
331+ *
332+ * @throws Exception
269333 */
270- public function run (IOutput $ out ) {
334+ public function run (IOutput $ out ): void {
271335 $ serverVersion = $ this ->config ->getSystemValueString ('version ' , '0.0.0 ' );
272336 $ mimeTypeVersion = $ this ->getMimeTypeVersion ();
273337
@@ -330,6 +394,10 @@ public function run(IOutput $out) {
330394 $ out ->info ('Fixed eml and msg mime type ' );
331395 }
332396
397+ if (version_compare ($ mimeTypeVersion , '30.0.0.0 ' , '< ' ) && $ this ->introduceExcalidrawType ()) {
398+ $ out ->info ('Fixed Excalidraw mime type ' );
399+ }
400+
333401 if (!$ this ->dryRun ) {
334402 $ this ->config ->setAppValue ('files ' , 'mimetype_version ' , $ serverVersion );
335403 }
0 commit comments