From 032ffc969eeed452091646e35c31003297186b41 Mon Sep 17 00:00:00 2001
From: Roeland Jago Douma <roeland@famdouma.nl>
Date: Wed, 8 Jul 2015 19:09:10 +0200
Subject: [PATCH] Move mimetypealiases.json to mimetypealiases.dist.json

---
 ...{mimetypealiases.json => mimetypealiases.dist.json} | 10 +++++++---
 core/command/maintenance/mimetypesjs.php               |  7 ++++++-
 lib/private/helper.php                                 |  7 ++++++-
 3 files changed, 19 insertions(+), 5 deletions(-)
 rename config/{mimetypealiases.json => mimetypealiases.dist.json} (89%)

diff --git a/config/mimetypealiases.json b/config/mimetypealiases.dist.json
similarity index 89%
rename from config/mimetypealiases.json
rename to config/mimetypealiases.dist.json
index f1b13b67ee6..2c9bdaa00c8 100644
--- a/config/mimetypealiases.json
+++ b/config/mimetypealiases.dist.json
@@ -1,7 +1,11 @@
 {
-	"_comment" : "When this file is changed make sure to run",
-	"_comment2": "./occ maintenance:mimetypesjs",
-	"_comment3": "Otherwise your update won't propagate through the system",
+	"_comment" : "Array of mimetype aliases.",
+	"_comment2": "Any changes you make here will be overwritten on an update of ownCloud.",
+	"_comment3": "Put any custom aliases in a new file mimetypealiases.json in this directory",
+
+	"_comment4": "After any change to mimetypealiases.json run:",
+	"_comment5": "./occ maintenance:mimetypesjs",
+	"_comment6": "Otherwise your update won't propagate through the system.",
 
 
 	"application/coreldraw": "image",
diff --git a/core/command/maintenance/mimetypesjs.php b/core/command/maintenance/mimetypesjs.php
index 95a4bcd891a..8b01f0acf79 100644
--- a/core/command/maintenance/mimetypesjs.php
+++ b/core/command/maintenance/mimetypesjs.php
@@ -33,7 +33,12 @@ class MimeTypesJS extends Command {
 
 	protected function execute(InputInterface $input, OutputInterface $output) {
 		// Fetch all the aliases
-		$aliases = json_decode(file_get_contents(dirname(__DIR__) . '/../../config/mimetypealiases.json'), true);
+		$aliases = json_decode(file_get_contents(\OC::$SERVERROOT . '/config/mimetypealiases.dist.json'), true);
+
+		if (file_exists(\OC::$SERVERROOT . '/config/mimetypealiases.json')) {
+			$custom = get_object_vars(json_decode(file_get_contents(\OC::$SERVERROOT . '/config/mimetypealiases.json')));
+			$aliases = array_merge($aliases, $custom);
+		}
 
 		// Remove comments
 		$keys = array_filter(array_keys($aliases), function($k) {
diff --git a/lib/private/helper.php b/lib/private/helper.php
index a40b9a23202..825166b58a1 100644
--- a/lib/private/helper.php
+++ b/lib/private/helper.php
@@ -188,8 +188,13 @@ class OC_Helper {
 
 		// On first access load the list of mimetype aliases
 		if (empty(self::$mimeTypeAlias)) {
-			$file = file_get_contents(OC::$SERVERROOT . '/config/mimetypealiases.json');
+			$file = file_get_contents(OC::$SERVERROOT . '/config/mimetypealiases.dist.json');
 			self::$mimeTypeAlias = get_object_vars(json_decode($file));
+
+			if (file_exists(\OC::$SERVERROOT . '/config/mimetypealiases.json')) {
+				$custom = get_object_vars(json_decode(file_get_contents(\OC::$SERVERROOT . '/config/mimetypealiases.json')));
+				self::$mimeTypeAlias = array_merge(self::$mimeTypeAlias, $custom);
+			}
 		}
 
 		if (isset(self::$mimeTypeAlias[$mimetype])) {
-- 
GitLab