Course: Fix export mbz validation, root-only resources, skip empty folders - refs BT#21977

pull/5995/head
Christian Beeznest 9 months ago
parent c60a4e23f5
commit 542765cb63
  1. 27
      main/inc/lib/moodleexport/FolderExport.php
  2. 34
      main/inc/lib/moodleexport/MoodleExport.php

@ -42,19 +42,26 @@ class FolderExport extends ActivityExport
/**
* 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;
}
/**

@ -404,15 +404,33 @@ class MoodleExport
$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)

Loading…
Cancel
Save