|
117 | 117 | $userAttributes = JsonUtility::jsonToSetString(json_encode($userAttributes), 'user_attributes'); |
118 | 118 | $usersService->saveUserAttributes($userAttributes, $user['user_id']); |
119 | 119 |
|
| 120 | + // Collect all items from the streaming parser into an array |
| 121 | + // so we can sort by sortOrder if provided |
| 122 | + $dataItems = []; |
| 123 | + foreach ($input as $key => $item) { |
| 124 | + $dataItems[$key] = $item; |
| 125 | + } |
| 126 | + |
| 127 | + // Sort by sortOrder if any items have it |
| 128 | + $hasSortOrder = array_filter($dataItems, fn($item) => isset($item['sortOrder'])); |
| 129 | + if ($hasSortOrder !== []) { |
| 130 | + uasort($dataItems, function ($a, $b) { |
| 131 | + $sortA = $a['sortOrder'] ?? PHP_INT_MAX; |
| 132 | + $sortB = $b['sortOrder'] ?? PHP_INT_MAX; |
| 133 | + return $sortA <=> $sortB; |
| 134 | + }); |
| 135 | + } |
| 136 | + |
120 | 137 | $responseData = []; |
121 | 138 | $dataCounter = 0; |
122 | | - foreach ($input as $rootKey => $data) { |
| 139 | + foreach ($dataItems as $rootKey => $data) { |
123 | 140 | $dataCounter++; |
124 | 141 |
|
125 | 142 |
|
|
622 | 639 | } |
623 | 640 | } |
624 | 641 |
|
625 | | - if ($noOfFailedRecords > 0 && $noOfFailedRecords == iterator_count($input)) { |
| 642 | + if ($noOfFailedRecords > 0 && $noOfFailedRecords == $dataCounter) { |
626 | 643 | $payloadStatus = 'failed'; |
627 | 644 | } elseif ($noOfFailedRecords > 0) { |
628 | 645 | $payloadStatus = 'partial'; |
|
661 | 678 |
|
662 | 679 |
|
663 | 680 | $payload = JsonUtility::encodeUtf8Json($payload); |
664 | | -$general->addApiTracking($transactionId, $user['user_id'], iterator_count($input), 'save-request', 'covid19', $_SERVER['REQUEST_URI'], $origJson, $payload, 'json', null, null, $authToken); |
| 681 | +$general->addApiTracking($transactionId, $user['user_id'], $dataCounter, 'save-request', 'covid19', $_SERVER['REQUEST_URI'], $origJson, $payload, 'json', null, null, $authToken); |
665 | 682 |
|
666 | 683 | $general->updateResultSyncDateTime('covid19', null, $updatedLabs); |
667 | 684 |
|
|
0 commit comments