- Модуль: disk
- Путь к файлу: ~/bitrix/modules/disk/lib/uf/controller.php
- Класс: BitrixDiskUfController
- Вызов: Controller::processActionReloadAttachedObject
protected function processActionReloadAttachedObject()
{
$this->checkRequiredPostParams(array('attachedId',));
if($this->errorCollection->hasErrors())
{
$this->sendJsonErrorResponse();
}
/** @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();
}
$file = $attachedModel->getFile();
if(!$file)
{
$this->sendJsonErrorResponse();
}
if(!$file->canUpdateByCloudImport($file->getStorage()->getCurrentUserSecurityContext()))
{
$this->sendJsonAccessDeniedResponse();
}
$importManager = CloudImportImportManager::buildByAttachedObject($attachedModel);
if(!$importManager)
{
return null;
}
$documentHandler = $importManager->getDocumentHandler();
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'));
}
$lastCloudImport = $attachedModel
->getFile()
->getLastCloudImportEntry()
;
if(!$importManager->hasNewVersion($lastCloudImport))
{
$this->sendJsonSuccessResponse(array(
'hasNewVersion' => false,
));
}
$cloudImportEntry = $importManager->forkImport($lastCloudImport);
if(!$cloudImportEntry)
{
$this->errorCollection->add($importManager->getErrors());
$this->sendJsonErrorResponse();
}
$this->sendJsonSuccessResponse(array(
'hasNewVersion' => true,
'cloudImport' => array(
'id' => $cloudImportEntry->getId(),
),
));
}