Merge pull request #9275 from NormalRa/master

Add .apk mimetype.
remotes/origin/fix-10825
Lukas Reschke 2014-08-15 14:41:53 +07:00
commit 98fc56831d
4 changed files with 71 additions and 0 deletions

@ -183,6 +183,7 @@ class OC_Helper {
'application/x-gzip' => 'package/x-generic', 'application/x-gzip' => 'package/x-generic',
'application/x-rar-compressed' => 'package/x-generic', 'application/x-rar-compressed' => 'package/x-generic',
'application/x-tar' => 'package/x-generic', 'application/x-tar' => 'package/x-generic',
'application/vnd.android.package-archive' => 'package/x-generic',
'application/zip' => 'package/x-generic', 'application/zip' => 'package/x-generic',
'application/msword' => 'x-office/document', 'application/msword' => 'x-office/document',

@ -32,6 +32,7 @@ return array(
'7z' => array('application/x-7z-compressed', null), '7z' => array('application/x-7z-compressed', null),
'accdb' => array('application/msaccess', null), 'accdb' => array('application/msaccess', null),
'ai' => array('application/illustrator', null), 'ai' => array('application/illustrator', null),
'apk' => array('application/vnd.android.package-archive', null),
'avi' => array('video/x-msvideo', null), 'avi' => array('video/x-msvideo', null),
'bash' => array('text/x-shellscript', null), 'bash' => array('text/x-shellscript', null),
'blend' => array('application/x-blender', null), 'blend' => array('application/x-blender', null),

@ -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 * Fix mime types
*/ */
@ -120,6 +158,10 @@ class RepairMimeTypes extends BasicEmitter implements \OC\RepairStep {
if ($this->fixOfficeMimeTypes()) { if ($this->fixOfficeMimeTypes()) {
$this->emit('\OC\Repair', 'info', array('Fixed office mime types')); $this->emit('\OC\Repair', 'info', array('Fixed office mime types'));
} }
if ($this->fixAPKMimeType()) {
$this->emit('\OC\Repair', 'info', array('Fixed APK mime type'));
}
} }
} }

@ -108,6 +108,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 * Test renaming and splitting old office mime types when
* new ones already exist * new ones already exist