* @param list > $rows * @param array $datasetMap * @return array * @throws Exception */
(string $uid, array $rows, array $datasetMap)
| 204 | * @throws Exception |
| 205 | */ |
| 206 | private function importReports(string $uid, array $rows, array $datasetMap): array { |
| 207 | $idMap = []; |
| 208 | |
| 209 | foreach ($rows as $row) { |
| 210 | if (!isset($row['id'])) { |
| 211 | continue; |
| 212 | } |
| 213 | |
| 214 | $oldId = (int)$row['id']; |
| 215 | $oldDataset = isset($row['dataset']) ? (int)$row['dataset'] : 0; |
| 216 | $newDataset = $oldDataset === 0 ? 0 : ($datasetMap[$oldDataset] ?? 0); |
| 217 | |
| 218 | $newId = $this->insertAndReturnId('analytics_report', [ |
| 219 | 'user_id' => $uid, |
| 220 | 'dataset' => $newDataset, |
| 221 | 'name' => $row['name'] ?? '', |
| 222 | 'subheader' => $row['subheader'] ?? null, |
| 223 | 'link' => $row['link'] ?? '', |
| 224 | 'type' => isset($row['type']) ? (int)$row['type'] : 0, |
| 225 | 'parent' => 0, |
| 226 | 'dimension1' => $row['dimension1'] ?? '', |
| 227 | 'dimension2' => $row['dimension2'] ?? '', |
| 228 | 'value' => $row['value'] ?? '', |
| 229 | 'chart' => $row['chart'] ?? 'line', |
| 230 | 'visualization' => $row['visualization'] ?? 'table', |
| 231 | 'chartoptions' => $row['chartoptions'] ?? null, |
| 232 | 'dataoptions' => $row['dataoptions'] ?? null, |
| 233 | 'filteroptions' => $row['filteroptions'] ?? null, |
| 234 | 'tableoptions' => $row['tableoptions'] ?? null, |
| 235 | 'refresh' => isset($row['refresh']) ? (int)$row['refresh'] : 0, |
| 236 | 'version' => isset($row['version']) ? (int)$row['version'] : 0, |
| 237 | ]); |
| 238 | $idMap[$oldId] = $newId; |
| 239 | } |
| 240 | |
| 241 | foreach ($rows as $row) { |
| 242 | if (!isset($row['id']) || !isset($idMap[(int)$row['id']])) { |
| 243 | continue; |
| 244 | } |
| 245 | |
| 246 | $newId = $idMap[(int)$row['id']]; |
| 247 | $oldParent = isset($row['parent']) ? (int)$row['parent'] : 0; |
| 248 | $newParent = $oldParent === 0 ? 0 : ($idMap[$oldParent] ?? 0); |
| 249 | $this->updateById('analytics_report', $newId, ['parent' => $newParent]); |
| 250 | } |
| 251 | |
| 252 | return $idMap; |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * @param list<array<string,mixed>> $rows |
no test coverage detected