diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-10-07 17:46:33 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-10-07 17:46:33 +0200 |
commit | b2872ef759e50a5b1eb3d54f8b878777b2f03977 (patch) | |
tree | 4b3b5d19a125e7827157573ca757a765bcdff7df /apps/files_sharing/lib/external | |
parent | c8021441d0cd3090b4406f445139f65d1045a460 (diff) | |
parent | d3c1fcf9615339786d3134b8b30d150f9a80f89d (diff) | |
download | nextcloud-server-b2872ef759e50a5b1eb3d54f8b878777b2f03977.tar.gz nextcloud-server-b2872ef759e50a5b1eb3d54f8b878777b2f03977.zip |
Merge pull request #19589 from owncloud/shares-external-mount-provider
Move the setup of external share mounts to a mountprovider
Diffstat (limited to 'apps/files_sharing/lib/external')
-rw-r--r-- | apps/files_sharing/lib/external/manager.php | 54 | ||||
-rw-r--r-- | apps/files_sharing/lib/external/mountprovider.php | 75 |
2 files changed, 84 insertions, 45 deletions
diff --git a/apps/files_sharing/lib/external/manager.php b/apps/files_sharing/lib/external/manager.php index ab6a02f94a1..86b8904cc9a 100644 --- a/apps/files_sharing/lib/external/manager.php +++ b/apps/files_sharing/lib/external/manager.php @@ -153,28 +153,6 @@ class Manager { return $this->mountShare($options); } - private function setupMounts() { - // don't setup server-to-server shares if the admin disabled it - if (\OCA\Files_Sharing\Helper::isIncomingServer2serverShareEnabled() === false) { - return false; - } - - if (!is_null($this->uid)) { - $query = $this->connection->prepare(' - SELECT `remote`, `share_token`, `password`, `mountpoint`, `owner` - FROM `*PREFIX*share_external` - WHERE `user` = ? AND `accepted` = ? - '); - $query->execute(array($this->uid, 1)); - - while ($row = $query->fetch()) { - $row['manager'] = $this; - $row['token'] = $row['share_token']; - $this->mountShare($row); - } - } - } - /** * get share * @@ -277,24 +255,6 @@ class Manager { } /** - * setup the server-to-server mounts - * - * @param array $params - */ - public static function setup(array $params) { - $externalManager = new \OCA\Files_Sharing\External\Manager( - \OC::$server->getDatabaseConnection(), - \OC\Files\Filesystem::getMountManager(), - \OC\Files\Filesystem::getLoader(), - \OC::$server->getHTTPHelper(), - \OC::$server->getNotificationManager(), - $params['user'] - ); - - $externalManager->setupMounts(); - } - - /** * remove '/user/files' from the path and trailing slashes * * @param string $path @@ -305,16 +265,20 @@ class Manager { return rtrim(substr($path, strlen($prefix)), '/'); } + 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, $this->storageLoader); + } + /** * @param array $data * @return Mount */ protected function mountShare($data) { - $data['manager'] = $this; - $mountPoint = '/' . $this->uid . '/files' . $data['mountpoint']; - $data['mountpoint'] = $mountPoint; - $data['certificateManager'] = \OC::$server->getCertificateManager($this->uid); - $mount = new Mount(self::STORAGE, $mountPoint, $data, $this, $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..1739cec543f --- /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/' . ltrim($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; + } +} |