MCPcopy Create free account
hub / github.com/Rello/analytics / importDatasets

Method importDatasets

lib/UserMigration/AnalyticsMigrator.php:174–211  ·  view source on GitHub ↗

* @param list > $rows * @return array * @throws Exception */

(string $uid, array $rows)

Source from the content-addressed store, hash-verified

172 * @throws Exception
173 */
174 private function importDatasets(string $uid, array $rows): array {
175 $idMap = [];
176
177 foreach ($rows as $row) {
178 if (!isset($row['id'])) {
179 continue;
180 }
181
182 $oldId = (int)$row['id'];
183 $newId = $this->insertAndReturnId('analytics_dataset', [
184 'user_id' => $uid,
185 'name' => $row['name'] ?? '',
186 'subheader' => $row['subheader'] ?? null,
187 'dimension1' => $row['dimension1'] ?? '',
188 'dimension2' => $row['dimension2'] ?? '',
189 'value' => $row['value'] ?? '',
190 'type' => isset($row['type']) ? (int)$row['type'] : 0,
191 'parent' => 0,
192 'ai_index' => isset($row['ai_index']) ? (int)$row['ai_index'] : 0,
193 'storage_mode' => $row['storage_mode'] ?? 'legacy',
194 'schema_version' => isset($row['schema_version']) ? (int)$row['schema_version'] : 0,
195 ]);
196 $idMap[$oldId] = $newId;
197 }
198
199 foreach ($rows as $row) {
200 if (!isset($row['id']) || !isset($idMap[(int)$row['id']])) {
201 continue;
202 }
203
204 $newId = $idMap[(int)$row['id']];
205 $oldParent = isset($row['parent']) ? (int)$row['parent'] : 0;
206 $newParent = $oldParent === 0 ? 0 : ($idMap[$oldParent] ?? 0);
207 $this->updateById('analytics_dataset', $newId, ['parent' => $newParent]);
208 }
209
210 return $idMap;
211 }
212
213 /**
214 * @param list<array<string,mixed>> $rows

Callers 1

importMethod · 0.95

Calls 2

insertAndReturnIdMethod · 0.95
updateByIdMethod · 0.95

Tested by

no test coverage detected