Skip to content

Commit 8a7a108

Browse files
authored
Merge pull request #5995 from christianbeeznest/Aix-21977-5
Course: Fix export mbz validation, root-only resources, skip empty folders - refs BT#21977
2 parents c60a4e2 + 542765c commit 8a7a108

File tree

2 files changed

+43
-18
lines changed

2 files changed

+43
-18
lines changed

main/inc/lib/moodleexport/FolderExport.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,26 @@ public function export($activityId, $exportDir, $moduleId, $sectionId): void
4242
/**
4343
* Get folder data dynamically from the course.
4444
*/
45-
public function getData(int $folderId, int $sectionId): array
45+
public function getData(int $folderId, int $sectionId): ?array
4646
{
4747
$folder = $this->course->resources['document'][$folderId];
4848

49-
return [
50-
'id' => $folderId,
51-
'moduleid' => $folder->source_id,
52-
'modulename' => 'folder',
53-
'contextid' => $folder->source_id,
54-
'name' => $folder->title,
55-
'sectionid' => $sectionId,
56-
'timemodified' => time(),
57-
];
49+
$folderPath = $folder->path . '/';
50+
foreach ($this->course->resources['document'] as $resource) {
51+
if ($resource->path !== $folder->path && str_starts_with($resource->path, $folderPath)) {
52+
return [
53+
'id' => $folderId,
54+
'moduleid' => $folder->source_id,
55+
'modulename' => 'folder',
56+
'contextid' => $folder->source_id,
57+
'name' => $folder->title,
58+
'sectionid' => $sectionId,
59+
'timemodified' => time(),
60+
];
61+
}
62+
}
63+
64+
return null;
5865
}
5966

6067
/**

main/inc/lib/moodleexport/MoodleExport.php

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -404,15 +404,33 @@ private function getActivities(): array
404404
$id = $resource->source_id;
405405
$title = $document['title'];
406406
} elseif ('file' === $resource->file_type) {
407-
$exportClass = ResourceExport::class;
408-
$moduleName = 'resource';
409-
$id = $resource->source_id;
410-
$title = $resource->title;
407+
$isRoot = substr_count($resource->path, '/') === 1;
408+
409+
if ($isRoot) {
410+
$exportClass = ResourceExport::class;
411+
$moduleName = 'resource';
412+
$id = $resource->source_id;
413+
$title = $resource->title;
414+
}
411415
} elseif ('folder' === $resource->file_type) {
412-
$exportClass = FolderExport::class;
413-
$moduleName = 'folder';
414-
$id = $resource->source_id;
415-
$title = $resource->title;
416+
$isEmpty = true;
417+
$folderPath = $resource->path . '/';
418+
419+
foreach ($this->course->resources['document'] as $childResource) {
420+
if (str_starts_with($childResource->path, $folderPath) && $childResource->path !== $resource->path) {
421+
$isEmpty = false;
422+
break;
423+
}
424+
}
425+
426+
$isRoot = substr_count($resource->path, '/') === 1;
427+
428+
if (!$isEmpty && $isRoot) {
429+
$exportClass = FolderExport::class;
430+
$moduleName = 'folder';
431+
$id = $resource->source_id;
432+
$title = $resource->title;
433+
}
416434
}
417435
}
418436
// Handle assignments (work)

0 commit comments

Comments
 (0)