Fix events import payload decoding and programme link remapping.
Deploy Ladill Events / deploy (push) Successful in 25s
Deploy Ladill Events / deploy (push) Successful in 25s
Decode JSON-string payloads from the platform export so event content, covers, and programme references import correctly. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -61,6 +61,9 @@ class ImportEventsCommand extends Command
|
||||
foreach ($payload['qr_codes'] ?? [] as $row) {
|
||||
$this->importCode($row, $commit);
|
||||
}
|
||||
if ($commit) {
|
||||
$this->remapAllProgrammeLinks();
|
||||
}
|
||||
foreach ($payload['qr_event_registrations'] ?? [] as $row) {
|
||||
$this->importRegistration($row, $commit);
|
||||
}
|
||||
@@ -127,17 +130,24 @@ class ImportEventsCommand extends Command
|
||||
'user_id',
|
||||
])->all();
|
||||
$attrs['user_id'] = $user->id;
|
||||
$attrs = $this->normalizeJsonAttributes($attrs, ['payload']);
|
||||
|
||||
if ($commit) {
|
||||
$code = QrCode::updateOrCreate(['short_code' => $shortCode], $attrs);
|
||||
$this->codeMap[$platformId] = $code->id;
|
||||
$this->remapProgrammeLinks($code);
|
||||
$this->copyCodeAssets($code);
|
||||
} else {
|
||||
$this->codeMap[$platformId] = $platformId;
|
||||
}
|
||||
}
|
||||
|
||||
private function remapAllProgrammeLinks(): void
|
||||
{
|
||||
QrCode::query()
|
||||
->where('type', QrCode::TYPE_EVENT)
|
||||
->each(fn (QrCode $code) => $this->remapProgrammeLinks($code));
|
||||
}
|
||||
|
||||
private function remapProgrammeLinks(QrCode $code): void
|
||||
{
|
||||
if ($code->type !== QrCode::TYPE_EVENT) {
|
||||
@@ -151,7 +161,30 @@ class ImportEventsCommand extends Command
|
||||
}
|
||||
|
||||
$content['programme_qr_id'] = $this->codeMap[$programmeId];
|
||||
$code->update(['content' => $content]);
|
||||
$payload = $code->payload ?? [];
|
||||
$payload['content'] = $content;
|
||||
$code->update(['payload' => $payload]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $attrs
|
||||
* @param list<string> $keys
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
private function normalizeJsonAttributes(array $attrs, array $keys): array
|
||||
{
|
||||
foreach ($keys as $key) {
|
||||
if (! isset($attrs[$key]) || ! is_string($attrs[$key])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$decoded = json_decode($attrs[$key], true);
|
||||
if (is_array($decoded)) {
|
||||
$attrs[$key] = $decoded;
|
||||
}
|
||||
}
|
||||
|
||||
return $attrs;
|
||||
}
|
||||
|
||||
/** @param array<string,mixed> $row */
|
||||
|
||||
Reference in New Issue
Block a user