feat: theming
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -72,4 +72,57 @@ class TenantStore
|
||||
$this->dataStore->selectCollection(self::COLLECTION_NAME)->deleteOne([ '_id' => $id]);
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// Settings Operations
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* Fetch settings for a tenant, optionally filtered to specific keys.
|
||||
*
|
||||
* @param string $identifier Tenant identifier
|
||||
* @param string[] $keys Optional list of keys to return; empty = all
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function fetchSettings(string $identifier, array $keys = []): array
|
||||
{
|
||||
$entry = $this->dataStore->selectCollection(self::COLLECTION_NAME)->findOne(
|
||||
['identifier' => $identifier],
|
||||
['projection' => ['settings' => 1]]
|
||||
);
|
||||
|
||||
$settings = (array)($entry['settings'] ?? []);
|
||||
|
||||
if (empty($keys)) {
|
||||
return $settings;
|
||||
}
|
||||
|
||||
$result = [];
|
||||
foreach ($keys as $key) {
|
||||
$result[$key] = $settings[$key] ?? null;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge-update settings for a tenant using atomic $set on sub-fields.
|
||||
*
|
||||
* @param string $identifier Tenant identifier
|
||||
* @param array<string, mixed> $settings Key-value pairs to persist
|
||||
*/
|
||||
public function storeSettings(string $identifier, array $settings): bool
|
||||
{
|
||||
$updates = [];
|
||||
foreach ($settings as $key => $value) {
|
||||
$updates["settings.{$key}"] = $value;
|
||||
}
|
||||
|
||||
$result = $this->dataStore->selectCollection(self::COLLECTION_NAME)->updateOne(
|
||||
['identifier' => $identifier],
|
||||
['$set' => $updates]
|
||||
);
|
||||
|
||||
return $result->getMatchedCount() > 0;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user