File tree Expand file tree Collapse file tree
src/Migration/Destinations Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -275,10 +275,27 @@ protected function convertArrayToCSV(array $value): string
275275 if (empty ($ value )) {
276276 return '' ;
277277 }
278+
278279 if (isset ($ value ['$id ' ])) {
279280 return $ value ['$id ' ];
280281 }
281- return \json_encode ($ value );
282+
283+ $ isStringArray = \array_reduce (
284+ $ value ,
285+ fn ($ carry , $ item ) => $ carry && is_string ($ item ),
286+ true
287+ );
288+
289+ if ($ isStringArray ) {
290+ // For string arrays, escape quotes and join with commas
291+ return \implode (', ' , \array_map (
292+ fn ($ item ) => \str_replace ('" ' , '"" ' , $ item ),
293+ $ value
294+ ));
295+ }
296+
297+ // For complex arrays, use JSON with escaped quotes
298+ return \str_replace ('" ' , '"" ' , \json_encode ($ value ));
282299 }
283300
284301 /**
@@ -289,7 +306,8 @@ protected function convertObjectToCSV($value): string
289306 if ($ value instanceof Row) {
290307 return $ value ->getId ();
291308 }
292- return \json_encode ($ value );
309+
310+ // Escape quotes for CSV by doubling them
311+ return \str_replace ('" ' , '"" ' , \json_encode ($ value ));
293312 }
294-
295313}
You can’t perform that action at this time.
0 commit comments