• Модуль: disk
  • Путь к файлу: ~/bitrix/modules/disk/lib/uf/controller.php
  • Класс: BitrixDiskUfController
  • Вызов: Controller::processActionCopyToMe
protected function processActionCopyToMe()
{
	$this->checkRequiredGetParams(array(
		'attachedId',
	));
	if($this->errorCollection->hasErrors())
	{
		$this->sendJsonErrorResponse();
	}
	$attachedModel = AttachedObject::loadById((int)$this->request->getQuery('attachedId'), array('OBJECT', 'VERSION'));
	if(!$attachedModel)
	{
		$this->errorCollection->add(array(new Error('Could not find attached object')));
		$this->sendJsonErrorResponse();
	}

	if(!$attachedModel->canRead($this->getUser()->getId()))
	{
		$this->errorCollection->add(array(new Error("Bad permission. Could not read this file")));
		$this->sendJsonErrorResponse();
	}

	$userStorage = Driver::getInstance()->getStorageByUserId($this->getUser()->getId());
	if(!$userStorage)
	{
		$this->errorCollection->add(array(new Error("Could not find storage for current user")));
		$this->sendJsonErrorResponse();
	}
	$folder = $userStorage->getFolderForSavedFiles();
	if(!$folder)
	{
		$this->errorCollection->add(array(new Error("Could not find folder for created files")));
		$this->sendJsonErrorResponse();
	}
	$file = $attachedModel->getObject();
	$newFile = $file->copyTo($folder, $this->getUser()->getId(), true);

	if(!$newFile)
	{
		$this->errorCollection->add(array(new Error("Could not copy file to storage for current user")));
		$this->sendJsonErrorResponse();
	}

	$urlManager = Driver::getInstance()->getUrlManager();
	$viewUrl = $urlManager->encodeUrn(
		$urlManager->getUrlFocusController('showObjectInGrid', array(
			'objectId' => $newFile->getId(),
		))
	);
	$runViewerUrl = $urlManager->encodeUrn(
		$urlManager->getUrlFocusController('showObjectInGrid', array(
			'objectId' => $newFile->getId(),
			'cmd' => 'show',
		))
	);


	$this->sendJsonSuccessResponse(array(
		'newId' => $newFile->getId(),
		'viewUrl' => $viewUrl,
		'runViewUrl' => $runViewerUrl,
	));
}