@@ -33,108 +33,108 @@ |
||
| 33 | 33 | * Mount provider for object store home storages |
| 34 | 34 | */ |
| 35 | 35 | class ObjectHomeMountProvider implements IHomeMountProvider { |
| 36 | - /** |
|
| 37 | - * @var IConfig |
|
| 38 | - */ |
|
| 39 | - private $config; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * ObjectStoreHomeMountProvider constructor. |
|
| 43 | - * |
|
| 44 | - * @param IConfig $config |
|
| 45 | - */ |
|
| 46 | - public function __construct(IConfig $config) { |
|
| 47 | - $this->config = $config; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Get the cache mount for a user |
|
| 52 | - * |
|
| 53 | - * @param IUser $user |
|
| 54 | - * @param IStorageFactory $loader |
|
| 55 | - * @return \OCP\Files\Mount\IMountPoint |
|
| 56 | - */ |
|
| 57 | - public function getHomeMountForUser(IUser $user, IStorageFactory $loader) { |
|
| 58 | - |
|
| 59 | - $config = $this->getMultiBucketObjectStoreConfig($user); |
|
| 60 | - if ($config === null) { |
|
| 61 | - $config = $this->getSingleBucketObjectStoreConfig($user); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - if ($config === null) { |
|
| 65 | - return null; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - return new MountPoint('\OC\Files\ObjectStore\HomeObjectStoreStorage', '/' . $user->getUID(), $config['arguments'], $loader); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @param IUser $user |
|
| 73 | - * @return array|null |
|
| 74 | - */ |
|
| 75 | - private function getSingleBucketObjectStoreConfig(IUser $user) { |
|
| 76 | - $config = $this->config->getSystemValue('objectstore'); |
|
| 77 | - if (!is_array($config)) { |
|
| 78 | - return null; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - // sanity checks |
|
| 82 | - if (empty($config['class'])) { |
|
| 83 | - \OCP\Util::writeLog('files', 'No class given for objectstore', ILogger::ERROR); |
|
| 84 | - } |
|
| 85 | - if (!isset($config['arguments'])) { |
|
| 86 | - $config['arguments'] = []; |
|
| 87 | - } |
|
| 88 | - // instantiate object store implementation |
|
| 89 | - $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
| 90 | - |
|
| 91 | - $config['arguments']['user'] = $user; |
|
| 92 | - |
|
| 93 | - return $config; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @param IUser $user |
|
| 98 | - * @return array|null |
|
| 99 | - */ |
|
| 100 | - private function getMultiBucketObjectStoreConfig(IUser $user) { |
|
| 101 | - $config = $this->config->getSystemValue('objectstore_multibucket'); |
|
| 102 | - if (!is_array($config)) { |
|
| 103 | - return null; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - // sanity checks |
|
| 107 | - if (empty($config['class'])) { |
|
| 108 | - \OCP\Util::writeLog('files', 'No class given for objectstore', ILogger::ERROR); |
|
| 109 | - } |
|
| 110 | - if (!isset($config['arguments'])) { |
|
| 111 | - $config['arguments'] = []; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - $bucket = $this->config->getUserValue($user->getUID(), 'homeobjectstore', 'bucket', null); |
|
| 115 | - |
|
| 116 | - if ($bucket === null) { |
|
| 117 | - /* |
|
| 36 | + /** |
|
| 37 | + * @var IConfig |
|
| 38 | + */ |
|
| 39 | + private $config; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * ObjectStoreHomeMountProvider constructor. |
|
| 43 | + * |
|
| 44 | + * @param IConfig $config |
|
| 45 | + */ |
|
| 46 | + public function __construct(IConfig $config) { |
|
| 47 | + $this->config = $config; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Get the cache mount for a user |
|
| 52 | + * |
|
| 53 | + * @param IUser $user |
|
| 54 | + * @param IStorageFactory $loader |
|
| 55 | + * @return \OCP\Files\Mount\IMountPoint |
|
| 56 | + */ |
|
| 57 | + public function getHomeMountForUser(IUser $user, IStorageFactory $loader) { |
|
| 58 | + |
|
| 59 | + $config = $this->getMultiBucketObjectStoreConfig($user); |
|
| 60 | + if ($config === null) { |
|
| 61 | + $config = $this->getSingleBucketObjectStoreConfig($user); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + if ($config === null) { |
|
| 65 | + return null; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + return new MountPoint('\OC\Files\ObjectStore\HomeObjectStoreStorage', '/' . $user->getUID(), $config['arguments'], $loader); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @param IUser $user |
|
| 73 | + * @return array|null |
|
| 74 | + */ |
|
| 75 | + private function getSingleBucketObjectStoreConfig(IUser $user) { |
|
| 76 | + $config = $this->config->getSystemValue('objectstore'); |
|
| 77 | + if (!is_array($config)) { |
|
| 78 | + return null; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + // sanity checks |
|
| 82 | + if (empty($config['class'])) { |
|
| 83 | + \OCP\Util::writeLog('files', 'No class given for objectstore', ILogger::ERROR); |
|
| 84 | + } |
|
| 85 | + if (!isset($config['arguments'])) { |
|
| 86 | + $config['arguments'] = []; |
|
| 87 | + } |
|
| 88 | + // instantiate object store implementation |
|
| 89 | + $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
| 90 | + |
|
| 91 | + $config['arguments']['user'] = $user; |
|
| 92 | + |
|
| 93 | + return $config; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @param IUser $user |
|
| 98 | + * @return array|null |
|
| 99 | + */ |
|
| 100 | + private function getMultiBucketObjectStoreConfig(IUser $user) { |
|
| 101 | + $config = $this->config->getSystemValue('objectstore_multibucket'); |
|
| 102 | + if (!is_array($config)) { |
|
| 103 | + return null; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + // sanity checks |
|
| 107 | + if (empty($config['class'])) { |
|
| 108 | + \OCP\Util::writeLog('files', 'No class given for objectstore', ILogger::ERROR); |
|
| 109 | + } |
|
| 110 | + if (!isset($config['arguments'])) { |
|
| 111 | + $config['arguments'] = []; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + $bucket = $this->config->getUserValue($user->getUID(), 'homeobjectstore', 'bucket', null); |
|
| 115 | + |
|
| 116 | + if ($bucket === null) { |
|
| 117 | + /* |
|
| 118 | 118 | * Use any provided bucket argument as prefix |
| 119 | 119 | * and add the mapping from username => bucket |
| 120 | 120 | */ |
| 121 | - if (!isset($config['arguments']['bucket'])) { |
|
| 122 | - $config['arguments']['bucket'] = ''; |
|
| 123 | - } |
|
| 124 | - $mapper = new \OC\Files\ObjectStore\Mapper($user); |
|
| 125 | - $numBuckets = isset($config['arguments']['num_buckets']) ? $config['arguments']['num_buckets'] : 64; |
|
| 126 | - $config['arguments']['bucket'] .= $mapper->getBucket($numBuckets); |
|
| 121 | + if (!isset($config['arguments']['bucket'])) { |
|
| 122 | + $config['arguments']['bucket'] = ''; |
|
| 123 | + } |
|
| 124 | + $mapper = new \OC\Files\ObjectStore\Mapper($user); |
|
| 125 | + $numBuckets = isset($config['arguments']['num_buckets']) ? $config['arguments']['num_buckets'] : 64; |
|
| 126 | + $config['arguments']['bucket'] .= $mapper->getBucket($numBuckets); |
|
| 127 | 127 | |
| 128 | - $this->config->setUserValue($user->getUID(), 'homeobjectstore', 'bucket', $config['arguments']['bucket']); |
|
| 129 | - } else { |
|
| 130 | - $config['arguments']['bucket'] = $bucket; |
|
| 131 | - } |
|
| 128 | + $this->config->setUserValue($user->getUID(), 'homeobjectstore', 'bucket', $config['arguments']['bucket']); |
|
| 129 | + } else { |
|
| 130 | + $config['arguments']['bucket'] = $bucket; |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - // instantiate object store implementation |
|
| 134 | - $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
| 133 | + // instantiate object store implementation |
|
| 134 | + $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
| 135 | 135 | |
| 136 | - $config['arguments']['user'] = $user; |
|
| 136 | + $config['arguments']['user'] = $user; |
|
| 137 | 137 | |
| 138 | - return $config; |
|
| 139 | - } |
|
| 138 | + return $config; |
|
| 139 | + } |
|
| 140 | 140 | } |