mirror of
https://github.com/nextcloud/server.git
synced 2026-02-20 00:12:30 -05:00
feat: allow configuring multiple objectstore configurations
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
b883fe2764
commit
ff74df3528
2 changed files with 32 additions and 8 deletions
|
|
@ -34,9 +34,14 @@ class PrimaryObjectStoreConfig {
|
|||
* @return ?ObjectStoreConfig
|
||||
*/
|
||||
public function getObjectStoreConfigForRoot(): ?array {
|
||||
$config = $this->getObjectStoreConfig();
|
||||
$configs = $this->getObjectStoreConfig();
|
||||
if (!$configs) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($config && $config['arguments']['multibucket']) {
|
||||
$config = $configs['root'] ?? $configs['default'];
|
||||
|
||||
if ($config['arguments']['multibucket']) {
|
||||
if (!isset($config['arguments']['bucket'])) {
|
||||
$config['arguments']['bucket'] = '';
|
||||
}
|
||||
|
|
@ -51,16 +56,27 @@ class PrimaryObjectStoreConfig {
|
|||
* @return ?ObjectStoreConfig
|
||||
*/
|
||||
public function getObjectStoreConfigForUser(IUser $user): ?array {
|
||||
$config = $this->getObjectStoreConfig();
|
||||
$configs = $this->getObjectStoreConfig();
|
||||
if (!$configs) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($config && $config['arguments']['multibucket']) {
|
||||
$store = $this->config->getUserValue($user->getUID(), 'homeobjectstore', 'objectstore', null);
|
||||
|
||||
if ($store) {
|
||||
$config = $configs[$store];
|
||||
} else {
|
||||
$config = $configs['default'];
|
||||
}
|
||||
|
||||
if ($config['arguments']['multibucket']) {
|
||||
$config['arguments']['bucket'] = $this->getBucketForUser($user, $config);
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ?ObjectStoreConfig
|
||||
* @return ?array<string, ObjectStoreConfig>
|
||||
*/
|
||||
private function getObjectStoreConfig(): ?array {
|
||||
$objectStore = $this->config->getSystemValue('objectstore', null);
|
||||
|
|
@ -69,9 +85,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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,7 +84,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'),
|
||||
|
|
|
|||
Loading…
Reference in a new issue