diff options
author | Robin McCorkell <rmccorkell@owncloud.com> | 2015-08-12 14:22:27 +0100 |
---|---|---|
committer | Robin McCorkell <rmccorkell@owncloud.com> | 2015-08-19 10:05:11 +0100 |
commit | a6a69ef1dfe1545e1362953803219ed6f28f71a5 (patch) | |
tree | 9c3c76b5c66f1fc83d843699c1878a825c18e52d /apps/files_external/lib/config | |
parent | 37beb58c6f395523d8e2934870c5f52a8c6f6df0 (diff) | |
download | nextcloud-server-a6a69ef1dfe1545e1362953803219ed6f28f71a5.tar.gz nextcloud-server-a6a69ef1dfe1545e1362953803219ed6f28f71a5.zip |
Introduce UserGlobalStoragesService
UserGlobalStoragesService reads the global storage configuration,
cherry-picking storages applicable to a user. Writing storages through
this service is forbidden, on punishment of throwing an exception.
Storage IDs may also be config hashes when retrieved from this service,
as it is unable to update the storages with real IDs.
As UserGlobalStoragesService and UserStoragesService share a bit of code
relating to users, that has been split into UserTrait. UserTrait also
allows for the user set to be overridden, rather than using the user
from IUserSession.
Config\ConfigAdapter has been reworked to use UserStoragesService and
UserGlobalStoragesService instead of
OC_Mount_Config::getAbsoluteMountPoints(), further reducing dependance
on that horrible static class.
Diffstat (limited to 'apps/files_external/lib/config')
-rw-r--r-- | apps/files_external/lib/config/configadapter.php | 98 |
1 files changed, 83 insertions, 15 deletions
diff --git a/apps/files_external/lib/config/configadapter.php b/apps/files_external/lib/config/configadapter.php index 6956de1e748..63615e716ae 100644 --- a/apps/files_external/lib/config/configadapter.php +++ b/apps/files_external/lib/config/configadapter.php @@ -2,6 +2,7 @@ /** * @author Morris Jobke <hey@morrisjobke.de> * @author Robin Appelman <icewind@owncloud.com> + * @author Robin McCorkell <rmccorkell@owncloud.com> * * @copyright Copyright (c) 2015, ownCloud, Inc. * @license AGPL-3.0 @@ -22,23 +23,67 @@ namespace OCA\Files_External\Config; +use OCP\Files\Storage; use OC\Files\Mount\MountPoint; use OCP\Files\Storage\IStorageFactory; use OCA\Files_External\Lib\PersonalMount; use OCP\Files\Config\IMountProvider; use OCP\IUser; use OCA\Files_external\Service\UserStoragesService; +use OCA\Files_External\Service\UserGlobalStoragesService; +use OCA\Files_External\Lib\StorageConfig; /** * Make the old files_external config work with the new public mount config api */ class ConfigAdapter implements IMountProvider { + /** @var UserStoragesService */ + private $userStoragesService; + + /** @var UserGlobalStoragesService */ + private $userGlobalStoragesService; + /** * @param UserStoragesService $userStoragesService + * @param UserGlobalStoragesService $userGlobalStoragesService */ - public function __construct(UserStoragesService $userStoragesService) { + public function __construct( + UserStoragesService $userStoragesService, + UserGlobalStoragesService $userGlobalStoragesService + ) { $this->userStoragesService = $userStoragesService; + $this->userGlobalStoragesService = $userGlobalStoragesService; + } + + /** + * Process storage ready for mounting + * + * @param StorageConfig $storage + */ + private function prepareStorageConfig(StorageConfig &$storage) { + $objectStore = $storage->getBackendOption('objectstore'); + if ($objectStore) { + $objectClass = $objectStore['class']; + $storage->setBackendOption('objectstore', new $objectClass($objectStore)); + } + + $storage->getBackend()->manipulateStorageConfig($storage); + } + + /** + * Construct the storage implementation + * + * @param StorageConfig $storageConfig + * @return Storage + */ + private function constructStorage(StorageConfig $storageConfig) { + $class = $storageConfig->getBackend()->getStorageClass(); + $storage = new $class($storageConfig->getBackendOptions()); + + $storage = $storageConfig->getBackend()->wrapStorage($storage); + + return $storage; } /** @@ -49,21 +94,44 @@ class ConfigAdapter implements IMountProvider { * @return \OCP\Files\Mount\IMountPoint[] */ public function getMountsForUser(IUser $user, IStorageFactory $loader) { - $mountPoints = \OC_Mount_Config::getAbsoluteMountPoints($user->getUID()); - $mounts = array(); - foreach ($mountPoints as $mountPoint => $options) { - if (isset($options['options']['objectstore'])) { - $objectClass = $options['options']['objectstore']['class']; - $options['options']['objectstore'] = new $objectClass($options['options']['objectstore']); - } - $mountOptions = isset($options['mountOptions']) ? $options['mountOptions'] : []; - if (isset($options['personal']) && $options['personal']) { - $mount = new PersonalMount($this->userStoragesService, $options['id'], $options['class'], $mountPoint, $options['options'], $loader, $mountOptions); - $mounts[] = $mount; - } else { - $mounts[] = new MountPoint($options['class'], $mountPoint, $options['options'], $loader, $mountOptions); - } + $mounts = []; + + $this->userStoragesService->setUser($user); + $this->userGlobalStoragesService->setUser($user); + + foreach ($this->userGlobalStoragesService->getAllStorages() as $storage) { + $this->prepareStorageConfig($storage); + $impl = $this->constructStorage($storage); + + $mount = new MountPoint( + $impl, + '/'.$user->getUID().'/files' . $storage->getMountPoint(), + null, + $loader, + $storage->getMountOptions() + ); + $mounts[$storage->getMountPoint()] = $mount; + } + + foreach ($this->userStoragesService->getAllStorages() as $storage) { + $this->prepareStorageConfig($storage); + $impl = $this->constructStorage($storage); + + $mount = new PersonalMount( + $this->userStoragesService, + $storage->getId(), + $impl, + '/'.$user->getUID().'/files' . $storage->getMountPoint(), + null, + $loader, + $storage->getMountOptions() + ); + $mounts[$storage->getMountPoint()] = $mount; } + + $this->userStoragesService->resetUser(); + $this->userGlobalStoragesService->resetUser(); + return $mounts; } } |