summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2014-08-15 14:41:53 +0200
committerLukas Reschke <lukas@owncloud.com>2014-08-15 14:41:53 +0200
commit98fc56831d4f7131a50b62b770ba265df5817ee4 (patch)
tree533f5a33016f3130f898a79b82931876ae1c9a3c
parenta6fff70a7cb591b8b011af5da0e2367d9739ff84 (diff)
parent8e11455f27d5efa6b95ccd695083697e0018e712 (diff)
downloadnextcloud-server-98fc56831d4f7131a50b62b770ba265df5817ee4.tar.gz
nextcloud-server-98fc56831d4f7131a50b62b770ba265df5817ee4.zip
Merge pull request #9275 from NormalRa/master
Add .apk mimetype.
-rw-r--r--lib/private/helper.php1
-rw-r--r--lib/private/mimetypes.list.php1
-rw-r--r--lib/repair/repairmimetypes.php42
-rw-r--r--tests/lib/repair/repairmimetypes.php27
4 files changed, 71 insertions, 0 deletions
diff --git a/lib/private/helper.php b/lib/private/helper.php
index f90c38d236c..79df2e3255c 100644
--- a/lib/private/helper.php
+++ b/lib/private/helper.php
@@ -183,6 +183,7 @@ class OC_Helper {
'application/x-gzip' => 'package/x-generic',
'application/x-rar-compressed' => 'package/x-generic',
'application/x-tar' => 'package/x-generic',
+ 'application/vnd.android.package-archive' => 'package/x-generic',
'application/zip' => 'package/x-generic',
'application/msword' => 'x-office/document',
diff --git a/lib/private/mimetypes.list.php b/lib/private/mimetypes.list.php
index 8db78361433..a44ec1daa1e 100644
--- a/lib/private/mimetypes.list.php
+++ b/lib/private/mimetypes.list.php
@@ -32,6 +32,7 @@ return array(
'7z' => array('application/x-7z-compressed', null),
'accdb' => array('application/msaccess', null),
'ai' => array('application/illustrator', null),
+ 'apk' => array('application/vnd.android.package-archive', null),
'avi' => array('video/x-msvideo', null),
'bash' => array('text/x-shellscript', null),
'blend' => array('application/x-blender', null),
diff --git a/lib/repair/repairmimetypes.php b/lib/repair/repairmimetypes.php
index f7618c6e060..e3f4402cfd5 100644
--- a/lib/repair/repairmimetypes.php
+++ b/lib/repair/repairmimetypes.php
@@ -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'));
+ }
}
}
diff --git a/tests/lib/repair/repairmimetypes.php b/tests/lib/repair/repairmimetypes.php
index 3ed19bd55bb..7754864a69e 100644
--- a/tests/lib/repair/repairmimetypes.php
+++ b/tests/lib/repair/repairmimetypes.php
@@ -109,6 +109,33 @@ class TestRepairMimeTypes extends PHPUnit_Framework_TestCase {
}
/**
+ * Test renaming the APK mime type
+ */
+ public function testRenameAPKMimeType() {
+ $this->addEntries(
+ array(
+ array('test.apk', 'application/octet-stream'),
+ array('bogus.apk', 'application/vnd.android.package-archive'),
+ array('bogus2.apk', 'application/wrong'),
+ )
+ );
+
+ $this->repair->run();
+
+ // force mimetype reload
+ DummyFileCache::clearCachedMimeTypes();
+ $this->storage->getCache()->loadMimeTypes();
+
+ $this->checkEntries(
+ array(
+ array('test.apk', 'application/vnd.android.package-archive'),
+ array('bogus.apk', 'application/vnd.android.package-archive'),
+ array('bogus2.apk', 'application/vnd.android.package-archive'),
+ )
+ );
+ }
+
+ /**
* Test renaming and splitting old office mime types when
* new ones already exist
*/