Skip to content

Commit

Permalink
feat: add removal of webhook listeners during ExApp unregister (#382)
Browse files Browse the repository at this point in the history
Resolves: #377 

Add webhooks removal during ExApp unregister only for NC30+ version.

---------

Signed-off-by: Andrey Borysenko <andrey18106x@gmail.com>
  • Loading branch information
andrey18106 committed Sep 10, 2024
1 parent 4a66978 commit f0a44bf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [3.2.0 - 2024-09-06]
## [3.2.0 - 2024-09-09]

### Added

Expand All @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- TaskProcessing: fixed bug when provider wasn't removed on unregister. #370
- OCC: ExApp unregister command now doesn't remove volume by default. #381
- WebhooksListener: added removal of the webhook listeners on ExApp unregister. #382

### Removed

Expand Down
20 changes: 20 additions & 0 deletions lib/Service/ExAppService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
use OCP\IConfig;
use OCP\IUser;
use OCP\IUserManager;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Log\LoggerInterface;
use SimpleXMLElement;

Expand Down Expand Up @@ -121,6 +123,7 @@ public function unregisterExApp(string $appId): bool {
$this->exAppArchiveFetcher->removeExAppFolder($appId);
$this->eventsListenerService->unregisterExAppEventListeners($appId);
$this->occService->unregisterExAppOccCommands($appId);
$this->unregisterExAppWebhooks($appId);
$r = $this->exAppMapper->deleteExApp($appId);
if ($r !== 1) {
$this->logger->error(sprintf('Error while unregistering %s ExApp from the database.', $appId));
Expand Down Expand Up @@ -399,4 +402,21 @@ public function removeExAppRoutes(ExApp $exApp): ?ExApp {
return null;
}
}

/**
* @psalm-suppress UndefinedClass
*/
private function unregisterExAppWebhooks(string $appId): void {
// webhook_listeners app since NC30 only
if (version_compare($this->config->getSystemValueString('version', '0.0.0'), '30.0', '<')) {
return;
}
try {
$webhookListenerMapper = \OCP\Server::get(\OCA\WebhookListeners\Db\WebhookListenerMapper::class);
$webhookListenerMapper->deleteByAppId($appId);
} catch (ContainerExceptionInterface | NotFoundExceptionInterface $e) {
} catch (Exception $e) {
$this->logger->debug(sprintf('Error while unregistering ExApp %s webhooks: %s', $appId, $e->getMessage()));
}
}
}

0 comments on commit f0a44bf

Please sign in to comment.