From daf2315513b479272e01fa3f3ee96f8aa022fafa Mon Sep 17 00:00:00 2001 From: Alexander Piskun <13381981+bigcat88@users.noreply.github.com> Date: Wed, 21 Feb 2024 19:10:02 +0300 Subject: [PATCH] always reset cache during ExApp unregister (#241) subj, a little more code, but more secure when "MYSQL Server has gone away" error occurs --------- Signed-off-by: Alexander Piskun --- lib/Db/ExAppMapper.php | 15 +++++++------ lib/Service/ExAppService.php | 41 ++++++++++++++++-------------------- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/lib/Db/ExAppMapper.php b/lib/Db/ExAppMapper.php index a9623f1a..7e69bdd7 100644 --- a/lib/Db/ExAppMapper.php +++ b/lib/Db/ExAppMapper.php @@ -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; + } } /** diff --git a/lib/Service/ExAppService.php b/lib/Service/ExAppService.php index c1d46895..c5a20c51 100644 --- a/lib/Service/ExAppService.php +++ b/lib/Service/ExAppService.php @@ -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 {