• Модуль: disk
  • Путь к файлу: ~/bitrix/modules/disk/lib/controller/attachedobject.php
  • Класс: BitrixDiskControllerAttachedObject
  • Вызов: AttachedObject::copyToMeAction
public function copyToMeAction(DiskAttachedObject $attachedObject)
{
	$currentUserId = $this->getCurrentUser()->getId();
	$userStorage = Driver::getInstance()->getStorageByUserId($currentUserId);
	if (!$userStorage)
	{
		$this->addError(new Error('Could not find storage for current user'));

		return;
	}

	$folder = $userStorage->getFolderForSavedFiles();
	if (!$folder)
	{
		$this->addError(new Error('Could not find folder for created files'));

		return;
	}

	$file = $attachedObject->getFile();
	if (!$file)
	{
		$this->addError(new Error('Could not find file to copy'));

		return;
	}

	//so, now we don't copy links in the method copyTo. But here we have to copy content.
	//And after we set name to new object as it was on link.
	$newFile = $file->getRealObject()->copyTo($folder, $currentUserId, true);
	if ($file->getRealObject()->getName() != $file->getName())
	{
		$newFile->renameInternal($file->getName(), true);
	}

	if (!$newFile)
	{
		$this->addError(new Error('Could not copy file to storage for current user'));

		return;
	}

	return (new File())->getAction($newFile);
}