protected function processActionSaveBlank()
 {
     $this->checkRequiredGetParams(array('type'));
     $this->checkRequiredPostParams(array('editSessionId'));
     if ($this->errorCollection->hasErrors()) {
         $this->sendJsonErrorResponse();
     }
     $currentSession = $this->getEditSessionByCurrentUser((int) $this->request->getPost('editSessionId'));
     if (!$currentSession) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_DOC_CONTROLLER_ERROR_COULD_NOT_FIND_EDIT_SESSION'), self::ERROR_COULD_NOT_FIND_EDIT_SESSION)));
         $this->sendJsonErrorResponse();
     }
     $tmpFile = \CTempFile::getFileName(uniqid('_wd'));
     checkDirPath($tmpFile);
     $fileData = new BlankFileData($this->request->getQuery('type'));
     $fileData->setId($currentSession->getServiceFileId());
     $fileData->setSrc($tmpFile);
     $fileData = $this->documentHandler->downloadFile($fileData);
     if (!$fileData) {
         if ($this->documentHandler->isRequiredAuthorization()) {
             $this->sendNeedAuth();
         }
         $this->errorCollection->add($this->documentHandler->getErrors());
         $this->sendJsonErrorResponse();
     }
     $fileArray = \CFile::makeFileArray($tmpFile);
     $fileArray['name'] = $fileData->getName();
     $fileArray['type'] = $fileData->getMimeType();
     $fileArray['MODULE_ID'] = Driver::INTERNAL_MODULE_ID;
     /** @noinspection PhpDynamicAsStaticMethodCallInspection */
     $fileId = \CFile::saveFile($fileArray, Driver::INTERNAL_MODULE_ID);
     if (!$fileId) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_DOC_CONTROLLER_ERROR_COULD_NOT_SAVE_FILE'), self::ERROR_COULD_NOT_SAVE_FILE)));
         $this->sendJsonErrorResponse();
     }
     $folder = null;
     if (!empty($_REQUEST['targetFolderId'])) {
         $folder = $this->getFolderToSaveFile((int) $_REQUEST['targetFolderId']);
     }
     if (!$folder) {
         $userStorage = Driver::getInstance()->getStorageByUserId($this->getUser()->getId());
         if (!$userStorage) {
             \CFile::delete($fileId);
             $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_DOC_CONTROLLER_ERROR_COULD_NOT_FIND_STORAGE'), self::ERROR_COULD_NOT_FIND_STORAGE)));
             $this->sendJsonErrorResponse();
         }
         $folder = $userStorage->getFolderForCreatedFiles();
     }
     if (!$folder) {
         \CFile::delete($fileId);
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_DOC_CONTROLLER_ERROR_COULD_NOT_FIND_FOLDER_FOR_CREATED_FILES'), self::ERROR_COULD_NOT_FIND_FOLDER_FOR_CREATED_FILES)));
         $this->sendJsonErrorResponse();
     }
     if (!$folder->canAdd($folder->getStorage()->getCurrentUserSecurityContext())) {
         \CFile::delete($fileId);
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_DOC_CONTROLLER_ERROR_BAD_RIGHTS'), self::ERROR_BAD_RIGHTS)));
         $this->sendJsonErrorResponse();
     }
     $newFile = $folder->addFile(array('NAME' => $fileData->getName(), 'FILE_ID' => $fileId, 'SIZE' => $fileArray['size'], 'CREATED_BY' => $this->getUser()->getId()), array(), true);
     if (!$newFile) {
         \CFile::delete($fileId);
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_DOC_CONTROLLER_ERROR_COULD_NOT_CREATE_FILE'), self::ERROR_COULD_NOT_CREATE_FILE)));
         $this->errorCollection->add($folder->getErrors());
         $this->sendJsonErrorResponse();
     }
     $this->deleteEditSession($currentSession);
     $this->deleteFile($currentSession, $fileData);
     $this->sendJsonSuccessResponse(array('folderName' => $folder->getName(), 'objectId' => $newFile->getId(), 'sizeInt' => $newFile->getSize(), 'size' => \CFile::formatSize($newFile->getSize()), 'name' => $newFile->getName(), 'extension' => $newFile->getExtension(), 'nameWithoutExtension' => getFileNameWithoutExtension($newFile->getName())));
 }
 protected function processActionPublishBlank()
 {
     $this->checkRequiredGetParams(array('type'));
     if ($this->errorCollection->hasErrors()) {
         $this->sendJsonErrorResponse();
     }
     $fileData = new BlankFileData($this->request->getQuery('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();
     }
     $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)));
 }