public static function getSaveCopyName($type, $sourceKey, $target)
{
if (self::pathExists($target->getRealFullPath() . "/" . $sourceKey, $type)) {
// only for assets: add the prefix _copy before the file extension (if exist) not after to that source.jpg will be source_copy.jpg and not source.jpg_copy
if ($type == "asset" && ($fileExtension = File::getFileExtension($sourceKey))) {
$sourceKey = str_replace("." . $fileExtension, "_copy." . $fileExtension, $sourceKey);
} else {
$sourceKey .= "_copy";
}
return self::getSaveCopyName($type, $sourceKey, $target);
}
return $sourceKey;
}
/** * @param AbstractObject $target * @param AbstractObject $source * @return AbstractObject copied object */ public function copyAsChild($target, $source) { //load properties $source->getProperties(); //load all in case of lazy loading fields self::loadAllObjectFields($source); $new = clone $source; $new->o_id = null; $new->setChilds(null); $new->setKey(Element\Service::getSaveCopyName("object", $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()); $new->save(); // $this->updateChilds($target, $new); return $new; }