From 5f795a43790b1fde964dc673a1ca2ae6b434db90 Mon Sep 17 00:00:00 2001 From: ralf Date: Fri, 17 May 2024 15:59:49 +0200 Subject: [PATCH] WIP ViDoTeach REST API: fix not working unsetting in PATCH requests with null value --- api/src/CalDAV/JsBase.php | 5 +++++ api/src/MimeMagic.php | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/api/src/CalDAV/JsBase.php b/api/src/CalDAV/JsBase.php index 453f66e918..827a09c82a 100644 --- a/api/src/CalDAV/JsBase.php +++ b/api/src/CalDAV/JsBase.php @@ -370,6 +370,11 @@ class JsBase $target = $value; } } + // if we unset fields stored directly in the database, they will NOT be updated :( + elseif (!$n) + { + $target = null; + } else { unset($parent[$part]); diff --git a/api/src/MimeMagic.php b/api/src/MimeMagic.php index aaa93aafb2..9f8e0d6a56 100644 --- a/api/src/MimeMagic.php +++ b/api/src/MimeMagic.php @@ -115,6 +115,25 @@ class MimeMagic return $key; } + /** + * Convert a MIME type to all known file extensions + * + * If we cannot map the type to any file extension, we return an empty array. + * + * @param string $_type The MIME type to be mapped to a file extension. + * @return array with possible file extensions + */ + public static function mime2extensions($_type) + { + $type = strtolower($_type); + if (isset(self::$mime_alias_map[$type])) $type = self::$mime_alias_map[$type]; + + return array_keys(array_filter(self::$mime_extension_map, static function($mime) use ($type) + { + return $mime == $type; + })); + } + /** * Fix old / aliased mime-types by returning valid/default mime-type *