Skip to content

Commit

Permalink
always reset cache during ExApp unregister (#241)
Browse files Browse the repository at this point in the history
subj, a little more code, but more secure when "MYSQL Server has gone
away" error occurs

---------

Signed-off-by: Alexander Piskun <[email protected]>
  • Loading branch information
bigcat88 authored Feb 21, 2024
1 parent 4e44e4a commit daf2315
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 30 deletions.
15 changes: 8 additions & 7 deletions lib/Db/ExAppMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,16 @@ public function getUsedPorts(): array {
return $ports;
}

/**
* @throws Exception
*/
public function deleteExApp(string $appId): int {
$qb = $this->db->getQueryBuilder();
return $qb->delete($this->tableName)
->where(
$qb->expr()->eq('appid', $qb->createNamedParameter($appId, IQueryBuilder::PARAM_STR))
)->executeStatement();
try {
return $qb->delete($this->tableName)
->where(
$qb->expr()->eq('appid', $qb->createNamedParameter($appId, IQueryBuilder::PARAM_STR))
)->executeStatement();
} catch (Exception) {
return 0;
}
}

/**
Expand Down
41 changes: 18 additions & 23 deletions lib/Service/ExAppService.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,30 +105,25 @@ public function unregisterExApp(string $appId): bool {
if ($exApp === null) {
return false;
}
try {
// TODO: Do we need to remove app_config_ex, app_preferences_ex too
$this->exAppScopesService->removeExAppScopes($appId);
$this->exAppUsersService->removeExAppUsers($appId);
$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);
$this->stylesService->deleteExAppStyles($appId);
$this->speechToTextService->unregisterExAppSpeechToTextProviders($appId);
$this->textProcessingService->unregisterExAppTextProcessingProviders($appId);
$this->translationService->unregisterExAppTranslationProviders($appId);
$this->settingsService->unregisterExAppForms($appId);
$this->exAppArchiveFetcher->removeExAppFolder($appId);
if ($this->exAppMapper->deleteExApp($appId) === 1) {
$this->cache->remove('/exApp_' . $appId);
return true;
}
$this->logger->warning(sprintf('Error while unregistering %s ExApp from the database.', $appId));
} catch (Exception $e) {
$this->logger->error(sprintf('Error while unregistering ExApp: %s', $e->getMessage()), ['exception' => $e]);
$this->exAppScopesService->removeExAppScopes($appId);
$this->exAppUsersService->removeExAppUsers($appId);
$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);
$this->stylesService->deleteExAppStyles($appId);
$this->speechToTextService->unregisterExAppSpeechToTextProviders($appId);
$this->textProcessingService->unregisterExAppTextProcessingProviders($appId);
$this->translationService->unregisterExAppTranslationProviders($appId);
$this->settingsService->unregisterExAppForms($appId);
$this->exAppArchiveFetcher->removeExAppFolder($appId);
$r = $this->exAppMapper->deleteExApp($appId);
if ($r !== 1) {
$this->logger->error(sprintf('Error while unregistering %s ExApp from the database.', $appId));
}
return false;
$this->cache->remove('/exApp_' . $appId);
return $r === 1;
}

public function getExAppFreePort(): int {
Expand Down

0 comments on commit daf2315

Please sign in to comment.