Skip to content

Commit 821578d

Browse files
committed
sort order for import content
1 parent 0dd0b7e commit 821578d

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/Services/ImportDataService.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,27 @@ protected function processForContent()
401401

402402
$this->guardAgaintsTableExist($model);
403403

404+
$reorderContent = function ($collection) {
405+
return collect($collection)
406+
->sortBy(function ($item, $contentKey) {
407+
408+
$slugSegments = explode('/', $contentKey);
409+
410+
$haveRootParent = collect($slugSegments)->contains('__root__');
411+
412+
$segmentCount = count($slugSegments);
413+
414+
//Higher Order if have root parent
415+
if ($haveRootParent) {
416+
return $segmentCount;
417+
}
418+
419+
return 999;
420+
});
421+
};
422+
423+
$this->pendingData['content'] = $reorderContent(collect($this->pendingData['content'] ?? []))->toArray();
424+
404425
foreach ($this->pendingData['content'] ?? [] as $contentKey => $item) {
405426

406427
try {

0 commit comments

Comments
 (0)