diff options
author | Robin Appelman <robin@icewind.nl> | 2022-12-01 16:25:15 +0100 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2025-05-14 15:23:27 +0200 |
commit | 5c33aec11f1906ecdd1ec418e840c81e651f3173 (patch) | |
tree | 8a1d759267482ac8501a0b215b3b45b91973f788 | |
parent | fa8e16199bc067b5902a608274beb16a929423db (diff) | |
download | nextcloud-server-multi-object-store.tar.gz nextcloud-server-multi-object-store.zip |
feat: allow configuring multiple objectstore configurationsmulti-object-store
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r-- | lib/private/Files/ObjectStore/PrimaryObjectStoreConfig.php | 36 | ||||
-rw-r--r-- | tests/lib/Files/Mount/ObjectHomeMountProviderTest.php | 2 |
2 files changed, 31 insertions, 7 deletions
diff --git a/lib/private/Files/ObjectStore/PrimaryObjectStoreConfig.php b/lib/private/Files/ObjectStore/PrimaryObjectStoreConfig.php index 19ea5c872e0..275f7e37880 100644 --- a/lib/private/Files/ObjectStore/PrimaryObjectStoreConfig.php +++ b/lib/private/Files/ObjectStore/PrimaryObjectStoreConfig.php @@ -33,9 +33,14 @@ class PrimaryObjectStoreConfig { * @return ?ObjectStoreConfig */ public function getObjectStoreConfigForRoot(): ?array { - $config = $this->getObjectStoreConfig(); + $configs = $this->getObjectStoreConfig(); + if (!$configs) { + return null; + } + + $config = $configs['root'] ?? $configs['default']; - if ($config && $config['arguments']['multibucket']) { + if ($config['arguments']['multibucket']) { if (!isset($config['arguments']['bucket'])) { $config['arguments']['bucket'] = ''; } @@ -50,9 +55,20 @@ class PrimaryObjectStoreConfig { * @return ?ObjectStoreConfig */ public function getObjectStoreConfigForUser(IUser $user): ?array { - $config = $this->getObjectStoreConfig(); + $configs = $this->getObjectStoreConfig(); + if (!$configs) { + return null; + } + + $store = $this->config->getUserValue($user->getUID(), 'homeobjectstore', 'objectstore', null); - if ($config && $config['arguments']['multibucket']) { + if ($store) { + $config = $configs[$store]; + } else { + $config = $configs['default']; + } + + if ($config['arguments']['multibucket']) { $config['arguments']['bucket'] = $this->getBucketForUser($user, $config); } return $config; @@ -68,9 +84,17 @@ class PrimaryObjectStoreConfig { // new-style multibucket config uses the same 'objectstore' key but sets `'multibucket' => true`, transparently upgrade older style config if ($objectStoreMultiBucket) { $objectStoreMultiBucket['arguments']['multibucket'] = true; - return $this->validateObjectStoreConfig($objectStoreMultiBucket); + return [ + 'default' => $this->validateObjectStoreConfig($objectStoreMultiBucket) + ]; } elseif($objectStore) { - return $this->validateObjectStoreConfig($objectStore); + if (!isset($objectStore['default'])) { + $objectStore = [ + 'default' => $objectStore, + ]; + } + + return array_map($this->validateObjectStoreConfig(...), $objectStore); } else { return null; } diff --git a/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php b/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php index 2a68e4ed8fb..deb3fb07189 100644 --- a/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php +++ b/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php @@ -83,7 +83,7 @@ class ObjectHomeMountProviderTest extends \Test\TestCase { $this->config->method('getUserValue') ->willReturn(null); - $this->config->expects($this->once()) + $this->config ->method('setUserValue') ->with( $this->equalTo('uid'), |