public copyContents ( $target, $source ) : mixed | ||
$target | ||
$source | ||
return | mixed |
public function copyContents($target, $source)
{
// check if the type is the same
if (get_class($source) != get_class($target)) {
throw new \Exception("Source and target have to be the same type");
}
if ($source instanceof Document\PageSnippet) {
$target->setElements($source->getElements());
$target->setTemplate($source->getTemplate());
$target->setAction($source->getAction());
$target->setController($source->getController());
if ($source instanceof Document\Page) {
$target->setTitle($source->getTitle());
$target->setDescription($source->getDescription());
}
} elseif ($source instanceof Document\Link) {
$target->setInternalType($source->getInternalType());
$target->setInternal($source->getInternal());
$target->setDirect($source->getDirect());
$target->setLinktype($source->getLinktype());
$target->setTarget($source->getTarget());
$target->setParameters($source->getParameters());
$target->setAnchor($source->getAnchor());
$target->setTitle($source->getTitle());
$target->setAccesskey($source->getAccesskey());
$target->setRel($source->getRel());
$target->setTabindex($source->getTabindex());
}
$target->setUserModification($this->_user->getId());
$target->setProperties($source->getProperties());
$target->save();
return $target;
}
public function copyAction() { $success = false; $sourceId = intval($this->getParam("sourceId")); $source = Document::getById($sourceId); $session = Session::get("pimcore_copy"); $targetId = intval($this->getParam("targetId")); if ($this->getParam("targetParentId")) { $sourceParent = Document::getById($this->getParam("sourceParentId")); // this is because the key can get the prefix "_copy" if the target does already exists if ($session->{$this->getParam("transactionId")}["parentId"]) { $targetParent = Document::getById($session->{$this->getParam("transactionId")}["parentId"]); } else { $targetParent = Document::getById($this->getParam("targetParentId")); } $targetPath = preg_replace("@^" . $sourceParent->getFullPath() . "@", $targetParent . "/", $source->getPath()); $target = Document::getByPath($targetPath); } else { $target = Document::getById($targetId); } if ($target instanceof Document) { if ($target->isAllowed("create")) { if ($source != null) { if ($this->getParam("type") == "child") { $enableInheritance = $this->getParam("enableInheritance") == "true" ? true : false; $resetIndex = $this->getParam("resetIndex") == "true" ? true : false; $newDocument = $this->_documentService->copyAsChild($target, $source, $enableInheritance, $resetIndex); $session->{$this->getParam("transactionId")}["idMapping"][(int) $source->getId()] = (int) $newDocument->getId(); // this is because the key can get the prefix "_copy" if the target does already exists if ($this->getParam("saveParentId")) { $session->{$this->getParam("transactionId")}["parentId"] = $newDocument->getId(); } Session::writeClose(); } else { if ($this->getParam("type") == "replace") { $this->_documentService->copyContents($target, $source); } } $success = true; } else { \Logger::error("prevended copy/paste because document with same path+key already exists in this location"); } } else { \Logger::error("could not execute copy/paste because of missing permissions on target [ " . $targetId . " ]"); $this->_helper->json(array("success" => false, "message" => "missing_permission")); } } $this->_helper->json(array("success" => $success)); }