Skip to content

Commit 618a70a

Browse files
committed
feat: allow configuring multiple objectstore configurations
Signed-off-by: Robin Appelman <[email protected]>
1 parent d56988c commit 618a70a

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

lib/private/Files/ObjectStore/PrimaryObjectStoreConfig.php

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,14 @@ public function buildObjectStore(array $config): IObjectStore {
3434
* @return ?ObjectStoreConfig
3535
*/
3636
public function getObjectStoreConfigForRoot(): ?array {
37-
$config = $this->getObjectStoreConfig();
37+
$configs = $this->getObjectStoreConfig();
38+
if (!$configs) {
39+
return null;
40+
}
41+
42+
$config = $configs['root'] ?? $configs['default'];
3843

39-
if ($config && $config['arguments']['multibucket']) {
44+
if ($config['arguments']['multibucket']) {
4045
if (!isset($config['arguments']['bucket'])) {
4146
$config['arguments']['bucket'] = '';
4247
}
@@ -51,16 +56,27 @@ public function getObjectStoreConfigForRoot(): ?array {
5156
* @return ?ObjectStoreConfig
5257
*/
5358
public function getObjectStoreConfigForUser(IUser $user): ?array {
54-
$config = $this->getObjectStoreConfig();
59+
$configs = $this->getObjectStoreConfig();
60+
if (!$configs) {
61+
return null;
62+
}
63+
64+
$store = $this->config->getUserValue($user->getUID(), 'homeobjectstore', 'objectstore', null);
5565

56-
if ($config && $config['arguments']['multibucket']) {
66+
if ($store) {
67+
$config = $configs[$store];
68+
} else {
69+
$config = $configs['default'];
70+
}
71+
72+
if ($config['arguments']['multibucket']) {
5773
$config['arguments']['bucket'] = $this->getBucketForUser($user, $config);
5874
}
5975
return $config;
6076
}
6177

6278
/**
63-
* @return ?ObjectStoreConfig
79+
* @return ?array<string, ObjectStoreConfig>
6480
*/
6581
private function getObjectStoreConfig(): ?array {
6682
$objectStore = $this->config->getSystemValue('objectstore', null);
@@ -69,9 +85,17 @@ private function getObjectStoreConfig(): ?array {
6985
// new-style multibucket config uses the same 'objectstore' key but sets `'multibucket' => true`, transparently upgrade older style config
7086
if ($objectStoreMultiBucket) {
7187
$objectStoreMultiBucket['arguments']['multibucket'] = true;
72-
return $this->validateObjectStoreConfig($objectStoreMultiBucket);
88+
return [
89+
'default' => $this->validateObjectStoreConfig($objectStoreMultiBucket)
90+
];
7391
} elseif ($objectStore) {
74-
return $this->validateObjectStoreConfig($objectStore);
92+
if (!isset($objectStore['default'])) {
93+
$objectStore = [
94+
'default' => $objectStore,
95+
];
96+
}
97+
98+
return array_map($this->validateObjectStoreConfig(...), $objectStore);
7599
} else {
76100
return null;
77101
}

tests/lib/Files/Mount/ObjectHomeMountProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function testMultiBucket() {
7979
$this->config->method('getUserValue')
8080
->willReturn(null);
8181

82-
$this->config->expects($this->once())
82+
$this->config
8383
->method('setUserValue')
8484
->with(
8585
$this->equalTo('uid'),

0 commit comments

Comments
 (0)