Merge pull request #19683 from owncloud/repair-donotrepairfoldermimetypes

Do not update mime types for folders with extension
This commit is contained in:
Thomas Müller 2015-10-12 15:08:19 +02:00
commit 64a8d01694
2 changed files with 28 additions and 2 deletions

View File

@ -35,6 +35,11 @@ class RepairMimeTypes extends BasicEmitter implements \OC\RepairStep {
*/
protected $config;
/**
* @var int
*/
protected $folderMimeTypeId;
/**
* @param \OCP\IConfig $config
*/
@ -91,7 +96,7 @@ class RepairMimeTypes extends BasicEmitter implements \OC\RepairStep {
return \OC_DB::prepare('
UPDATE `*PREFIX*filecache`
SET `mimetype` = ?
WHERE `mimetype` <> ? AND `name` ILIKE ?
WHERE `mimetype` <> ? AND `mimetype` <> ? AND `name` ILIKE ?
');
}
@ -124,6 +129,10 @@ class RepairMimeTypes extends BasicEmitter implements \OC\RepairStep {
}
private function updateMimetypes($updatedMimetypes) {
if (empty($this->folderMimeTypeId)) {
$result = \OC_DB::executeAudited(self::getIdStmt(), array('httpd/unix-directory'));
$this->folderMimeTypeId = (int)$result->fetchOne();
}
foreach ($updatedMimetypes as $extension => $mimetype) {
$result = \OC_DB::executeAudited(self::existsStmt(), array($mimetype));
@ -139,7 +148,7 @@ class RepairMimeTypes extends BasicEmitter implements \OC\RepairStep {
$mimetypeId = $result->fetchOne();
// change mimetype for files with x extension
\OC_DB::executeAudited(self::updateByNameStmt(), array($mimetypeId, $mimetypeId, '%.' . $extension));
\OC_DB::executeAudited(self::updateByNameStmt(), array($mimetypeId, $this->folderMimeTypeId, $mimetypeId, '%.' . $extension));
}
}

View File

@ -514,5 +514,22 @@ class RepairMimeTypes extends \Test\TestCase {
$this->renameMimeTypes($currentMimeTypes, $fixedMimeTypes);
}
/**
* Test that mime type renaming does not affect folders
*/
public function testDoNotChangeFolderMimeType() {
$currentMimeTypes = [
['test.conf', 'httpd/unix-directory'],
['test.cnf', 'httpd/unix-directory'],
];
$fixedMimeTypes = [
['test.conf', 'httpd/unix-directory'],
['test.cnf', 'httpd/unix-directory'],
];
$this->renameMimeTypes($currentMimeTypes, $fixedMimeTypes);
}
}