Skip to content

Commit

Permalink
Merge pull request #5995 from christianbeeznest/Aix-21977-5
Browse files Browse the repository at this point in the history
Course: Fix export mbz validation, root-only resources, skip empty folders - refs BT#21977
  • Loading branch information
NicoDucou authored Dec 23, 2024
2 parents c60a4e2 + 542765c commit 8a7a108
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 18 deletions.
27 changes: 17 additions & 10 deletions main/inc/lib/moodleexport/FolderExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,26 @@ public function export($activityId, $exportDir, $moduleId, $sectionId): void
/**
* Get folder data dynamically from the course.
*/
public function getData(int $folderId, int $sectionId): array
public function getData(int $folderId, int $sectionId): ?array
{
$folder = $this->course->resources['document'][$folderId];

return [
'id' => $folderId,
'moduleid' => $folder->source_id,
'modulename' => 'folder',
'contextid' => $folder->source_id,
'name' => $folder->title,
'sectionid' => $sectionId,
'timemodified' => time(),
];
$folderPath = $folder->path . '/';
foreach ($this->course->resources['document'] as $resource) {
if ($resource->path !== $folder->path && str_starts_with($resource->path, $folderPath)) {
return [
'id' => $folderId,
'moduleid' => $folder->source_id,
'modulename' => 'folder',
'contextid' => $folder->source_id,
'name' => $folder->title,
'sectionid' => $sectionId,
'timemodified' => time(),
];
}
}

return null;
}

/**
Expand Down
34 changes: 26 additions & 8 deletions main/inc/lib/moodleexport/MoodleExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,15 +404,33 @@ private function getActivities(): array
$id = $resource->source_id;
$title = $document['title'];
} elseif ('file' === $resource->file_type) {
$exportClass = ResourceExport::class;
$moduleName = 'resource';
$id = $resource->source_id;
$title = $resource->title;
$isRoot = substr_count($resource->path, '/') === 1;

if ($isRoot) {
$exportClass = ResourceExport::class;
$moduleName = 'resource';
$id = $resource->source_id;
$title = $resource->title;
}
} elseif ('folder' === $resource->file_type) {
$exportClass = FolderExport::class;
$moduleName = 'folder';
$id = $resource->source_id;
$title = $resource->title;
$isEmpty = true;
$folderPath = $resource->path . '/';

foreach ($this->course->resources['document'] as $childResource) {
if (str_starts_with($childResource->path, $folderPath) && $childResource->path !== $resource->path) {
$isEmpty = false;
break;
}
}

$isRoot = substr_count($resource->path, '/') === 1;

if (!$isEmpty && $isRoot) {
$exportClass = FolderExport::class;
$moduleName = 'folder';
$id = $resource->source_id;
$title = $resource->title;
}
}
}
// Handle assignments (work)
Expand Down

0 comments on commit 8a7a108

Please sign in to comment.