diff --git a/src/Extension/BaseElementExtension.php b/src/Extension/BaseElementExtension.php index a432946..535d49b 100644 --- a/src/Extension/BaseElementExtension.php +++ b/src/Extension/BaseElementExtension.php @@ -243,6 +243,7 @@ public function onBeforeDelete() $firstVirtual = $this->getVirtualElements()->First(); $wasPublished = false; } + if ($firstVirtual) { $clone = $this->owner->duplicate(false); @@ -251,9 +252,11 @@ public function onBeforeDelete() $clone->Sort = $firstVirtual->Sort; $clone->write(); + if ($wasPublished) { - $clone->doPublish(); - $firstVirtual->doUnpublish(); + $clone->publishRecursive(); + + $firstVirtual->doArchive(); } // clone has a new ID, so need to repoint @@ -262,14 +265,18 @@ public function onBeforeDelete() if ($virtual->ID == $firstVirtual->ID) { continue; } + $pub = false; + if ($virtual->isPublished()) { $pub = true; } + $virtual->LinkedElementID = $clone->ID; $virtual->write(); + if ($pub) { - $virtual->doPublish(); + $virtual->publishRecursive(); } }