* Get the data from a data source; * * @param int $datasourceId * @param $datasetMetadata * @param bool $allowCacheValidation * @return array|NotFoundException */
(int $datasourceId, $datasetMetadata, bool $allowCacheValidation = true)
| 204 | * @return array|NotFoundException |
| 205 | */ |
| 206 | #[NoAdminRequired] |
| 207 | public function read(int $datasourceId, $datasetMetadata, bool $allowCacheValidation = true) { |
| 208 | if (!$this->getDatasources()[$datasourceId]) { |
| 209 | $result['error'] = $this->l10n->t('Data source not available anymore'); |
| 210 | return $result; |
| 211 | } |
| 212 | |
| 213 | $option = array(); |
| 214 | // before 3.1.0, the options were in another format. as of 3.1.0 the standard option array is used |
| 215 | if ($datasetMetadata['link'][0] !== '{') { |
| 216 | $option['link'] = $datasetMetadata['link']; |
| 217 | } else { |
| 218 | $option = json_decode($datasetMetadata['link'], true); |
| 219 | } |
| 220 | unset($option['cacheKey']); |
| 221 | $option['user_id'] = $datasetMetadata['user_id']; |
| 222 | if (isset($option['link']) && in_array($datasourceId, [ |
| 223 | self::DATASET_TYPE_LOCAL_CSV, |
| 224 | self::DATASET_TYPE_LOCAL_SPREADSHEET, |
| 225 | self::DATASET_TYPE_LOCAL_JSON, |
| 226 | ], true)) { |
| 227 | $option['link'] = $this->VariableService->replaceDatasourceText((string)$option['link']); |
| 228 | } |
| 229 | if ($allowCacheValidation && isset($datasetMetadata['cacheKey']) && $datasetMetadata['cacheKey'] !== '') { |
| 230 | $option['cacheKey'] = $datasetMetadata['cacheKey']; |
| 231 | } |
| 232 | |
| 233 | try { |
| 234 | // read the data from the source |
| 235 | $result = $this->getDatasources()[$datasourceId]->readData($option); |
| 236 | if (isset($result['cache']['notModified']) && $result['cache']['notModified'] === true) { |
| 237 | return $result; |
| 238 | } |
| 239 | |
| 240 | // if data source should be timestamped/snapshoted |
| 241 | if (isset($option['timestamp']) && ($option['timestamp'] === 'true' || $option['timestamp'] === 'filename')) { |
| 242 | $timestamp = $this->getDatasourceTimestamp($option); |
| 243 | if ($timestamp === null) { |
| 244 | return [ |
| 245 | 'error' => $this->l10n->t('No valid timestamp found in datasource filename'), |
| 246 | 'data' => [], |
| 247 | 'status' => 'nodata', |
| 248 | ]; |
| 249 | } |
| 250 | |
| 251 | $result['data'] = array_map(function ($tag) use ($timestamp) { |
| 252 | $columns = count($tag); |
| 253 | if ($columns > 1) { |
| 254 | // shift values by one dimension and stores date in second column |
| 255 | return array($tag[$columns - 2], $timestamp, $tag[$columns - 1]); |
| 256 | } else { |
| 257 | // just return 2 columns if the original data only has one column |
| 258 | return array($timestamp, $tag[$columns - 1]); |
| 259 | } |
| 260 | }, $result['data']); |
| 261 | } |
| 262 | |
| 263 | \OCA\Analytics\Service\PanoramaFilterService::validateDimensions( |
no test coverage detected