@@ -649,26 +649,24 @@ protected function truncateFields(Collection $collection, array &$generatedRow):
649649 }
650650
651651 if ($ indexedFields !== [] && isset ($ generatedRow ['value ' ]) && is_array ($ generatedRow ['value ' ])) {
652- // Iterate over generated rows BY REFERENCE (&) - we are going to modify the contents of $field
653- foreach ($ generatedRow as &$ field ) {
654- foreach ($ indexedFields as $ indexedFieldname ) {
655- // The key will have the index name in the following format added to it.
656- // Adjust the max key size allowed to take it into account.
657- $ maxKeySize = 1020 - strlen ('value_ ' . $ indexedFieldname . '_1 ' );
658-
659- // It's important that we count the number of bytes
660- // in the field - not just the number of characters.
661- // UTF-8 characters can be between 1 and 4 bytes.
662- //
663- // From the strlen documentation:
664- // Attention with utf8:
665- // $foo = "bär";
666- // strlen($foo) will return 4 and not 3 as expected..
667- //
668- // So strlen does count the bytes - not the characters.
669- if (array_key_exists ($ indexedFieldname , $ field ) && (is_string ($ field [$ indexedFieldname ]) && strlen ($ field [$ indexedFieldname ]) > $ maxKeySize )) {
670- $ field [$ indexedFieldname ] = substr ($ field [$ indexedFieldname ], 0 , $ maxKeySize );
671- }
652+ $ value = &$ generatedRow ['value ' ];
653+ foreach ($ indexedFields as $ indexedFieldname ) {
654+ // The key will have the index name in the following format added to it.
655+ // Adjust the max key size allowed to take it into account.
656+ $ maxKeySize = 1020 - strlen ('value_ ' . $ indexedFieldname . '_1 ' );
657+
658+ // It's important that we count the number of bytes
659+ // in the field - not just the number of characters.
660+ // UTF-8 characters can be between 1 and 4 bytes.
661+ //
662+ // From the strlen documentation:
663+ // Attention with utf8:
664+ // $foo = "bär";
665+ // strlen($foo) will return 4 and not 3 as expected..
666+ //
667+ // So strlen does count the bytes - not the characters.
668+ if (array_key_exists ($ indexedFieldname , $ value ) && (is_string ($ value [$ indexedFieldname ]) && strlen ($ value [$ indexedFieldname ]) > $ maxKeySize )) {
669+ $ value [$ indexedFieldname ] = substr ($ value [$ indexedFieldname ], 0 , $ maxKeySize );
672670 }
673671 }
674672 }
0 commit comments