| 14 | use OCA\Analytics\Exception\FlexibleStorageException; |
| 15 | |
| 16 | class DatasetStorageResolver { |
| 17 | public const LEGACY = 'legacy'; |
| 18 | public const FLEXIBLE_SHARED = 'flexible_shared'; |
| 19 | |
| 20 | public function __construct( |
| 21 | private DatasetMapper $datasetMapper, |
| 22 | private StorageMapper $legacyMapper, |
| 23 | private FlexibleStorageMapper $flexibleMapper, |
| 24 | ) { |
| 25 | } |
| 26 | |
| 27 | /** @return array{dataset:array<string,mixed>,mode:string,mapper:StorageMapper|FlexibleStorageMapper,tables:array{columns:?string,records:string,values:?string}} */ |
| 28 | public function resolve(int $datasetId, bool $ownerOnly = false): array { |
| 29 | $dataset = $ownerOnly ? $this->datasetMapper->readOwn($datasetId) : $this->datasetMapper->read($datasetId); |
| 30 | if (!is_array($dataset) || $dataset === []) { |
| 31 | throw new FlexibleStorageException('dataset_not_found', 'The dataset does not exist or is not accessible.', ['datasetId' => $datasetId], 404); |
| 32 | } |
| 33 | |
| 34 | $mode = (string)($dataset['storage_mode'] ?? self::LEGACY); |
| 35 | [$mapper, $tables] = match ($mode) { |
| 36 | self::LEGACY => [$this->legacyMapper, ['columns' => null, 'records' => 'analytics_facts', 'values' => null]], |
| 37 | self::FLEXIBLE_SHARED => [$this->flexibleMapper, ['columns' => 'analytics_flex_columns', 'records' => 'analytics_flex_records', 'values' => 'analytics_flex_values']], |
| 38 | default => throw new FlexibleStorageException('unsupported_storage_mode', 'The dataset uses an unsupported storage mode.', ['datasetId' => $datasetId, 'storageMode' => $mode], 409), |
| 39 | }; |
| 40 | |
| 41 | return ['dataset' => $dataset, 'mode' => $mode, 'mapper' => $mapper, 'tables' => $tables]; |
| 42 | } |
| 43 | } |
nothing calls this directly
no outgoing calls
no test coverage detected