/** * Uploads new chunk from cloud drive if necessary. * @param Entry $entry Cloud import entry. * @return bool */ public function uploadChunk(Entry $entry) { $tmpFile = \CTempFile::getFileName(uniqid('_wd', true)); checkDirPath($tmpFile); $fileData = new Document\FileData(); $fileData->setId($entry->getServiceObjectId()); $fileData->setMimeType($entry->getMimeType()); $fileData->setSrc($tmpFile); $chunkSize = self::CHUNK_SIZE; $downloadedContentSize = $entry->getDownloadedContentSize(); $contentSize = $entry->getContentSize(); if ($contentSize == 0 && $this->documentHandler instanceof Document\GoogleHandler) { return $this->uploadEmptyFileFromGoogle($entry, $fileData); } if ($contentSize - $downloadedContentSize < $chunkSize) { $chunkSize = $contentSize - $downloadedContentSize; } $startRange = $downloadedContentSize; if (!$this->documentHandler->downloadPartFile($fileData, $startRange, $chunkSize)) { $this->errorCollection->add($this->documentHandler->getErrors()); return false; } $token = null; if ($entry->getTmpFile() && $entry->getTmpFile()->getToken()) { //todo it's strange, fix it $token = $entry->getTmpFile()->getToken(); } $uploadFileManager = new Bitrix24Disk\UploadFileManager(); $uploadFileManager->setTmpFileClass(TmpFile::className())->setUser($this->documentHandler->getUserId())->setFileSize($contentSize)->setToken($token)->setContentRange(array($startRange, $startRange + $chunkSize - 1)); $tmpFileArray = \CFile::makeFileArray($tmpFile); if (!$uploadFileManager->upload($fileData->getId(), $tmpFileArray)) { $this->errorCollection->add($uploadFileManager->getErrors()); return false; } if ($token === null) { $entry->linkTmpFile(TmpFile::load(array('=TOKEN' => $uploadFileManager->getToken()))); } return $entry->increaseDownloadedContentSize($chunkSize); }