diff options
author | Robin Appelman <icewind@owncloud.com> | 2015-11-02 13:13:06 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2015-12-04 13:48:21 +0100 |
commit | a1898dc2bf9a89def29c1437903e560609f0cf40 (patch) | |
tree | 527d941bd240dd1c02760819724d21dfdd5d041c /apps/files_external/service/userstoragesservice.php | |
parent | 98bb8372f7f0ab1f669cdd92d439814e1b6aaa1a (diff) | |
download | nextcloud-server-a1898dc2bf9a89def29c1437903e560609f0cf40.tar.gz nextcloud-server-a1898dc2bf9a89def29c1437903e560609f0cf40.zip |
db config backend for files_external
Diffstat (limited to 'apps/files_external/service/userstoragesservice.php')
-rw-r--r-- | apps/files_external/service/userstoragesservice.php | 108 |
1 files changed, 22 insertions, 86 deletions
diff --git a/apps/files_external/service/userstoragesservice.php b/apps/files_external/service/userstoragesservice.php index a8cdf60ad9c..5cf04578caf 100644 --- a/apps/files_external/service/userstoragesservice.php +++ b/apps/files_external/service/userstoragesservice.php @@ -35,107 +35,26 @@ use \OCA\Files_External\Service\UserTrait; * (aka personal storages) */ class UserStoragesService extends StoragesService { - use UserTrait; /** * Create a user storages service * * @param BackendService $backendService + * @param DBConfigService $dbConfig * @param IUserSession $userSession user session */ public function __construct( BackendService $backendService, + DBConfigService $dbConfig, IUserSession $userSession ) { $this->userSession = $userSession; - parent::__construct($backendService); - } - - /** - * Read legacy config data - * - * @return array list of storage configs - */ - protected function readLegacyConfig() { - // read user config - $user = $this->getUser()->getUID(); - return \OC_Mount_Config::readData($user); - } - - /** - * Write legacy config data - * - * @param array $mountPoints - */ - protected function writeLegacyConfig(array $mountPoints) { - // write user config - $user = $this->getUser()->getUID(); - \OC_Mount_Config::writeData($user, $mountPoints); - } - - /** - * Read the external storages config - * - * @return array map of storage id to storage config - */ - protected function readConfig() { - $user = $this->getUser()->getUID(); - // TODO: in the future don't rely on the global config reading code - $storages = parent::readConfig(); - - $filteredStorages = []; - foreach ($storages as $configId => $storage) { - // filter out all bogus storages that aren't for the current user - if (!in_array($user, $storage->getApplicableUsers())) { - continue; - } - - // clear applicable users, should not be used - $storage->setApplicableUsers([]); - - // strip out unneeded applicableUser fields - $filteredStorages[$configId] = $storage; - } - - return $filteredStorages; + parent::__construct($backendService, $dbConfig); } - /** - * Write the storages to the user's configuration. - * - * @param array $storages map of storage id to storage config - */ - public function writeConfig($storages) { - $user = $this->getUser()->getUID(); - - // let the horror begin - $mountPoints = []; - foreach ($storages as $storageConfig) { - $mountPoint = $storageConfig->getMountPoint(); - $oldBackendOptions = $storageConfig->getBackendOptions(); - $storageConfig->setBackendOptions( - \OC_Mount_Config::encryptPasswords( - $oldBackendOptions - ) - ); - - $rootMountPoint = '/' . $user . '/files/' . ltrim($mountPoint, '/'); - - $this->addMountPoint( - $mountPoints, - \OC_Mount_Config::MOUNT_TYPE_USER, - $user, - $rootMountPoint, - $storageConfig - ); - - // restore old backend options where the password was not encrypted, - // because we don't want to change the state of the original object - $storageConfig->setBackendOptions($oldBackendOptions); - } - - $this->writeLegacyConfig($mountPoints); + protected function readDBConfig() { + return $this->dbConfig->getUserMountsFor(DBConfigService::APPLICABLE_TYPE_USER, $this->getUser()->getUID()); } /** @@ -173,6 +92,23 @@ class UserStoragesService extends StoragesService { } } + protected function getType() { + return DBConfigService::MOUNT_TYPE_PERSONAl; + } + + /** + * Add new storage to the configuration + * + * @param StorageConfig $newStorage storage attributes + * + * @return StorageConfig storage config, with added id + */ + public function addStorage(StorageConfig $newStorage) { + $config = parent::addStorage($newStorage); + $this->dbConfig->addApplicable($config->getId(), DBConfigService::APPLICABLE_TYPE_USER, $this->getUser()->getUID()); + return $config; + } + /** * Get the visibility type for this controller, used in validation * |