• Модуль: disk
  • Путь к файлу: ~/bitrix/modules/disk/lib/uf/controller.php
  • Класс: BitrixDiskUfController
  • Вызов: Controller::processActionUpdateAttachedObject
protected function processActionUpdateAttachedObject()
{
	$this->checkRequiredPostParams(array('cloudImportId', 'attachedId', ));

	if($this->errorCollection->hasErrors())
	{
		$this->sendJsonErrorResponse();
	}
	$cloudImport = CloudImportEntry::load(array(
		'ID' => $this->request->getPost('cloudImportId'),
		'USER_ID' => $this->getUser()->getId(),
	), array('TMP_FILE'));
	if(!$cloudImport)
	{
		$this->errorCollection->addOne(new Error('Could not find cloud import', self::ERROR_COULD_NOT_FIND_CLOUD_IMPORT));
		$this->sendJsonErrorResponse();
	}

	$documentHandlersManager = Driver::getInstance()->getDocumentHandlersManager();
	$documentHandler = $documentHandlersManager->getHandlerByCode($cloudImport->getService());
	if(!$documentHandler)
	{
		$this->errorCollection->add($documentHandlersManager->getErrors());
		$this->sendJsonErrorResponse();
	}
	if(!$documentHandler->checkAccessibleTokenService())
	{
		$this->errorCollection->add(array(new Error(Loc::getMessage('DISK_UF_CONTROLLER_ERROR_COULD_NOT_WORK_WITH_TOKEN_SERVICE_B24', array('#NAME#' => $documentHandler::getName())), self::ERROR_COULD_NOT_WORK_WITH_TOKEN_SERVICE)));
		$this->errorCollection->add($documentHandler->getErrors());
		$this->sendJsonErrorResponse();
	}

	if(!$documentHandler->queryAccessToken()->hasAccessToken() || $documentHandler->isRequiredAuthorization())
	{
		$this->sendNeedAuth($documentHandler->getUrlForAuthorizeInTokenService('opener'));
	}


	/** @var AttachedObject $attachedModel */
	$attachedModel = AttachedObject::loadById((int)$this->request->getPost('attachedId'), array('OBJECT'));
	if(!$attachedModel)
	{
		$this->errorCollection->add(array(new Error('Could not find attached object')));
		$this->sendJsonErrorResponse();
	}

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

	$importManager = new CloudImportImportManager($documentHandler);
	$version = $importManager->uploadVersion($cloudImport);
	if(!$version)
	{
		$this->errorCollection->add($importManager->getErrors());
		$this->sendJsonErrorResponse();
	}

	$this->sendJsonSuccessResponse();
}