/** * Saves file in destination folder from entry of cloud import. * @param Entry $entry Cloud import entry. * @param Folder $folder Destination folder. * @return \Bitrix\Disk\File|null New file object. */ public function saveFile(Entry $entry, Folder $folder) { if (!$entry->getTmpFile()) { $this->errorCollection->addOne(new Error('Could not find cloud import', self::ERROR_COULD_NOT_FIND_CLOUD_IMPORT)); return null; } if ($entry->getContentSize() != $entry->getDownloadedContentSize()) { $this->errorCollection->addOne(new Error('Content size != downloaded content size')); return null; } $fileData = new Document\FileData(); $fileData->setId($entry->getServiceObjectId()); $fileMetadata = $this->documentHandler->getFileMetadata($fileData); if (!$fileMetadata || empty($fileMetadata['name'])) { $this->errorCollection->add($this->documentHandler->getErrors()); return null; } $name = $fileMetadata['name']; if (!getFileExtension($name)) { $name = $this->recoverExtensionInName($name, $fileMetadata['mimeType']); } $tmpFile = $entry->getTmpFile(); $fileArray = \CFile::makeFileArray($tmpFile->getAbsolutePath()); $file = $folder->uploadFile($fileArray, array('NAME' => $name, 'CREATED_BY' => $this->documentHandler->getUserId(), 'CONTENT_PROVIDER' => $this->documentHandler->getCode()), array(), true); if (!$file) { $tmpFile->delete(); $this->errorCollection->add($folder->getErrors()); return null; } $entry->linkObject($file); return $file; }
protected function getEditSessionByCurrentUser($sessionId) { return EditSession::load(array('ID' => $sessionId, 'USER_ID' => $this->getUser()->getId(), '=SERVICE' => $this->documentHandler->getCode())); }
protected function listItemsCloud(DocumentHandler $documentHandler, $path = '/') { $urlManager = Driver::getInstance()->getUrlManager(); $items = $documentHandler->listFolder($path, $this->request->getQuery('folderId')); if ($items === null) { $this->errorCollection->add($documentHandler->getErrors()); return null; } $response = array(); foreach ($items as $item) { $item['link'] = $urlManager->getUrlUfController('loadItems', array('folderId' => $item['id'], 'service' => $documentHandler->getCode())); $response[$item['id']] = $item; } unset($item); return $response; }