public function copyRecursive($target, $source)
{
// avoid recursion
if (!$this->_copyRecursiveIds) {
$this->_copyRecursiveIds = [];
}
if (in_array($source->getId(), $this->_copyRecursiveIds)) {
return;
}
if (method_exists($source, "getElements")) {
$source->getElements();
}
$source->getProperties();
$new = clone $source;
$new->id = null;
$new->setChilds(null);
$new->setKey(Element\Service::getSaveCopyName("document", $new->getKey(), $target));
$new->setParentId($target->getId());
$new->setUserOwner($this->_user->getId());
$new->setUserModification($this->_user->getId());
$new->setDao(null);
$new->setLocked(false);
$new->setCreationDate(time());
if (method_exists($new, "setPrettyUrl")) {
$new->setPrettyUrl(null);
}
$new->save();
// add to store
$this->_copyRecursiveIds[] = $new->getId();
foreach ($source->getChilds() as $child) {
$this->copyRecursive($new, $child);
}
$this->updateChilds($target, $new);
// triggers actions after the complete document cloning
\Pimcore::getEventManager()->trigger('document.postCopy', $new, ['base_element' => $source]);
return $new;
}