Skip to content

Commit

Permalink
remove fileActions during uninstall, corrected cache cleaning during …
Browse files Browse the repository at this point in the history
…enable/disable app process.
  • Loading branch information
bigcat88 committed Dec 2, 2023
1 parent b80683e commit 5e67fda
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 9 deletions.
12 changes: 12 additions & 0 deletions lib/Db/ExFilesActionsMenuMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,16 @@ public function findByName(string $name): ExFilesActionsMenu {
);
return $this->findEntity($qb);
}

/**
* @throws Exception
*/
public function removeAllByAppId(string $appId): int {
$qb = $this->db->getQueryBuilder();
$qb->delete($this->tableName)
->where(
$qb->expr()->eq('appid', $qb->createNamedParameter($appId, IQueryBuilder::PARAM_STR))
);
return $qb->executeStatement();
}
}
6 changes: 6 additions & 0 deletions lib/Service/AppAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function __construct(
private readonly ExAppInitialStateService $initialStateService,
private readonly ExAppScriptsService $scriptsService,
private readonly ExAppStylesService $stylesService,
private readonly ExFilesActionsMenuService $filesActionsMenuService,
private readonly ISecureRandom $random,
private readonly IUserSession $userSession,
private readonly ISession $session,
Expand Down Expand Up @@ -143,6 +144,7 @@ public function unregisterExApp(string $appId): ?ExApp {
$this->exAppScopesService->removeExAppScopes($exApp);
$this->exAppUsersService->removeExAppUsers($exApp);
$this->talkBotsService->unregisterExAppTalkBots($exApp); // TODO: Think about internal Events for clean and flexible unregister ExApp callbacks
$this->filesActionsMenuService->unregisterExAppFileActions($appId);
$this->topMenuService->unregisterExAppMenuEntries($appId);
$this->initialStateService->deleteExAppInitialStates($appId);
$this->scriptsService->deleteExAppScripts($appId);
Expand Down Expand Up @@ -186,6 +188,8 @@ public function enableExApp(ExApp $exApp): bool {
$cacheKey = '/exApp_' . $exApp->getAppid();
$exApp->setEnabled(1);
$this->cache->set($cacheKey, $exApp, self::CACHE_TTL);
$this->filesActionsMenuService->resetCacheEnabled();
$this->topMenuService->resetCacheEnabled();

$exAppEnabled = $this->requestToExApp($exApp, '/enabled?enabled=1', null, 'PUT');
if ($exAppEnabled instanceof IResponse) {
Expand Down Expand Up @@ -240,6 +244,8 @@ public function disableExApp(ExApp $exApp): bool {
$cacheKey = '/exApp_' . $exApp->getAppid();
$exApp->setEnabled(0);
$this->cache->set($cacheKey, $exApp, self::CACHE_TTL);
$this->topMenuService->resetCacheEnabled();
$this->filesActionsMenuService->resetCacheEnabled();
return true;
} catch (Exception $e) {
$this->logger->error(sprintf('Error while disabling ExApp: %s', $e->getMessage()));
Expand Down
22 changes: 18 additions & 4 deletions lib/Service/ExFilesActionsMenuService.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ public function registerFileActionMenu(string $appId, array $params): ?ExFilesAc
$newFileActionMenu->setId($fileActionMenu->getId());
}
$fileActionMenu = $this->mapper->insertOrUpdate($newFileActionMenu);
$cacheKey = '/ex_files_actions_menu_' . $appId . '_' . $params['name'];
$this->cache->remove('/ex_files_actions_menus');
$this->cache->set($cacheKey, $fileActionMenu);
$this->cache->set('/ex_files_actions_menu_' . $appId . '_' . $params['name'], $fileActionMenu);
$this->resetCacheEnabled();
} catch (Exception $e) {
$this->logger->error(sprintf('Failed to register ExApp %s FileActionMenu %s. Error: %s', $appId, $params['name'], $e->getMessage()), ['exception' => $e]);
return null;
Expand All @@ -87,7 +86,7 @@ public function unregisterFileActionMenu(string $appId, string $fileActionMenuNa
}
$this->mapper->delete($fileActionMenu);
$this->cache->remove('/ex_files_actions_menu_' . $appId . '_' . $fileActionMenuName);
$this->cache->remove('/ex_files_actions_menus');
$this->resetCacheEnabled();
return $fileActionMenu;
} catch (Exception $e) {
$this->logger->error(sprintf('Failed to unregister ExApp %s FileActionMenu %s. Error: %s', $appId, $fileActionMenuName, $e->getMessage()), ['exception' => $e]);
Expand Down Expand Up @@ -206,4 +205,19 @@ public function loadFileActionIcon(string $appId, string $exFileActionName): ?ar
}
return null;
}

public function unregisterExAppFileActions(string $appId): int {
try {
$result = $this->mapper->removeAllByAppId($appId);
} catch (Exception) {
$result = -1;
}
$this->cache->clear('/ex_files_actions_menu_' . $appId);
$this->resetCacheEnabled();
return $result;
}

public function resetCacheEnabled(): void {
$this->cache->remove('/ex_files_actions_menus');
}
}
13 changes: 8 additions & 5 deletions lib/Service/TopMenuService.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ public function registerExAppMenuEntry(string $appId, string $name, string $disp
$newMenuEntry->setId($menuEntry->getId());
}
$menuEntry = $this->mapper->insertOrUpdate($newMenuEntry);
$cacheKey = '/ex_top_menu_' . $appId . '_' . $name;
$this->cache->remove('/ex_top_menus');
$this->cache->set($cacheKey, $menuEntry);
$this->cache->set('/ex_top_menu_' . $appId . '_' . $name, $menuEntry);
$this->resetCacheEnabled();
} catch (Exception $e) {
$this->logger->error(
sprintf('Failed to register ExApp %s TopMenu %s. Error: %s', $appId, $name, $e->getMessage()), ['exception' => $e]
Expand All @@ -109,7 +108,7 @@ public function unregisterExAppMenuEntry(string $appId, string $name): bool {
return false;
}
$this->cache->remove('/ex_top_menu_' . $appId . '_' . $name);
$this->cache->remove('/ex_top_menus');
$this->resetCacheEnabled();
$this->initialStateService->deleteExAppInitialStatesByTypeName($appId, 'top_menu', $name);
$this->scriptsService->deleteExAppScriptsByTypeName($appId, 'top_menu', $name);
$this->stylesService->deleteExAppStylesByTypeName($appId, 'top_menu', $name);
Expand All @@ -123,7 +122,7 @@ public function unregisterExAppMenuEntries(string $appId): int {
$result = -1;
}
$this->cache->clear('/ex_top_menu_' . $appId);
$this->cache->remove('/ex_top_menus');
$this->resetCacheEnabled();
return $result;
}

Expand Down Expand Up @@ -160,4 +159,8 @@ public function getExAppMenuEntries(): array {
return [];
}
}

public function resetCacheEnabled(): void {
$this->cache->remove('/ex_top_menus');
}
}

0 comments on commit 5e67fda

Please sign in to comment.