/** * Copies object to target folder. * @param Folder $targetFolder Target folder. * @param int $updatedBy Id of user. * @param bool $generateUniqueName Generates unique name for object in directory. * @return BaseObject|null */ public function copyTo(Folder $targetFolder, $updatedBy, $generateUniqueName = false) { $this->errorCollection->clear(); /** @noinspection PhpDynamicAsStaticMethodCallInspection */ $forkFileId = \CFile::copyFile($this->getFileId(), true); if (!$forkFileId) { $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_FILE_MODEL_ERROR_COULD_NOT_COPY_FILE'), self::ERROR_COULD_NOT_COPY_FILE))); return null; } /** @noinspection PhpDynamicAsStaticMethodCallInspection */ $fileArray = \CFile::getFileArray($forkFileId); $fileModel = $targetFolder->addFile(array('NAME' => $this->getName(), 'FILE_ID' => $forkFileId, 'SIZE' => $fileArray['FILE_SIZE'], 'CREATED_BY' => $updatedBy), array(), $generateUniqueName); if (!$fileModel) { $this->errorCollection->add($targetFolder->getErrors()); return null; } return $fileModel; }