aboutsummaryrefslogtreecommitdiff
path: root/lib/models/Courseware/StructuralElement.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/models/Courseware/StructuralElement.php')
-rw-r--r--lib/models/Courseware/StructuralElement.php6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/models/Courseware/StructuralElement.php b/lib/models/Courseware/StructuralElement.php
index 9aa4f90..dbe2e62 100644
--- a/lib/models/Courseware/StructuralElement.php
+++ b/lib/models/Courseware/StructuralElement.php
@@ -817,6 +817,12 @@ SQL;
*/
public function copy(User $user, StructuralElement $parent, string $purpose = ''): StructuralElement
{
+ $ancestorIds = array_column($parent->findAncestors(), 'id');
+ $ancestorIds[] = $parent->id;
+ if (in_array($this->id, $ancestorIds)) {
+ throw new \InvalidArgumentException('Cannot copy into descendants.');
+ }
+
$file_ref_id = $this->copyImage($user, $parent);
$element = self::build([