Skip to content

Commit

Permalink
Small bug in getRegisteredFileActions and getExAppMenuEntries (#189)
Browse files Browse the repository at this point in the history
**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._
  • Loading branch information
bigcat88 authored Dec 31, 2023
1 parent 08ecfeb commit 2ad52f0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
22 changes: 10 additions & 12 deletions lib/Service/UI/FilesActionsMenuService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}
}

Expand Down
20 changes: 12 additions & 8 deletions lib/Service/UI/TopMenuService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}
Expand Down

0 comments on commit 2ad52f0

Please sign in to comment.