diff --git a/components/ILIAS/HTMLLearningModule/classes/class.ilObjFileBasedLM.php b/components/ILIAS/HTMLLearningModule/classes/class.ilObjFileBasedLM.php
index eddaac649046..f5919b73a371 100755
--- a/components/ILIAS/HTMLLearningModule/classes/class.ilObjFileBasedLM.php
+++ b/components/ILIAS/HTMLLearningModule/classes/class.ilObjFileBasedLM.php
@@ -231,7 +231,12 @@ public function cloneObject(int $target_id, int $copy_id = 0, bool $omit_tree =
}
// copy content
- $new_obj->populateByDirectoy($this->getDataDirectory());
+ $this->cloneContainerResource($new_obj);
+
+ // copy legacy content (only relevant for not yet migrated modules)
+ if (is_dir($this->getDataDirectory())) {
+ $new_obj->populateByDirectoy($this->getDataDirectory());
+ }
$new_obj->setStartFile((string) $this->getStartFile());
$new_obj->update();
@@ -239,6 +244,31 @@ public function cloneObject(int $target_id, int $copy_id = 0, bool $omit_tree =
return $new_obj;
}
+ /**
+ * Replace the empty container resource of the target object (created in
+ * ilObjFileBasedLM::create()) by a clone of this object's container.
+ */
+ protected function cloneContainerResource(ilObjFileBasedLM $new_obj): void
+ {
+ $source = $this->getResource();
+ if ($source === null) {
+ return;
+ }
+
+ $target = $new_obj->getResource();
+ if ($target !== null) {
+ $this->irss->manageContainer()->remove(
+ $target->getIdentification(),
+ new ilHTLMStakeholder()
+ );
+ }
+
+ $cloned_rid = $this->irss->manageContainer()->clone(
+ $source->getIdentification()
+ );
+ $new_obj->setRID($cloned_rid->serialize());
+ }
+
public function isInfoEnabled(): bool
{
return ilObjContentObjectAccess::isInfoEnabled($this->getId());