From 0763a173321488acaadceb1eb0ecf1ec8691bf21 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Mon, 13 Jul 2020 15:43:42 +0200 Subject: Move federated_share_added into a typed event Signed-off-by: Morris Jobke --- .../lib/Events/FederatedShareAddedEvent.php | 54 ++++++++++++++++++++++ apps/federatedfilesharing/lib/Notifications.php | 20 ++++---- .../lib/OCM/CloudFederationProviderFiles.php | 4 +- 3 files changed, 67 insertions(+), 11 deletions(-) create mode 100644 apps/federatedfilesharing/lib/Events/FederatedShareAddedEvent.php (limited to 'apps/federatedfilesharing/lib') diff --git a/apps/federatedfilesharing/lib/Events/FederatedShareAddedEvent.php b/apps/federatedfilesharing/lib/Events/FederatedShareAddedEvent.php new file mode 100644 index 00000000000..f1269b9f938 --- /dev/null +++ b/apps/federatedfilesharing/lib/Events/FederatedShareAddedEvent.php @@ -0,0 +1,54 @@ + + * + * @author Morris Jobke + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\FederatedFileSharing\Events; + +use OCP\EventDispatcher\Event; + +/** + * This event is triggered when a federated share is successfully added + * + * @since 20.0.0 + */ +class FederatedShareAddedEvent extends Event { + + /** @var string */ + private $remote; + + /** + * @since 20.0.0 + */ + public function __construct(string $remote) { + $this->remote = $remote; + } + + /** + * @since 20.0.0 + */ + public function getRemote(): string { + return $this->remote; + } +} diff --git a/apps/federatedfilesharing/lib/Notifications.php b/apps/federatedfilesharing/lib/Notifications.php index 7b2105ecb0f..2dc3104e6a7 100644 --- a/apps/federatedfilesharing/lib/Notifications.php +++ b/apps/federatedfilesharing/lib/Notifications.php @@ -25,8 +25,10 @@ namespace OCA\FederatedFileSharing; +use OCA\FederatedFileSharing\Events\FederatedShareAddedEvent; use OCP\AppFramework\Http; use OCP\BackgroundJob\IJobList; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Federation\ICloudFederationFactory; use OCP\Federation\ICloudFederationProviderManager; use OCP\Http\Client\IClientService; @@ -53,21 +55,17 @@ class Notifications { /** @var ICloudFederationFactory */ private $cloudFederationFactory; - /** - * @param AddressHandler $addressHandler - * @param IClientService $httpClientService - * @param IDiscoveryService $discoveryService - * @param IJobList $jobList - * @param ICloudFederationProviderManager $federationProviderManager - * @param ICloudFederationFactory $cloudFederationFactory - */ + /** @var IEventDispatcher */ + private $eventDispatcher; + public function __construct( AddressHandler $addressHandler, IClientService $httpClientService, IDiscoveryService $discoveryService, IJobList $jobList, ICloudFederationProviderManager $federationProviderManager, - ICloudFederationFactory $cloudFederationFactory + ICloudFederationFactory $cloudFederationFactory, + IEventDispatcher $eventDispatcher ) { $this->addressHandler = $addressHandler; $this->httpClientService = $httpClientService; @@ -75,6 +73,7 @@ class Notifications { $this->jobList = $jobList; $this->federationProviderManager = $federationProviderManager; $this->cloudFederationFactory = $cloudFederationFactory; + $this->eventDispatcher = $eventDispatcher; } /** @@ -119,7 +118,8 @@ class Notifications { $ocsSuccess = $ocsStatus && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200); if ($result['success'] && (!$ocsStatus ||$ocsSuccess)) { - \OC_Hook::emit('OCP\Share', 'federated_share_added', ['server' => $remote]); + $event = new FederatedShareAddedEvent($remote); + $this->eventDispatcher->dispatchTyped($event); return true; } } diff --git a/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php b/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php index d427e324e1f..228e481655e 100644 --- a/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php +++ b/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php @@ -34,6 +34,7 @@ use OCA\Files_Sharing\Activity\Providers\RemoteShares; use OCP\Activity\IManager as IActivityManager; use OCP\App\IAppManager; use OCP\Constants; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Federation\Exceptions\ActionNotSupportedException; use OCP\Federation\Exceptions\AuthenticationFailedException; use OCP\Federation\Exceptions\BadRequestException; @@ -240,7 +241,8 @@ class CloudFederationProviderFiles implements ICloudFederationProvider { \OC::$server->getCloudFederationFactory(), \OC::$server->getGroupManager(), \OC::$server->getUserManager(), - $shareWith + $shareWith, + \OC::$server->query(IEventDispatcher::class) ); try { -- cgit v1.2.3