- Модуль: disk
- Путь к файлу: ~/bitrix/modules/disk/lib/document/localdocumentcontroller.php
- Класс: BitrixDiskDocumentLocalDocumentController
- Вызов: LocalDocumentController::processActionPublishBlank
protected function processActionPublishBlank($type)
{
$fileData = new BlankFileData($type);
if($this->request->getPost('targetFolderId'))
{
$folder = Folder::loadById((int)$this->request->getPost('targetFolderId'), array('STORAGE'));
if(!$folder)
{
$this->errorCollection->add(array(new Error(Loc::getMessage('DISK_LOCAL_DOC_CONTROLLER_ERROR_COULD_NOT_FIND_FOLDER'), self::ERROR_COULD_NOT_FIND_FOLDER)));
$this->sendJsonErrorResponse();
}
}
else
{
$userStorage = Driver::getInstance()->getStorageByUserId($this->getUser()->getId());
if(!$userStorage)
{
$this->errorCollection->add(array(new Error(Loc::getMessage('DISK_LOCAL_DOC_CONTROLLER_ERROR_COULD_NOT_FIND_STORAGE'), self::ERROR_COULD_NOT_FIND_STORAGE)));
$this->sendJsonErrorResponse();
}
$folder = $userStorage->getFolderForCreatedFiles();
}
if(!$folder)
{
$this->errorCollection->add(array(new Error(Loc::getMessage('DISK_LOCAL_DOC_CONTROLLER_ERROR_COULD_NOT_FIND_FOLDER_FOR_CREATED_FILES'), self::ERROR_COULD_NOT_FIND_FOLDER_FOR_CREATED_FILES)));
$this->sendJsonErrorResponse();
}
$storage = $folder->getStorage();
if(!$folder->canAdd($storage->getCurrentUserSecurityContext()))
{
$this->errorCollection->add(array(new Error(Loc::getMessage('DISK_LOCAL_DOC_CONTROLLER_ERROR_BAD_RIGHTS'), self::ERROR_BAD_RIGHTS)));
$this->sendJsonErrorResponse();
}
if ($type === 'xlsx')
{
$newFile = $folder->uploadFile(CFile::makeFileArray($fileData->getSrc()), [
'NAME' => $fileData->getName(),
'CREATED_BY' => $this->getUser()->getId(),
], [], true);
}
else
{
$newFile = $folder->addBlankFile(array(
'NAME' => $fileData->getName(),
'CREATED_BY' => $this->getUser()->getId(),
'MIME_TYPE' => $fileData->getMimeType(),
), array(), true);
}
if(!$newFile)
{
$this->errorCollection->add(array(new Error(Loc::getMessage('DISK_LOCAL_DOC_CONTROLLER_ERROR_COULD_NOT_CREATE_FILE'), self::ERROR_COULD_NOT_CREATE_FILE)));
$this->errorCollection->add($folder->getErrors());
$this->sendJsonErrorResponse();
}
$this->sendJsonSuccessResponse(array(
'ufValue' => FileUserType::NEW_FILE_PREFIX . $newFile->getId(),
'id' => $newFile->getId(),
'object' => array(
'id' => $newFile->getId(),
'name' => $newFile->getName(),
'sizeInt' => $newFile->getSize(),
'size' => CFile::formatSize($newFile->getSize()),
'extension' => $newFile->getExtension(),
'nameWithoutExtension' => getFileNameWithoutExtension($newFile->getName()),
),
'folderName' => $storage->getProxyType()->getTitleForCurrentUser() . ' / ' . $folder->getName(),
'link' => Driver::getInstance()->getUrlManager()->getUrlForStartEditFile($newFile->getId(), self::CODE),
));
}