@@ -312,18 +312,19 @@ private function validate(): string|false
312312
313313 $ analysis = $ this ->mappingAnalysis ();
314314
315- if (empty ( $ analysis ['mismatches ' ]) ) {
315+ if (! $ analysis ['hasChanges ' ] ) {
316316 $ this ->omni ->success ('Mapping already matches - nothing to re-index ' );
317317 $ this ->newLine ();
318318
319319 return false ;
320320 }
321321
322- $ fieldsToUpdate = $ this ->formatMismatchesForDisplay ($ analysis ['mismatches ' ]);
323- $ this ->omni ->dataList ($ fieldsToUpdate , 'Fields to Update ' , 'text-emerald-500 ' );
322+ if (! empty ($ analysis ['newMappings ' ])) {
323+ $ this ->omni ->dataList ($ analysis ['newMappings ' ], 'New Mappings ' , 'text-emerald-500 ' );
324+ }
324325
325- if (! empty ($ analysis ['unmapped ' ])) {
326- $ this ->omni ->dataList ($ this -> nestDotNotation ( $ analysis ['unmapped ' ]) , 'Unmapped Fields ' , 'text-rose-500 ' );
326+ if (! empty ($ analysis ['changedMappings ' ])) {
327+ $ this ->omni ->dataList ($ analysis ['changedMappings ' ] , 'Changed/Removed Mappings ' , 'text-rose-500 ' );
327328 }
328329
329330 return 'CREATE_TEMP ' ;
@@ -686,68 +687,20 @@ private function mappingAnalysis(): array
686687 'properties ' => $ this ->schema ->compileMapping ($ this ->mappingDefinition ),
687688 ]);
688689
689- $ desiredFields = array_keys ( $ desiredMapping );
690- $ mismatches = [] ;
690+ $ currentFlat = collect ( $ currentMapping )-> dot ( );
691+ $ desiredFlat = collect ( $ desiredMapping )-> dot () ;
691692
692- foreach ($ desiredMapping as $ field => $ desired ) {
693- $ current = $ currentMapping [$ field ] ?? null ;
694- if ($ current === $ desired ) {
695- continue ;
696- }
697-
698- $ mismatches [$ field ] = [
699- 'current ' => ($ current ['type ' ] ?? null ) ?? 'missing ' ,
700- 'desired ' => $ desired ['type ' ] ?? 'unknown ' ,
701- ];
702- }
703-
704- $ unmapped = [];
705- foreach ($ currentMapping as $ field => $ details ) {
706- if (isset ($ desiredMapping [$ field ])) {
707- continue ;
708- }
709- $ unmapped [$ field ] = $ details ['type ' ] ?? 'object ' ;
710- }
693+ $ changedMappings = $ currentFlat ->diffAssoc ($ desiredFlat );
694+ $ newMappings = $ desiredFlat ->diffAssoc ($ currentFlat );
695+ $ hasChanges = $ changedMappings ->count () || $ newMappings ->count ();
711696
712697 return [
713- 'mismatches ' => $ mismatches ,
714- 'unmapped ' => $ unmapped ,
698+ 'changedMappings ' => $ changedMappings ->undot ()->toArray (),
699+ 'newMappings ' => $ newMappings ->undot ()->toArray (),
700+ 'hasChanges ' => $ hasChanges ,
715701 ];
716702 }
717703
718- private function formatMismatchesForDisplay (array $ mismatches ): array
719- {
720- $ display = [];
721- foreach ($ mismatches as $ field => $ info ) {
722- $ label = $ info ['current ' ].' → ' .$ info ['desired ' ];
723- if (empty ($ info ['details ' ])) {
724- $ display [$ field ] = $ label ;
725-
726- continue ;
727- }
728- $ display [$ field ] = [$ label => $ info ['details ' ]];
729- }
730-
731- return $ display ;
732- }
733-
734- private function nestDotNotation (array $ flat ): array
735- {
736- $ nested = [];
737- foreach ($ flat as $ key => $ value ) {
738- $ parts = explode ('. ' , $ key );
739- if (count ($ parts ) === 1 ) {
740- $ nested [$ key ] = $ value ;
741-
742- continue ;
743- }
744- $ parent = array_shift ($ parts );
745- $ nested [$ parent ][implode ('. ' , $ parts )] = $ value ;
746- }
747-
748- return $ nested ;
749- }
750-
751704 private function confirmSettings (): bool
752705 {
753706 $ this ->omni ->dataList ([
0 commit comments