From 2ad52f0684107c3421d53954614e3b3c0be94e73 Mon Sep 17 00:00:00 2001 From: Alexander Piskun <13381981+bigcat88@users.noreply.github.com> Date: Sun, 31 Dec 2023 17:08:06 +0300 Subject: [PATCH] Small bug in getRegisteredFileActions and getExAppMenuEntries (#189) **Fixed getRegisteredFileActions/getExAppMenuEntries returning wrong result on first call** _Issue was found during implementing SpeechToText Provider API, as this internal APIs has the same struct._ --- lib/Service/UI/FilesActionsMenuService.php | 22 ++++++++++------------ lib/Service/UI/TopMenuService.php | 20 ++++++++++++-------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/lib/Service/UI/FilesActionsMenuService.php b/lib/Service/UI/FilesActionsMenuService.php index 8f3d58f2..2912ef2e 100644 --- a/lib/Service/UI/FilesActionsMenuService.php +++ b/lib/Service/UI/FilesActionsMenuService.php @@ -91,23 +91,21 @@ public function unregisterFileActionMenu(string $appId, string $name): ?FilesAct /** * Get list of registered file actions (only for enabled ExApps) * - * @return FilesActionsMenu[]|null + * @return FilesActionsMenu[] */ - public function getRegisteredFileActions(): ?array { + public function getRegisteredFileActions(): array { try { $cacheKey = '/ex_ui_files_actions'; - $cached = $this->cache->get($cacheKey); - if ($cached !== null) { - return array_map(function ($cacheEntry) { - return $cacheEntry instanceof FilesActionsMenu ? $cacheEntry : new FilesActionsMenu($cacheEntry); - }, $cached); + $records = $this->cache->get($cacheKey); + if ($records === null) { + $records = $this->mapper->findAllEnabled(); + $this->cache->set($cacheKey, $records); } - - $fileActions = $this->mapper->findAllEnabled(); - $this->cache->set($cacheKey, $fileActions); - return $fileActions; + return array_map(function ($record) { + return new FilesActionsMenu($record); + }, $records); } catch (Exception) { - return null; + return []; } } diff --git a/lib/Service/UI/TopMenuService.php b/lib/Service/UI/TopMenuService.php index 19024665..f96a70a4 100644 --- a/lib/Service/UI/TopMenuService.php +++ b/lib/Service/UI/TopMenuService.php @@ -142,18 +142,22 @@ public function getExAppMenuEntry(string $appId, string $name): ?TopMenu { return $menuEntry; } + /** + * Get list of registered TopMenu entries (only for enabled ExApps) + * + * @return TopMenu[] + */ public function getExAppMenuEntries(): array { try { $cacheKey = '/ex_top_menus'; - $cached = $this->cache->get($cacheKey); - if ($cached !== null) { - return array_map(function ($cacheEntry) { - return $cacheEntry instanceof TopMenu ? $cacheEntry : new TopMenu($cacheEntry); - }, $cached); + $records = $this->cache->get($cacheKey); + if ($records === null) { + $records = $this->mapper->findAllEnabled(); + $this->cache->set($cacheKey, $records); } - $menuEntries = $this->mapper->findAllEnabled(); - $this->cache->set($cacheKey, $menuEntries); - return $menuEntries; + return array_map(function ($record) { + return new TopMenu($record); + }, $records); } catch (Exception) { return []; }