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->getRealFullPath() . "@", $targetParent . "/", $source->getRealPath());
$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();
} elseif ($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(["success" => false, "message" => "missing_permission"]);
}
}
$this->_helper->json(["success" => $success]);
}