diff options
author | Robin Appelman <icewind@owncloud.com> | 2015-10-05 16:39:11 +0200 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2015-10-05 16:39:11 +0200 |
commit | e1c562f66b8547e0418a14f9f4fe8616c622caa8 (patch) | |
tree | f64a3387fe269ecc2a4b36382d32b674346b0a6a /apps | |
parent | a0c9dc298680eaa4f9f077978d8baefdec102d93 (diff) | |
download | nextcloud-server-e1c562f66b8547e0418a14f9f4fe8616c622caa8.tar.gz nextcloud-server-e1c562f66b8547e0418a14f9f4fe8616c622caa8.zip |
extract the mount provider from the manager
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files_sharing/appinfo/application.php | 13 | ||||
-rw-r--r-- | apps/files_sharing/lib/external/manager.php | 27 | ||||
-rw-r--r-- | apps/files_sharing/lib/external/mountprovider.php | 75 |
3 files changed, 91 insertions, 24 deletions
diff --git a/apps/files_sharing/appinfo/application.php b/apps/files_sharing/appinfo/application.php index c3e2a1d707d..872229fa743 100644 --- a/apps/files_sharing/appinfo/application.php +++ b/apps/files_sharing/appinfo/application.php @@ -118,6 +118,17 @@ class Application extends App { ); }); + $container->registerService('ExternalMountProvider', function (IContainer $c) { + /** @var \OCP\IServerContainer $server */ + $server = $c->query('ServerContainer'); + return new \OCA\Files_Sharing\External\MountProvider( + $server->getDatabaseConnection(), + function() use ($c) { + return $c->query('ExternalManager'); + } + ); + }); + $container->registerService('PropagationManager', function (IContainer $c) { /** @var \OCP\IServerContainer $server */ $server = $c->query('ServerContainer'); @@ -138,7 +149,7 @@ class Application extends App { $server = $this->getContainer()->query('ServerContainer'); $mountProviderCollection = $server->getMountProviderCollection(); $mountProviderCollection->registerProvider($this->getContainer()->query('MountProvider')); - $mountProviderCollection->registerProvider($this->getContainer()->query('ExternalManager')); + $mountProviderCollection->registerProvider($this->getContainer()->query('ExternalMountProvider')); } public function setupPropagation() { diff --git a/apps/files_sharing/lib/external/manager.php b/apps/files_sharing/lib/external/manager.php index 662e70d1237..a017a465b55 100644 --- a/apps/files_sharing/lib/external/manager.php +++ b/apps/files_sharing/lib/external/manager.php @@ -28,12 +28,9 @@ namespace OCA\Files_Sharing\External; use OC\Files\Filesystem; use OCP\Files; -use OCP\Files\Config\IMountProvider; -use OCP\Files\Storage\IStorageFactory; use OC\Notification\IManager; -use OCP\IUser; -class Manager implements IMountProvider { +class Manager { const STORAGE = '\OCA\Files_Sharing\External\Storage'; /** @@ -155,22 +152,6 @@ class Manager implements IMountProvider { return $this->mountShare($options); } - public function getMountsForUser(IUser $user, IStorageFactory $loader) { - $query = $this->connection->prepare(' - SELECT `remote`, `share_token`, `password`, `mountpoint`, `owner` - FROM `*PREFIX*share_external` - WHERE `user` = ? AND `accepted` = ? - '); - $query->execute([$user->getUID(), 1]); - $mounts = []; - while ($row = $query->fetch()) { - $row['manager'] = $this; - $row['token'] = $row['share_token']; - $mounts[] = $this->getMount($row, $loader); - } - return $mounts; - } - /** * get share * @@ -283,12 +264,12 @@ class Manager implements IMountProvider { return rtrim(substr($path, strlen($prefix)), '/'); } - protected function getMount($data, IStorageFactory $storageFactory) { + public function getMount($data) { $data['manager'] = $this; $mountPoint = '/' . $this->uid . '/files' . $data['mountpoint']; $data['mountpoint'] = $mountPoint; $data['certificateManager'] = \OC::$server->getCertificateManager($this->uid); - return new Mount(self::STORAGE, $mountPoint, $data, $this, $storageFactory); + return new Mount(self::STORAGE, $mountPoint, $data, $this, $this->storageLoader); } /** @@ -296,7 +277,7 @@ class Manager implements IMountProvider { * @return Mount */ protected function mountShare($data) { - $mount = $this->getMount($data, $this->storageLoader); + $mount = $this->getMount($data); $this->mountManager->addMount($mount); return $mount; } diff --git a/apps/files_sharing/lib/external/mountprovider.php b/apps/files_sharing/lib/external/mountprovider.php new file mode 100644 index 00000000000..59072c203fb --- /dev/null +++ b/apps/files_sharing/lib/external/mountprovider.php @@ -0,0 +1,75 @@ +<?php +/** + * @author Robin Appelman <icewind@owncloud.com> + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace OCA\Files_Sharing\External; + +use OCP\Files\Config\IMountProvider; +use OCP\Files\Storage\IStorageFactory; +use OCP\IDBConnection; +use OCP\IUser; + +class MountProvider implements IMountProvider { + const STORAGE = '\OCA\Files_Sharing\External\Storage'; + + /** + * @var \OCP\IDBConnection + */ + private $connection; + + /** + * @var callable + */ + private $managerProvider; + + /** + * @param \OCP\IDBConnection $connection + * @param callable $managerProvider due to setup order we need a callable that return the manager instead of the manager itself + */ + public function __construct(IDBConnection $connection, callable $managerProvider) { + $this->connection = $connection; + $this->managerProvider = $managerProvider; + } + + public function getMount(IUser $user, $data, IStorageFactory $storageFactory) { + $data['manager'] = $this; + $mountPoint = '/' . $user->getUID() . '/files' . $data['mountpoint']; + $data['mountpoint'] = $mountPoint; + $data['certificateManager'] = \OC::$server->getCertificateManager($user->getUID()); + $managerProvider = $this->managerProvider; + return new Mount(self::STORAGE, $mountPoint, $data, $managerProvider(), $storageFactory); + } + + public function getMountsForUser(IUser $user, IStorageFactory $loader) { + $query = $this->connection->prepare(' + SELECT `remote`, `share_token`, `password`, `mountpoint`, `owner` + FROM `*PREFIX*share_external` + WHERE `user` = ? AND `accepted` = ? + '); + $query->execute([$user->getUID(), 1]); + $mounts = []; + while ($row = $query->fetch()) { + $row['manager'] = $this; + $row['token'] = $row['share_token']; + $mounts[] = $this->getMount($user, $row, $loader); + } + return $mounts; + } +} |