From 449011dae7ea0ec7eb8d6c78e89709982020e709 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 10 Mar 2017 15:37:21 +0100 Subject: remove discovery manager in favour of the OCSDiscoveryService Signed-off-by: Bjoern Schiessle --- apps/files_sharing/lib/AppInfo/Application.php | 6 +---- apps/files_sharing/lib/External/Manager.php | 35 ++++++++++++++++---------- apps/files_sharing/lib/External/Storage.php | 16 ++++++------ apps/files_sharing/lib/Hooks.php | 6 +---- 4 files changed, 31 insertions(+), 32 deletions(-) (limited to 'apps/files_sharing/lib') diff --git a/apps/files_sharing/lib/AppInfo/Application.php b/apps/files_sharing/lib/AppInfo/Application.php index f9540df3ff2..d4e83ce5d6b 100644 --- a/apps/files_sharing/lib/AppInfo/Application.php +++ b/apps/files_sharing/lib/AppInfo/Application.php @@ -92,17 +92,13 @@ class Application extends App { $container->registerService('ExternalManager', function (SimpleContainer $c) use ($server) { $user = $server->getUserSession()->getUser(); $uid = $user ? $user->getUID() : null; - $discoveryManager = new DiscoveryManager( - \OC::$server->getMemCacheFactory(), - \OC::$server->getHTTPClientService() - ); return new \OCA\Files_Sharing\External\Manager( $server->getDatabaseConnection(), \OC\Files\Filesystem::getMountManager(), \OC\Files\Filesystem::getLoader(), $server->getHTTPClientService(), $server->getNotificationManager(), - $discoveryManager, + $server->getOCSDiscoveryService(), $uid ); }); diff --git a/apps/files_sharing/lib/External/Manager.php b/apps/files_sharing/lib/External/Manager.php index 0a57324c32f..2c348907384 100644 --- a/apps/files_sharing/lib/External/Manager.php +++ b/apps/files_sharing/lib/External/Manager.php @@ -32,8 +32,11 @@ namespace OCA\Files_Sharing\External; use OC\Files\Filesystem; use OCA\FederatedFileSharing\DiscoveryManager; use OCP\Files; +use OCP\Files\Storage\IStorageFactory; use OCP\Http\Client\IClientService; +use OCP\IDBConnection; use OCP\Notification\IManager; +use OCP\OCS\IDiscoveryService; class Manager { const STORAGE = '\OCA\Files_Sharing\External\Storage'; @@ -44,7 +47,7 @@ class Manager { private $uid; /** - * @var \OCP\IDBConnection + * @var IDBConnection */ private $connection; @@ -54,7 +57,7 @@ class Manager { private $mountManager; /** - * @var \OCP\Files\Storage\IStorageFactory + * @var IStorageFactory */ private $storageLoader; @@ -67,24 +70,27 @@ class Manager { * @var IManager */ private $notificationManager; - /** @var DiscoveryManager */ - private $discoveryManager; /** - * @param \OCP\IDBConnection $connection + * @var IDiscoveryService + */ + private $discoveryService; + + /** + * @param IDBConnection $connection * @param \OC\Files\Mount\Manager $mountManager - * @param \OCP\Files\Storage\IStorageFactory $storageLoader + * @param IStorageFactory $storageLoader * @param IClientService $clientService * @param IManager $notificationManager - * @param DiscoveryManager $discoveryManager + * @param IDiscoveryService $discoveryService * @param string $uid */ - public function __construct(\OCP\IDBConnection $connection, + public function __construct(IDBConnection $connection, \OC\Files\Mount\Manager $mountManager, - \OCP\Files\Storage\IStorageFactory $storageLoader, + IStorageFactory $storageLoader, IClientService $clientService, IManager $notificationManager, - DiscoveryManager $discoveryManager, + IDiscoveryService $discoveryService, $uid) { $this->connection = $connection; $this->mountManager = $mountManager; @@ -92,7 +98,7 @@ class Manager { $this->clientService = $clientService; $this->uid = $uid; $this->notificationManager = $notificationManager; - $this->discoveryManager = $discoveryManager; + $this->discoveryService = $discoveryService; } /** @@ -260,7 +266,10 @@ class Manager { */ private function sendFeedbackToRemote($remote, $token, $remoteId, $feedback) { - $url = rtrim($remote, '/') . $this->discoveryManager->getShareEndpoint($remote) . '/' . $remoteId . '/' . $feedback . '?format=' . \OCP\Share::RESPONSE_FORMAT; + $federationEndpoints = $this->discoveryService->discover($remote, 'FEDERATED_SHARING'); + $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares'; + + $url = rtrim($remote, '/') . $endpoint . '/' . $remoteId . '/' . $feedback . '?format=' . \OCP\Share::RESPONSE_FORMAT; $fields = array('token' => $token); $client = $this->clientService->newClient(); @@ -376,7 +385,7 @@ class Manager { /** * remove re-shares from share table and mapping in the federated_reshares table - * + * * @param $mountPointId */ protected function removeReShares($mountPointId) { diff --git a/apps/files_sharing/lib/External/Storage.php b/apps/files_sharing/lib/External/Storage.php index 51d97388db7..7e0f1fd0b75 100644 --- a/apps/files_sharing/lib/External/Storage.php +++ b/apps/files_sharing/lib/External/Storage.php @@ -51,8 +51,6 @@ class Storage extends DAV implements ISharedStorage { private $memcacheFactory; /** @var \OCP\Http\Client\IClientService */ private $httpClient; - /** @var \OCP\ICertificateManager */ - private $certificateManager; /** @var bool */ private $updateChecked = false; @@ -64,14 +62,11 @@ class Storage extends DAV implements ISharedStorage { public function __construct($options) { $this->memcacheFactory = \OC::$server->getMemCacheFactory(); $this->httpClient = $options['HttpClientService']; - $discoveryManager = new DiscoveryManager( - $this->memcacheFactory, - $this->httpClient - ); $this->manager = $options['manager']; - $this->certificateManager = $options['certificateManager']; $this->cloudId = $options['cloudId']; + $discoveryService = \OC::$server->getOCSDiscoveryService(); + list($protocol, $remote) = explode('://', $this->cloudId->getRemote()); if (strpos($remote, '/')) { list($host, $root) = explode('/', $remote, 2); @@ -80,9 +75,12 @@ class Storage extends DAV implements ISharedStorage { $root = ''; } $secure = $protocol === 'https'; - $root = rtrim($root, '/') . $discoveryManager->getWebDavEndpoint($this->cloudId->getRemote()); + $federatedSharingEndpoints = $discoveryService->discover($this->cloudId->getRemote(), 'FEDERATED_SHARING'); + $webDavEndpoint = isset($federatedSharingEndpoints['webdav']) ? $federatedSharingEndpoints['webdav'] : '/public.php/webdav'; + $root = rtrim($root, '/') . $webDavEndpoint; $this->mountPoint = $options['mountpoint']; $this->token = $options['token']; + parent::__construct(array( 'secure' => $secure, 'host' => $host, @@ -350,7 +348,7 @@ class Storage extends DAV implements ISharedStorage { } return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_SHARE); } - + public function getPermissions($path) { $response = $this->propfind($path); if (isset($response['{http://open-collaboration-services.org/ns}share-permissions'])) { diff --git a/apps/files_sharing/lib/Hooks.php b/apps/files_sharing/lib/Hooks.php index 2029e97d08b..8c5fc6a8d6a 100644 --- a/apps/files_sharing/lib/Hooks.php +++ b/apps/files_sharing/lib/Hooks.php @@ -32,17 +32,13 @@ use OCA\FederatedFileSharing\DiscoveryManager; class Hooks { public static function deleteUser($params) { - $discoveryManager = new DiscoveryManager( - \OC::$server->getMemCacheFactory(), - \OC::$server->getHTTPClientService() - ); $manager = new External\Manager( \OC::$server->getDatabaseConnection(), \OC\Files\Filesystem::getMountManager(), \OC\Files\Filesystem::getLoader(), \OC::$server->getHTTPClientService(), \OC::$server->getNotificationManager(), - $discoveryManager, + \OC::$server->getOCSDiscoveryService(), $params['uid']); $manager->removeUserShares($params['uid']); -- cgit v1.2.3 From 53bca14a27538e457f69fbbdf5aeae2eb3194706 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 5 Apr 2017 22:35:59 +0200 Subject: Do proper DI Signed-off-by: Roeland Jago Douma --- apps/federatedfilesharing/lib/AppInfo/Application.php | 4 ++-- apps/federatedfilesharing/lib/BackgroundJob/RetryJob.php | 2 +- .../lib/Controller/MountPublicLinkController.php | 2 +- .../lib/Controller/RequestHandlerController.php | 2 +- .../tests/Controller/RequestHandlerControllerTest.php | 2 +- apps/federation/lib/AppInfo/Application.php | 2 +- apps/federation/lib/BackgroundJob/GetSharedSecret.php | 2 +- apps/federation/lib/BackgroundJob/RequestSharedSecret.php | 2 +- apps/files_sharing/lib/AppInfo/Application.php | 2 +- apps/files_sharing/lib/External/Storage.php | 2 +- apps/files_sharing/lib/Hooks.php | 2 +- apps/files_sharing/tests/External/ManagerTest.php | 2 +- lib/private/AppFramework/DependencyInjection/DIContainer.php | 9 --------- lib/private/Server.php | 10 +--------- lib/private/Share/Share.php | 2 +- lib/private/Share20/ProviderFactory.php | 2 +- lib/public/IServerContainer.php | 6 ------ 17 files changed, 16 insertions(+), 39 deletions(-) (limited to 'apps/files_sharing/lib') diff --git a/apps/federatedfilesharing/lib/AppInfo/Application.php b/apps/federatedfilesharing/lib/AppInfo/Application.php index daeb049a31e..9d8464e37d5 100644 --- a/apps/federatedfilesharing/lib/AppInfo/Application.php +++ b/apps/federatedfilesharing/lib/AppInfo/Application.php @@ -51,7 +51,7 @@ class Application extends App { $notification = new Notifications( $addressHandler, $server->getHTTPClientService(), - $server->getOCSDiscoveryService(), + $server->query(\OCP\OCS\IDiscoveryService::class), \OC::$server->getJobList() ); return new RequestHandlerController( @@ -99,7 +99,7 @@ class Application extends App { $notifications = new \OCA\FederatedFileSharing\Notifications( $addressHandler, \OC::$server->getHTTPClientService(), - \OC::$server->getOCSDiscoveryService(), + \OC::$server->query(\OCP\OCS\IDiscoveryService::class), \OC::$server->getJobList() ); $tokenHandler = new \OCA\FederatedFileSharing\TokenHandler( diff --git a/apps/federatedfilesharing/lib/BackgroundJob/RetryJob.php b/apps/federatedfilesharing/lib/BackgroundJob/RetryJob.php index 8d81d56802d..821647e5e39 100644 --- a/apps/federatedfilesharing/lib/BackgroundJob/RetryJob.php +++ b/apps/federatedfilesharing/lib/BackgroundJob/RetryJob.php @@ -70,7 +70,7 @@ class RetryJob extends Job { $this->notifications = new Notifications( $addressHandler, \OC::$server->getHTTPClientService(), - \OC::$server->getOCSDiscoveryService(), + \OC::$server->query(\OCP\OCS\IDiscoveryService::class), \OC::$server->getJobList() ); } diff --git a/apps/federatedfilesharing/lib/Controller/MountPublicLinkController.php b/apps/federatedfilesharing/lib/Controller/MountPublicLinkController.php index d20018f38a3..d7e466d1a64 100644 --- a/apps/federatedfilesharing/lib/Controller/MountPublicLinkController.php +++ b/apps/federatedfilesharing/lib/Controller/MountPublicLinkController.php @@ -254,7 +254,7 @@ class MountPublicLinkController extends Controller { Filesystem::getLoader(), \OC::$server->getHTTPClientService(), \OC::$server->getNotificationManager(), - \OC::$server->getOCSDiscoveryService(), + \OC::$server->query(\OCP\OCS\IDiscoveryService::class), \OC::$server->getUserSession()->getUser()->getUID() ); diff --git a/apps/federatedfilesharing/lib/Controller/RequestHandlerController.php b/apps/federatedfilesharing/lib/Controller/RequestHandlerController.php index fa212680225..2b643810fb4 100644 --- a/apps/federatedfilesharing/lib/Controller/RequestHandlerController.php +++ b/apps/federatedfilesharing/lib/Controller/RequestHandlerController.php @@ -158,7 +158,7 @@ class RequestHandlerController extends OCSController { \OC\Files\Filesystem::getLoader(), \OC::$server->getHTTPClientService(), \OC::$server->getNotificationManager(), - \OC::$server->getOCSDiscoveryService(), + \OC::$server->query(\OCP\OCS\IDiscoveryService::class), $shareWith ); diff --git a/apps/federatedfilesharing/tests/Controller/RequestHandlerControllerTest.php b/apps/federatedfilesharing/tests/Controller/RequestHandlerControllerTest.php index c695fb140e5..512000181c1 100644 --- a/apps/federatedfilesharing/tests/Controller/RequestHandlerControllerTest.php +++ b/apps/federatedfilesharing/tests/Controller/RequestHandlerControllerTest.php @@ -276,7 +276,7 @@ class RequestHandlerControllerTest extends TestCase { Filesystem::getLoader(), $httpClientService, \OC::$server->getNotificationManager(), - \OC::$server->getOCSDiscoveryService(), + \OC::$server->query(\OCP\OCS\IDiscoveryService::class), $toDelete ); diff --git a/apps/federation/lib/AppInfo/Application.php b/apps/federation/lib/AppInfo/Application.php index e76a8f850c8..3166316b108 100644 --- a/apps/federation/lib/AppInfo/Application.php +++ b/apps/federation/lib/AppInfo/Application.php @@ -135,7 +135,7 @@ class Application extends \OCP\AppFramework\App { public function getSyncService() { $syncService = \OC::$server->query('CardDAVSyncService'); $dbHandler = $this->getContainer()->query('DbHandler'); - $discoveryService = \OC::$server->getOCSDiscoveryService(); + $discoveryService = \OC::$server->query(\OCP\OCS\IDiscoveryService::class); return new SyncFederationAddressBooks($dbHandler, $syncService, $discoveryService); } diff --git a/apps/federation/lib/BackgroundJob/GetSharedSecret.php b/apps/federation/lib/BackgroundJob/GetSharedSecret.php index 82622978908..b25c51afd0e 100644 --- a/apps/federation/lib/BackgroundJob/GetSharedSecret.php +++ b/apps/federation/lib/BackgroundJob/GetSharedSecret.php @@ -101,7 +101,7 @@ class GetSharedSecret extends Job{ $this->jobList = $jobList ? $jobList : \OC::$server->getJobList(); $this->urlGenerator = $urlGenerator ? $urlGenerator : \OC::$server->getURLGenerator(); $this->dbHandler = $dbHandler ? $dbHandler : new DbHandler(\OC::$server->getDatabaseConnection(), \OC::$server->getL10N('federation')); - $this->ocsDiscoveryService = $ocsDiscoveryService ? $ocsDiscoveryService : \OC::$server->getOCSDiscoveryService(); + $this->ocsDiscoveryService = $ocsDiscoveryService ? $ocsDiscoveryService : \OC::$server->query(\OCP\OCS\IDiscoveryService::class); if ($trustedServers) { $this->trustedServers = $trustedServers; } else { diff --git a/apps/federation/lib/BackgroundJob/RequestSharedSecret.php b/apps/federation/lib/BackgroundJob/RequestSharedSecret.php index 6687b080bb0..1587a3b16e9 100644 --- a/apps/federation/lib/BackgroundJob/RequestSharedSecret.php +++ b/apps/federation/lib/BackgroundJob/RequestSharedSecret.php @@ -99,7 +99,7 @@ class RequestSharedSecret extends Job { $this->urlGenerator = $urlGenerator ? $urlGenerator : \OC::$server->getURLGenerator(); $this->dbHandler = $dbHandler ? $dbHandler : new DbHandler(\OC::$server->getDatabaseConnection(), \OC::$server->getL10N('federation')); $this->logger = \OC::$server->getLogger(); - $this->ocsDiscoveryService = $ocsDiscoveryService ? $ocsDiscoveryService : \OC::$server->getOCSDiscoveryService(); + $this->ocsDiscoveryService = $ocsDiscoveryService ? $ocsDiscoveryService : \OC::$server->query(\OCP\OCS\IDiscoveryService::class); if ($trustedServers) { $this->trustedServers = $trustedServers; } else { diff --git a/apps/files_sharing/lib/AppInfo/Application.php b/apps/files_sharing/lib/AppInfo/Application.php index d4e83ce5d6b..f502d905fe8 100644 --- a/apps/files_sharing/lib/AppInfo/Application.php +++ b/apps/files_sharing/lib/AppInfo/Application.php @@ -98,7 +98,7 @@ class Application extends App { \OC\Files\Filesystem::getLoader(), $server->getHTTPClientService(), $server->getNotificationManager(), - $server->getOCSDiscoveryService(), + $server->query(\OCP\OCS\IDiscoveryService::class), $uid ); }); diff --git a/apps/files_sharing/lib/External/Storage.php b/apps/files_sharing/lib/External/Storage.php index 7e0f1fd0b75..12ee3265c2a 100644 --- a/apps/files_sharing/lib/External/Storage.php +++ b/apps/files_sharing/lib/External/Storage.php @@ -65,7 +65,7 @@ class Storage extends DAV implements ISharedStorage { $this->manager = $options['manager']; $this->cloudId = $options['cloudId']; - $discoveryService = \OC::$server->getOCSDiscoveryService(); + $discoveryService = \OC::$server->query(\OCP\OCS\IDiscoveryService::class); list($protocol, $remote) = explode('://', $this->cloudId->getRemote()); if (strpos($remote, '/')) { diff --git a/apps/files_sharing/lib/Hooks.php b/apps/files_sharing/lib/Hooks.php index 8c5fc6a8d6a..821c3046595 100644 --- a/apps/files_sharing/lib/Hooks.php +++ b/apps/files_sharing/lib/Hooks.php @@ -38,7 +38,7 @@ class Hooks { \OC\Files\Filesystem::getLoader(), \OC::$server->getHTTPClientService(), \OC::$server->getNotificationManager(), - \OC::$server->getOCSDiscoveryService(), + \OC::$server->query(\OCP\OCS\IDiscoveryService::class), $params['uid']); $manager->removeUserShares($params['uid']); diff --git a/apps/files_sharing/tests/External/ManagerTest.php b/apps/files_sharing/tests/External/ManagerTest.php index efe4065e383..9f60261c203 100644 --- a/apps/files_sharing/tests/External/ManagerTest.php +++ b/apps/files_sharing/tests/External/ManagerTest.php @@ -77,7 +77,7 @@ class ManagerTest extends TestCase { new StorageFactory(), $this->clientService, \OC::$server->getNotificationManager(), - \OC::$server->getOCSDiscoveryService(), + \OC::$server->query(\OCP\OCS\IDiscoveryService::class), $this->uid ); $this->testMountProvider = new MountProvider(\OC::$server->getDatabaseConnection(), function() { diff --git a/lib/private/AppFramework/DependencyInjection/DIContainer.php b/lib/private/AppFramework/DependencyInjection/DIContainer.php index 4b72c2c9e3e..4fb13b09ae0 100644 --- a/lib/private/AppFramework/DependencyInjection/DIContainer.php +++ b/lib/private/AppFramework/DependencyInjection/DIContainer.php @@ -56,8 +56,6 @@ use OCP\IL10N; use OCP\IRequest; use OCP\IServerContainer; use OCP\IUserSession; -use OCP\Files\Mount\IMountManager; -use OCP\OCS\IDiscoveryService; use OCP\RichObjectStrings\IValidator; use OCP\Util; @@ -139,13 +137,6 @@ class DIContainer extends SimpleContainer implements IAppContainer { return $c; }); - $this->registerService(IMountManager::class, function () { - return $this->getServer()->getMountManager(); - }); - $this->registerService(IDiscoveryService::class, function($c) { - return $this->getServer()->getOCSDiscoveryService(); - }); - // commonly used attributes $this->registerService('UserId', function ($c) { return $c->query('OCP\\IUserSession')->getSession()->get('user_id'); diff --git a/lib/private/Server.php b/lib/private/Server.php index 13387ebd3ed..67075076801 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -937,7 +937,7 @@ class Server extends ServerContainer implements IServerContainer { }); }); - $this->registerService('OCSDiscoveryService', function (Server $c) { + $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); }); @@ -1001,14 +1001,6 @@ class Server extends ServerContainer implements IServerContainer { return $this->query('EncryptionKeyStorage'); } - /** - * @return \OC\OCS\DiscoveryService - */ - public function getOCSDiscoveryService() { - return $this->query('OCSDiscoveryService'); - } - - /** * The current request object holding all information about the request * currently being processed is returned from this method. diff --git a/lib/private/Share/Share.php b/lib/private/Share/Share.php index 2b4a57b89a4..b3e4cb2d4aa 100644 --- a/lib/private/Share/Share.php +++ b/lib/private/Share/Share.php @@ -2742,7 +2742,7 @@ class Share extends Constants { 'result' => '', ]; $try = 0; - $discoveryService = \OC::$server->getOCSDiscoveryService(); + $discoveryService = \OC::$server->query(\OCP\OCS\IDiscoveryService::class); while ($result['success'] === false && $try < 2) { $federationEndpoints = $discoveryService->discover($protocol . $remoteDomain, 'FEDERATED_SHARING'); $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares'; diff --git a/lib/private/Share20/ProviderFactory.php b/lib/private/Share20/ProviderFactory.php index 5eb34a483e7..ba6699ae7ad 100644 --- a/lib/private/Share20/ProviderFactory.php +++ b/lib/private/Share20/ProviderFactory.php @@ -107,7 +107,7 @@ class ProviderFactory implements IProviderFactory { $notifications = new Notifications( $addressHandler, $this->serverContainer->getHTTPClientService(), - $this->serverContainer->getOCSDiscoveryService(), + $this->serverContainer->query(\OCP\OCS\IDiscoveryService::class), $this->serverContainer->getJobList() ); $tokenHandler = new TokenHandler( diff --git a/lib/public/IServerContainer.php b/lib/public/IServerContainer.php index 4d084aae79e..8c74c05d801 100644 --- a/lib/public/IServerContainer.php +++ b/lib/public/IServerContainer.php @@ -531,10 +531,4 @@ interface IServerContainer extends IContainer { * @since 12.0.0 */ public function getCloudIdManager(); - - /** - * @return \OC\OCS\DiscoveryService - * @since 12.0.0 - */ - public function getOCSDiscoveryService(); } -- cgit v1.2.3