From b29a0f263f64e41a43853600c7aec717af4f64e6 Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Wed, 3 Jun 2015 15:12:53 -0300 Subject: [PATCH 1/3] Don't flip. --- includes/mimetype.utils.inc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/includes/mimetype.utils.inc b/includes/mimetype.utils.inc index 03708f99..deb7f13b 100644 --- a/includes/mimetype.utils.inc +++ b/includes/mimetype.utils.inc @@ -22,8 +22,7 @@ function islandora_get_extension_for_mimetype($mimetype) { $mimetype_mapping = file_mimetype_mapping(); $extension_index = array_search($mimetype, $mimetype_mapping['mimetypes']); if ($extension_index !== FALSE) { - $mime_array_flipped = array_reverse($mimetype_mapping['extensions']); - $extension = array_search($extension_index, $mime_array_flipped); + $extension = array_search($extension_index, $mimetype_mapping['extensions']); } // We can only have one mapping in drupal for 'xml'. From c52034cccf2e39ab40cc9651e26c176c1fb26fee Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Wed, 3 Jun 2015 15:37:21 -0300 Subject: [PATCH 2/3] Still flip, but comment and handle the XML case. --- includes/mimetype.utils.inc | 6 +++++- islandora.module | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/includes/mimetype.utils.inc b/includes/mimetype.utils.inc index deb7f13b..62c1824e 100644 --- a/includes/mimetype.utils.inc +++ b/includes/mimetype.utils.inc @@ -22,7 +22,11 @@ function islandora_get_extension_for_mimetype($mimetype) { $mimetype_mapping = file_mimetype_mapping(); $extension_index = array_search($mimetype, $mimetype_mapping['mimetypes']); if ($extension_index !== FALSE) { - $extension = array_search($extension_index, $mimetype_mapping['extensions']); + // Reversing such that any altered values take precedence over the default + // mappings. As such we need to handle the case of application/xml mapping + // to .xml. + $mime_array_flipped = array_reverse($mimetype_mapping['extensions']); + $extension = array_search($extension_index, $mime_array_flipped); } // We can only have one mapping in drupal for 'xml'. diff --git a/islandora.module b/islandora.module index 2dec1fd9..10d6060f 100644 --- a/islandora.module +++ b/islandora.module @@ -1662,6 +1662,12 @@ function islandora_file_mimetype_mapping_alter(&$mapping) { end($mapping['mimetypes']); $mapping['extensions'][$ext] = key($mapping['mimetypes']); } + // Get the current XML mapping and unset it so it comes last when we do our + // reverse when getting mimetypes from extensions for use in downloads. + // @see islandora_get_extension_for_mimetype. + $xml_int = $mapping['extensions']['xml']; + unset($mapping['extensions']['xml']); + $mapping['extensions']['xml'] = $xml_int; } /** From 7b30f89c0feacefbbdf279fe34ea46b943ce5bde Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Wed, 3 Jun 2015 15:40:34 -0300 Subject: [PATCH 3/3] Minus superfluous sentence. --- includes/mimetype.utils.inc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/includes/mimetype.utils.inc b/includes/mimetype.utils.inc index 62c1824e..81866fc8 100644 --- a/includes/mimetype.utils.inc +++ b/includes/mimetype.utils.inc @@ -23,8 +23,7 @@ function islandora_get_extension_for_mimetype($mimetype) { $extension_index = array_search($mimetype, $mimetype_mapping['mimetypes']); if ($extension_index !== FALSE) { // Reversing such that any altered values take precedence over the default - // mappings. As such we need to handle the case of application/xml mapping - // to .xml. + // mappings. $mime_array_flipped = array_reverse($mimetype_mapping['extensions']); $extension = array_search($extension_index, $mime_array_flipped); }