@@ -46,14 +46,23 @@ public function export()
4646
4747 $ errors = [];
4848
49- foreach ($ records -> items () as $ record ) {
49+ if ($ currentExportingFolder === ImportDataHelper:: FOLDER_IDENTIFIER_NAVIGATION ) {
5050
51- $ this ->processRecordForImportUsed (
51+ $ this ->processNavigationRecordsForImportUsed (
52+ $ records ->items (),
53+ $ fs ,
54+ (Arr::get ($ subFolders , ImportDataHelper::FOLDER_IDENTIFIER_NAVIGATION ) ?? $ folderName ),
55+ $ errors ,
56+ );
57+
58+ } else {
59+
60+ collect ($ records ->items ())->each (fn ($ record ) => $ this ->processRecordForImportUsed (
5261 $ record ,
5362 $ fs ,
5463 (Arr::get ($ subFolders , $ currentExportingFolder ) ?? $ folderName ),
5564 $ errors ,
56- );
65+ )) ;
5766 }
5867
5968 $ processingData = $ this ->record ->getProcessingMessages ();
@@ -113,7 +122,7 @@ private function getRecordsToExport()
113122
114123 $ allRecord = $ query ->get ();
115124
116- $ tree = $ allRecord ->toTree ();
125+ $ tree = $ allRecord ->groupBy ( ' category ' )-> map ( fn ( $ r ) => $ r -> toTree () );
117126 $ totalTreeItems = count ($ tree );
118127
119128 $ perPage = $ totalTreeItems ;
@@ -263,4 +272,47 @@ protected static function getBaseQueryForModel(string $type)
263272
264273 return null ;
265274 }
275+
276+ protected function processNavigationRecordsForImportUsed (
277+ $ records ,
278+ $ fs ,
279+ ?string $ dir ,
280+ array &$ errors ,
281+ ) {
282+ try {
283+ foreach ($ records as $ key => $ record ) {
284+ // Already grouped by category, $key = category
285+ if (! $ record instanceof Model) {
286+ foreach ($ record as $ index => $ modelNavigation ) {
287+ try {
288+
289+ $ filename = "{$ key }_ {$ index }.json " ;
290+
291+
292+ $ content = $ this ->prepareImportContentFromModel ($ modelNavigation );
293+
294+ $ path = $ dir . '/ ' . $ filename ;
295+ $ fs ->put ($ path , $ content );
296+
297+ } catch (\Throwable $ th ) {
298+ $ errors [] = [
299+ 'record ' => $ record ->getKey (),
300+ 'model ' => get_class ($ record ),
301+ 'message ' => $ th ->getMessage (),
302+ ];
303+ }
304+
305+ }
306+ } else {
307+ $ this ->processRecordForImportUsed ($ record , $ fs , $ dir , $ errors );
308+ }
309+ }
310+ } catch (\Throwable $ th ) {
311+ $ errors [] = [
312+ 'record ' => null ,
313+ 'model ' => Navigation::class,
314+ 'message ' => $ th ->getMessage (),
315+ ];
316+ }
317+ }
266318}
0 commit comments