@@ -255,9 +255,6 @@ private function exportDocuments(int $batchSize): void
255255
256256 $ documentId = $ parsedData ['$id ' ] ?? 'unique() ' ;
257257
258- // `$id`, `$permissions` in the doc can cause issues!
259- unset($ parsedData ['$id ' ], $ parsedData ['$permissions ' ]);
260-
261258 $ document = new Document ($ documentId , $ collection , $ parsedData );
262259 $ buffer [] = $ document ;
263260
@@ -348,25 +345,22 @@ private function withCsvStream(callable $callback): void
348345 */
349346 private function validateCSVHeaders (array $ headers , array $ attributeTypes ): void
350347 {
351- $ expectedAttributes = array_keys ($ attributeTypes );
352-
353- // Ignore keys like $id, $permissions, etc.
354- $ filteredHeaders = array_filter ($ headers , fn ($ key ) => ! str_starts_with ($ key , '$ ' ));
355-
356- $ extraAttributes = array_diff ($ filteredHeaders , $ expectedAttributes );
357- $ missingAttributes = array_diff ($ expectedAttributes , $ filteredHeaders );
348+ $ internalAttributes = ['$id ' , '$permissions ' , '$createdAt ' , '$updatedAt ' ];
349+ $ expectedAttributes = \array_keys ($ attributeTypes );
350+ $ extraAttributes = \array_diff ($ headers , $ expectedAttributes , $ internalAttributes );
351+ $ missingAttributes = \array_diff ($ expectedAttributes , $ headers );
358352
359353 if (! empty ($ missingAttributes ) || ! empty ($ extraAttributes )) {
360354 $ messages = [];
361355
362356 if (! empty ($ missingAttributes )) {
363357 $ label = count ($ missingAttributes ) === 1 ? 'Missing attribute ' : 'Missing attributes ' ;
364- $ messages [] = "{ $ label} : ' " .implode ("', ' " , $ missingAttributes )."' " ;
358+ $ messages [] = "$ label: ' " .implode ("', ' " , $ missingAttributes )."' " ;
365359 }
366360
367361 if (! empty ($ extraAttributes )) {
368362 $ label = count ($ extraAttributes ) === 1 ? 'Unexpected attribute ' : 'Unexpected attributes ' ;
369- $ messages [] = "{ $ label} : ' " .implode ("', ' " , $ extraAttributes )."' " ;
363+ $ messages [] = "$ label: ' " .implode ("', ' " , $ extraAttributes )."' " ;
370364 }
371365
372366 throw new \Exception ('CSV header mismatch. ' .implode (' | ' , $ messages ));
0 commit comments