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

Method importDatasets

lib/UserMigration/AnalyticsMigrator.php:163–198  ·  view source on GitHub ↗

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

(string $uid, array $rows)

Source from the content-addressed store, hash-verified

161 * @throws Exception
162 */
163 private function importDatasets(string $uid, array $rows): array {
164 $idMap = [];
165
166 foreach ($rows as $row) {
167 if (!isset($row['id'])) {
168 continue;
169 }
170
171 $oldId = (int)$row['id'];
172 $newId = $this->insertAndReturnId('analytics_dataset', [
173 'user_id' => $uid,
174 'name' => $row['name'] ?? '',
175 'subheader' => $row['subheader'] ?? null,
176 'dimension1' => $row['dimension1'] ?? '',
177 'dimension2' => $row['dimension2'] ?? '',
178 'value' => $row['value'] ?? '',
179 'type' => isset($row['type']) ? (int)$row['type'] : 0,
180 'parent' => 0,
181 'ai_index' => isset($row['ai_index']) ? (int)$row['ai_index'] : 0,
182 ]);
183 $idMap[$oldId] = $newId;
184 }
185
186 foreach ($rows as $row) {
187 if (!isset($row['id']) || !isset($idMap[(int)$row['id']])) {
188 continue;
189 }
190
191 $newId = $idMap[(int)$row['id']];
192 $oldParent = isset($row['parent']) ? (int)$row['parent'] : 0;
193 $newParent = $oldParent === 0 ? 0 : ($idMap[$oldParent] ?? 0);
194 $this->updateById('analytics_dataset', $newId, ['parent' => $newParent]);
195 }
196
197 return $idMap;
198 }
199
200 /**
201 * @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