]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add APK mimetype repair scenario.
authorNormal Ra <normalraw@gmail.com>
Tue, 12 Aug 2014 12:07:10 +0000 (14:07 +0200)
committerNormal Ra <normalraw@gmail.com>
Tue, 12 Aug 2014 12:07:10 +0000 (14:07 +0200)
lib/repair/repairmimetypes.php

index f7618c6e06055c7c10f60f396888c76c80c7a0bb..00f5340a87837df64e2136569324899d675d5ec9 100644 (file)
@@ -113,6 +113,44 @@ class RepairMimeTypes extends BasicEmitter implements \OC\RepairStep {
                }
        }
 
+       private function fixAPKMimeType() {
+               $existsStmt = \OC_DB::prepare('
+                       SELECT count(`mimetype`)
+                       FROM   `*PREFIX*mimetypes`
+                       WHERE  `mimetype` = ?
+               ');
+
+               $insertStmt = \OC_DB::prepare('
+                       INSERT INTO `*PREFIX*mimetypes` ( `mimetype` )
+                       VALUES ( ? )
+                               ');
+
+
+               $updateByNameStmt = \OC_DB::prepare('
+                       UPDATE `*PREFIX*filecache`
+                       SET `mimetype` = (
+                               SELECT `id`
+                               FROM `*PREFIX*mimetypes`
+                               WHERE `mimetype` = ?
+                       ) WHERE `name` LIKE ?
+               ');
+
+
+               $mimeTypeExtension = 'apk';
+               $mimeTypeName = 'application/vnd.android.package-archive';
+
+               $result = \OC_DB::executeAudited($existsStmt, array($mimeTypeName));
+               $exists = $result->fetchOne();
+
+               if ( ! $exists ) {
+                       // insert mimetype
+                       \OC_DB::executeAudited($insertStmt, array($mimeTypeName));
+               }
+
+               // change mimetype for files with x extension
+               \OC_DB::executeAudited($updateByNameStmt, array($mimeTypeName, '%.'.$mimeTypeExtension));
+       }
+
        /**
         * Fix mime types
         */
@@ -120,6 +158,10 @@ class RepairMimeTypes extends BasicEmitter implements \OC\RepairStep {
                if ($this->fixOfficeMimeTypes()) {
                        $this->emit('\OC\Repair', 'info', array('Fixed office mime types'));
                }
+
+               if ($this->fixAPKMimeType()) {
+                       $this->emit('\OC\Repair', 'info', array('Fixed APK mime type'));
+               }
        }
 }